Mercurial > hg > rc1
comparison vendor/pear/crypt_gpg/tests/SignatureTest.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 * Signature class 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 SignatureTestCase | |
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-2011 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 * Signature class. | |
50 */ | |
51 require_once 'Crypt/GPG/Signature.php'; | |
52 | |
53 /** | |
54 * Signature class tests for Crypt_GPG. | |
55 * | |
56 * @category Encryption | |
57 * @package Crypt_GPG | |
58 * @author Michael Gauthier <mike@silverorange.com> | |
59 * @copyright 2008-2010 silverorange | |
60 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | |
61 * @link http://pear.php.net/package/Crypt_GPG | |
62 */ | |
63 class SignatureTestCase extends Crypt_GPG_TestCase | |
64 { | |
65 // construct | |
66 // {{{ testConstructFromSignature() | |
67 | |
68 /** | |
69 * @group construct | |
70 */ | |
71 public function testConstructFromSignature() | |
72 { | |
73 $expectedSignature = new Crypt_GPG_Signature(array( | |
74 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
75 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
76 'keyId' => '0C097D9EC94C06363', | |
77 'creation' => 1221785858, | |
78 'expiration' => 1421785858, | |
79 'valid' => false, | |
80 'userId' => 'Alice <alice@example.com>' | |
81 )); | |
82 | |
83 $signature = new Crypt_GPG_Signature($expectedSignature); | |
84 | |
85 $this->assertEquals($expectedSignature, $signature); | |
86 } | |
87 | |
88 // }}} | |
89 // {{{ testConstructFromArray() | |
90 | |
91 /** | |
92 * @group construct | |
93 */ | |
94 public function testConstructFromArray() | |
95 { | |
96 $signature = new Crypt_GPG_Signature(array( | |
97 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
98 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
99 'keyId' => '0C097D9EC94C06363', | |
100 'creation' => 1221785858, | |
101 'expiration' => 1421785858, | |
102 'valid' => false, | |
103 'userId' => 'Alice <alice@example.com>' | |
104 )); | |
105 | |
106 $this->assertEquals('KuhELanvhPRXozEjFWb2mam1q20', | |
107 $signature->getId()); | |
108 | |
109 $this->assertEquals('8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
110 $signature->getKeyFingerprint()); | |
111 | |
112 $this->assertEquals('0C097D9EC94C06363', $signature->getKeyId()); | |
113 | |
114 $this->assertEquals(1221785858, $signature->getCreationDate()); | |
115 $this->assertEquals(1421785858, $signature->getExpirationDate()); | |
116 | |
117 $this->assertFalse($signature->isValid()); | |
118 | |
119 $this->assertEquals('Alice <alice@example.com>', | |
120 strval($signature->getUserId())); | |
121 } | |
122 | |
123 // }}} | |
124 | |
125 // accessors | |
126 // {{{ testGetId() | |
127 | |
128 /** | |
129 * @group accessors | |
130 */ | |
131 public function testGetId() | |
132 { | |
133 $signature = new Crypt_GPG_Signature(array( | |
134 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
135 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
136 'creation' => 1221785858, | |
137 'expiration' => 1421785858, | |
138 'valid' => false, | |
139 'userId' => 'Alice <alice@example.com>' | |
140 )); | |
141 | |
142 $this->assertEquals('KuhELanvhPRXozEjFWb2mam1q20', $signature->getId()); | |
143 } | |
144 | |
145 // }}} | |
146 // {{{ testGetKeyFingerprint() | |
147 | |
148 /** | |
149 * @group accessors | |
150 */ | |
151 public function testGetKeyFingerprint() | |
152 { | |
153 $signature = new Crypt_GPG_Signature(array( | |
154 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
155 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
156 'creation' => 1221785858, | |
157 'expiration' => 1421785858, | |
158 'valid' => false, | |
159 'userId' => 'Alice <alice@example.com>' | |
160 )); | |
161 | |
162 $this->assertEquals('8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
163 $signature->getKeyFingerprint()); | |
164 } | |
165 | |
166 // }}} | |
167 // {{{ testGetKeyId() | |
168 | |
169 /** | |
170 * @group accessors | |
171 */ | |
172 public function testGetKeyId() | |
173 { | |
174 $signature = new Crypt_GPG_Signature(array( | |
175 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
176 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
177 'keyId' => '0C097D9EC94C06363', | |
178 'creation' => 1221785858, | |
179 'expiration' => 1421785858, | |
180 'valid' => false, | |
181 'userId' => 'Alice <alice@example.com>' | |
182 )); | |
183 | |
184 $this->assertEquals('0C097D9EC94C06363', $signature->getKeyId()); | |
185 } | |
186 | |
187 // }}} | |
188 // {{{ testGetCreationDate() | |
189 | |
190 /** | |
191 * @group accessors | |
192 */ | |
193 public function testGetCreationDate() | |
194 { | |
195 $signature = new Crypt_GPG_Signature(array( | |
196 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
197 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
198 'creation' => 1221785858, | |
199 'expiration' => 1421785858, | |
200 'valid' => false, | |
201 'userId' => 'Alice <alice@example.com>' | |
202 )); | |
203 | |
204 $this->assertEquals(1221785858, $signature->getCreationDate()); | |
205 } | |
206 | |
207 // }}} | |
208 // {{{ testGetExpirationDate() | |
209 | |
210 /** | |
211 * @group accessors | |
212 */ | |
213 public function testGetExpirationDate() | |
214 { | |
215 $signature = new Crypt_GPG_Signature(array( | |
216 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
217 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
218 'creation' => 1221785858, | |
219 'expiration' => 1421785858, | |
220 'valid' => false, | |
221 'userId' => 'Alice <alice@example.com>' | |
222 )); | |
223 | |
224 $this->assertEquals(1421785858, $signature->getExpirationDate()); | |
225 } | |
226 | |
227 // }}} | |
228 // {{{ testIsValid() | |
229 | |
230 /** | |
231 * @group accessors | |
232 */ | |
233 public function testIsValid() | |
234 { | |
235 $signature = new Crypt_GPG_Signature(array( | |
236 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
237 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
238 'creation' => 1221785858, | |
239 'expiration' => 1421785858, | |
240 'valid' => true, | |
241 'userId' => 'Alice <alice@example.com>' | |
242 )); | |
243 | |
244 $this->assertTrue($signature->isValid()); | |
245 | |
246 $signature = new Crypt_GPG_Signature(array( | |
247 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
248 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
249 'creation' => 1221785858, | |
250 'expiration' => 1421785858, | |
251 'valid' => false, | |
252 'userId' => 'Alice <alice@example.com>' | |
253 )); | |
254 | |
255 | |
256 $this->assertFalse($signature->isValid()); | |
257 } | |
258 | |
259 // }}} | |
260 // {{{ testGetUserId() | |
261 | |
262 /** | |
263 * @group accessors | |
264 */ | |
265 public function testGetUserId() | |
266 { | |
267 $signature = new Crypt_GPG_Signature(array( | |
268 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
269 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
270 'creation' => 1221785858, | |
271 'expiration' => 1421785858, | |
272 'valid' => true, | |
273 'userId' => 'Alice <alice@example.com>' | |
274 )); | |
275 | |
276 $expectedUserId = new Crypt_GPG_UserId(array( | |
277 'name' => 'Alice', | |
278 'email' => 'alice@example.com' | |
279 )); | |
280 | |
281 $this->assertEquals($expectedUserId, $signature->getUserId()); | |
282 } | |
283 | |
284 // }}} | |
285 | |
286 // mutators | |
287 // {{{ testSetId() | |
288 | |
289 /** | |
290 * @group mutators | |
291 */ | |
292 public function testSetId() | |
293 { | |
294 $expectedSignature = new Crypt_GPG_Signature(array( | |
295 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
296 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
297 'creation' => 1221785858, | |
298 'expiration' => 1421785858, | |
299 'valid' => true, | |
300 'userId' => 'Alice <alice@example.com>' | |
301 )); | |
302 | |
303 $signature = new Crypt_GPG_Signature(array( | |
304 'id' => 'something different', | |
305 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
306 'creation' => 1221785858, | |
307 'expiration' => 1421785858, | |
308 'valid' => true, | |
309 'userId' => 'Alice <alice@example.com>' | |
310 )); | |
311 | |
312 $signature->setId('KuhELanvhPRXozEjFWb2mam1q20'); | |
313 | |
314 $this->assertEquals($expectedSignature, $signature); | |
315 } | |
316 | |
317 // }}} | |
318 // {{{ testSetKeyFingerprint() | |
319 | |
320 /** | |
321 * @group mutators | |
322 */ | |
323 public function testSetKeyFingerprint() | |
324 { | |
325 $expectedSignature = new Crypt_GPG_Signature(array( | |
326 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
327 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
328 'creation' => 1221785858, | |
329 'expiration' => 1421785858, | |
330 'valid' => true, | |
331 'userId' => 'Alice <alice@example.com>' | |
332 )); | |
333 | |
334 $signature = new Crypt_GPG_Signature(array( | |
335 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
336 'fingerprint' => 'bad fingerprint', | |
337 'creation' => 1221785858, | |
338 'expiration' => 1421785858, | |
339 'valid' => true, | |
340 'userId' => 'Alice <alice@example.com>' | |
341 )); | |
342 | |
343 $signature->setKeyFingerprint( | |
344 '8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
345 | |
346 $this->assertEquals($expectedSignature, $signature); | |
347 } | |
348 | |
349 // }}} | |
350 // {{{ testSetKeyId() | |
351 | |
352 /** | |
353 * @group mutators | |
354 */ | |
355 public function testSetKeyId() | |
356 { | |
357 $expectedSignature = new Crypt_GPG_Signature(array( | |
358 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
359 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
360 'keyId' => '0C097D9EC94C06363', | |
361 'creation' => 1221785858, | |
362 'expiration' => 1421785858, | |
363 'valid' => true, | |
364 'userId' => 'Alice <alice@example.com>' | |
365 )); | |
366 | |
367 $signature = new Crypt_GPG_Signature(array( | |
368 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
369 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
370 'keyId' => 'bad key id', | |
371 'creation' => 1221785858, | |
372 'expiration' => 1421785858, | |
373 'valid' => true, | |
374 'userId' => 'Alice <alice@example.com>' | |
375 )); | |
376 | |
377 $signature->setKeyId('0C097D9EC94C06363'); | |
378 | |
379 $this->assertEquals($expectedSignature, $signature); | |
380 } | |
381 | |
382 // }}} | |
383 // {{{ testSetCreationDate() | |
384 | |
385 /** | |
386 * @group mutators | |
387 */ | |
388 public function testSetCreationDate() | |
389 { | |
390 $expectedSignature = new Crypt_GPG_Signature(array( | |
391 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
392 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
393 'creation' => 1221785858, | |
394 'expiration' => 1421785858, | |
395 'valid' => true, | |
396 'userId' => 'Alice <alice@example.com>' | |
397 )); | |
398 | |
399 $signature = new Crypt_GPG_Signature(array( | |
400 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
401 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
402 'creation' => 1111111111, | |
403 'expiration' => 1421785858, | |
404 'valid' => true, | |
405 'userId' => 'Alice <alice@example.com>' | |
406 )); | |
407 | |
408 $signature->setCreationDate(1221785858); | |
409 | |
410 $this->assertEquals($expectedSignature, $signature); | |
411 } | |
412 | |
413 // }}} | |
414 // {{{ testSetExpirationDate() | |
415 | |
416 /** | |
417 * @group mutators | |
418 */ | |
419 public function testSetExpirationDate() | |
420 { | |
421 $expectedSignature = new Crypt_GPG_Signature(array( | |
422 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
423 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
424 'creation' => 1221785858, | |
425 'expiration' => 1421785858, | |
426 'valid' => true, | |
427 'userId' => 'Alice <alice@example.com>' | |
428 )); | |
429 | |
430 $signature = new Crypt_GPG_Signature(array( | |
431 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
432 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
433 'creation' => 1221785858, | |
434 'expiration' => 0, | |
435 'valid' => true, | |
436 'userId' => 'Alice <alice@example.com>' | |
437 )); | |
438 | |
439 $signature->setExpirationDate(1421785858); | |
440 | |
441 $this->assertEquals($expectedSignature, $signature); | |
442 } | |
443 | |
444 // }}} | |
445 // {{{ testSetValid() | |
446 | |
447 /** | |
448 * @group mutators | |
449 */ | |
450 public function testSetValid() | |
451 { | |
452 $expectedSignature = new Crypt_GPG_Signature(array( | |
453 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
454 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
455 'creation' => 1221785858, | |
456 'expiration' => 1421785858, | |
457 'valid' => true, | |
458 'userId' => 'Alice <alice@example.com>' | |
459 )); | |
460 | |
461 $signature = new Crypt_GPG_Signature(array( | |
462 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
463 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
464 'creation' => 1221785858, | |
465 'expiration' => 1421785858, | |
466 'valid' => false, | |
467 'userId' => 'Alice <alice@example.com>' | |
468 )); | |
469 | |
470 $signature->setValid(true); | |
471 | |
472 $this->assertEquals($expectedSignature, $signature); | |
473 } | |
474 | |
475 // }}} | |
476 // {{{ testSetUserId() | |
477 | |
478 /** | |
479 * @group accessors | |
480 */ | |
481 public function testSetUserId() | |
482 { | |
483 $expectedSignature = new Crypt_GPG_Signature(array( | |
484 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
485 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
486 'creation' => 1221785858, | |
487 'expiration' => 1421785858, | |
488 'valid' => true, | |
489 'userId' => 'Alice <alice@example.com>' | |
490 )); | |
491 | |
492 $signature = new Crypt_GPG_Signature(array( | |
493 'id' => 'KuhELanvhPRXozEjFWb2mam1q20', | |
494 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
495 'creation' => 1221785858, | |
496 'expiration' => 1421785858, | |
497 'valid' => true, | |
498 'userId' => 'Bob <bob@example.com>' | |
499 )); | |
500 | |
501 $userId = new Crypt_GPG_UserId(array( | |
502 'name' => 'Alice', | |
503 'email' => 'alice@example.com' | |
504 )); | |
505 | |
506 $signature->setUserId($userId); | |
507 | |
508 $this->assertEquals($expectedSignature, $signature); | |
509 } | |
510 | |
511 // }}} | |
512 | |
513 // fluent interface | |
514 // {{{ testFluentInterface | |
515 | |
516 /** | |
517 * @group fluent | |
518 */ | |
519 public function testFluentInterface() | |
520 { | |
521 $signature = new Crypt_GPG_Signature(); | |
522 $returnedSignature = $signature->setId('KuhELanvhPRXozEjFWb2mam1q20'); | |
523 $this->assertEquals( | |
524 $signature, | |
525 $returnedSignature, | |
526 'Failed asserting fluent interface works for setId() method.' | |
527 ); | |
528 | |
529 $signature = new Crypt_GPG_Signature(); | |
530 $returnedSignature = $signature->setKeyFingerprint( | |
531 '8D2299D9C5C211128B32BBB0C097D9EC94C06363' | |
532 ); | |
533 $this->assertEquals( | |
534 $signature, | |
535 $returnedSignature, | |
536 'Failed asserting fluent interface works for setKeyFingerprint() ' . | |
537 'method.' | |
538 ); | |
539 | |
540 $signature = new Crypt_GPG_Signature(); | |
541 $returnedSignature = $signature->setKeyId('0C097D9EC94C06363'); | |
542 $this->assertEquals( | |
543 $signature, | |
544 $returnedSignature, | |
545 'Failed asserting fluent interface works for setKeyId() method' | |
546 ); | |
547 | |
548 $signature = new Crypt_GPG_Signature(); | |
549 $returnedSignature = $signature->setCreationDate(1234567890); | |
550 $this->assertEquals( | |
551 $signature, | |
552 $returnedSignature, | |
553 'Failed asserting fluent interface works for setCreationDate() ' . | |
554 'method.' | |
555 ); | |
556 | |
557 $signature = new Crypt_GPG_Signature(); | |
558 $returnedSignature = $signature->setExpirationDate(1234567890); | |
559 $this->assertEquals( | |
560 $signature, | |
561 $returnedSignature, | |
562 'Failed asserting fluent interface works for setExpirationDate() ' . | |
563 'method.' | |
564 ); | |
565 | |
566 $signature = new Crypt_GPG_Signature(); | |
567 $returnedSignature = $signature->setValid(true); | |
568 $this->assertEquals( | |
569 $signature, | |
570 $returnedSignature, | |
571 'Failed asserting fluent interface works for setValid() method.' | |
572 ); | |
573 | |
574 $signature = new Crypt_GPG_Signature(); | |
575 $returnedSignature = $signature->setUserId(new Crypt_GPG_UserId()); | |
576 $this->assertEquals( | |
577 $signature, | |
578 $returnedSignature, | |
579 'Failed asserting fluent interface works for setUserId() method.' | |
580 ); | |
581 } | |
582 | |
583 // }}} | |
584 } | |
585 | |
586 ?> |