comparison vendor/pear/crypt_gpg/tests/GeneralTest.php @ 0:1e000243b222

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