1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* General test cases for the Crypt_GPG package.
*
* These tests require the PHPUnit 3.6 or greater package to be installed.
* PHPUnit is installable using PEAR. See the
* {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
* for detailed installation instructions.
*
* To run these tests, use:
* <code>
* $ phpunit GeneralTestCase
* </code>
*
* LICENSE:
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>
*
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier <mike@silverorange.com>
* @copyright 2005-2013 silverorange
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id$
* @link http://pear.php.net/package/Crypt_GPG
*/
use PHPUnit\Framework\Attributes\Group;
/**
* Base test case.
*/
require_once 'TestCase.php';
/**
* General tests for Crypt_GPG.
*
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier <mike@silverorange.com>
* @copyright 2008-2013 silverorange
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear.php.net/package/Crypt_GPG
*/
class GeneralTest extends Crypt_GPG_TestCase
{
public function testPublicKeyringFileException()
{
$this->expectException('Crypt_GPG_FileException');
$publicKeyringFile = $this->getTempFilename('pubring.gpg');
new Crypt_GPG(['publicKeyring' => $publicKeyringFile]);
}
public function testPrivateKeyringFileException()
{
$this->expectException('Crypt_GPG_FileException');
$privateKeyringFile = $this->getTempFilename('secring.gpg');
new Crypt_GPG(['privateKeyring' => $privateKeyringFile]);
}
public function testTrustDatabaseFileException()
{
$this->expectException('Crypt_GPG_FileException');
$trustDbFile = $this->getTempFilename('secring.gpg');
new Crypt_GPG(['trustDb' => $trustDbFile]);
}
public function testHomedirFileException_NoCreate()
{
$this->expectException('Crypt_GPG_FileException');
$this->expectExceptionMessage('cannot be created');
if (posix_getuid() === 0) {
$this->markTestSkipped('Root can write to any homedir.');
}
$nonCreatableDirectory = '//.gnupg';
new Crypt_GPG(['homedir' => $nonCreatableDirectory]);
}
public function testHomedirFileException_NoExecute()
{
$this->expectException('Crypt_GPG_FileException');
$this->expectExceptionMessage('is not enterable');
if (posix_getuid() === 0) {
$this->markTestSkipped('Root can do what it wants to any homedir.');
}
$nonExecutableDirectory = $this->getTempFilename('home-no-execute');
mkdir($nonExecutableDirectory);
chmod($nonExecutableDirectory, 0600); // rw- --- ---
new Crypt_GPG(['homedir' => $nonExecutableDirectory]);
}
public function testHomedirFileException_NoWrite()
{
$this->expectException('Crypt_GPG_FileException');
$this->expectExceptionMessage('is not writable');
if (posix_getuid() === 0) {
$this->markTestSkipped('Root can write to any homedir.');
}
$nonWriteableDirectory = $this->getTempFilename('home-no-write');
mkdir($nonWriteableDirectory);
chmod($nonWriteableDirectory, 0500); // r-x --- ---
new Crypt_GPG(['homedir' => $nonWriteableDirectory]);
}
public function testBinaryPEARException()
{
$this->expectException('PEAR_Exception');
new Crypt_GPG(['binary' => './non-existent-binary']);
}
public function testGPGBinaryPEARException()
{
$this->expectException('PEAR_Exception');
new Crypt_GPG(['gpgBinary' => './non-existent-binary']);
}
#[Group('write')]
public function testSetEngine()
{
$engine = new Crypt_GPG_Engine($this->getOptions());
$gpg = new Crypt_GPG();
$gpg->setEngine($engine);
$this->assertSame($this->getPropertyValue('Crypt_GPG', $gpg, 'engine'), $engine);
}
/**
* @group fluent
*/
public function testFluentInterface()
{
$returnedGpg = $this->gpg->setEngine(
new Crypt_GPG_Engine($this->getOptions())
);
$this->assertEquals(
$this->gpg,
$returnedGpg,
'Failed asserting fluent interface works for setEngine() method.'
);
$returnedGpg = $this->gpg->addDecryptKey(
'8D2299D9C5C211128B32BBB0C097D9EC94C06363',
'test1'
);
$this->assertEquals(
$this->gpg,
$returnedGpg,
'Failed asserting fluent interface works for addDecryptKey() ' .
'method.'
);
$returnedGpg = $this->gpg->addEncryptKey(
'8D2299D9C5C211128B32BBB0C097D9EC94C06363'
);
$this->assertEquals(
$this->gpg,
$returnedGpg,
'Failed asserting fluent interface works for addEncryptKey() ' .
'method.'
);
$returnedGpg = $this->gpg->addSignKey(
'8D2299D9C5C211128B32BBB0C097D9EC94C06363',
'test1'
);
$this->assertEquals(
$this->gpg,
$returnedGpg,
'Failed asserting fluent interface works for addSignKey() ' .
'method.'
);
$returnedGpg = $this->gpg->clearDecryptKeys();
$this->assertEquals(
$this->gpg,
$returnedGpg,
'Failed asserting fluent interface works for clearDecryptKeys() ' .
'method.'
);
$returnedGpg = $this->gpg->clearEncryptKeys();
$this->assertEquals(
$this->gpg,
$returnedGpg,
'Failed asserting fluent interface works for clearEncryptKeys() ' .
'method.'
);
$returnedGpg = $this->gpg->clearSignKeys();
$this->assertEquals(
$this->gpg,
$returnedGpg,
'Failed asserting fluent interface works for clearSignKeys() ' .
'method.'
);
}
}
|