Mercurial > hg > rc1
comparison vendor/pear/crypt_gpg/tests/GetKeysTest.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 * Key retrieval tests 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 GetKeysTestCase | |
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-2008 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 * Tests key retrieval of Crypt_GPG. | |
50 * | |
51 * @category Encryption | |
52 * @package Crypt_GPG | |
53 * @author Michael Gauthier <mike@silverorange.com> | |
54 * @copyright 2005-2008 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 GetKeysTestCase extends Crypt_GPG_TestCase | |
59 { | |
60 // {{{ testGetKeys() | |
61 | |
62 /** | |
63 * @group get-keys | |
64 */ | |
65 public function testGetKeys() | |
66 { | |
67 $expectedKeys = array(); | |
68 | |
69 // {{{ first-keypair@example.com | |
70 $key = new Crypt_GPG_Key(); | |
71 $expectedKeys[] = $key; | |
72 | |
73 $userId = new Crypt_GPG_UserId(); | |
74 $userId->setName('First Keypair Test Key'); | |
75 $userId->setComment('do not encrypt important data with this key'); | |
76 $userId->setEmail('first-keypair@example.com'); | |
77 $key->addUserId($userId); | |
78 | |
79 $subKey = new Crypt_GPG_SubKey(); | |
80 $subKey->setId('C097D9EC94C06363'); | |
81 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); | |
82 $subKey->setFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
83 $subKey->setLength(1024); | |
84 $subKey->setCreationDate(1221785805); | |
85 $subKey->setExpirationDate(0); | |
86 $subKey->setUsage(Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_CERTIFY); | |
87 $subKey->setCanEncrypt(false); | |
88 $subKey->setHasPrivate(true); | |
89 $key->addSubKey($subKey); | |
90 | |
91 $subKey = new Crypt_GPG_SubKey(); | |
92 $subKey->setId('9F93F9116728EF12'); | |
93 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); | |
94 $subKey->setFingerprint('C9C65B3BBF040E40D0EA27B79F93F9116728EF12'); | |
95 $subKey->setLength(2048); | |
96 $subKey->setCreationDate(1221785821); | |
97 $subKey->setExpirationDate(0); | |
98 $subKey->setCanSign(false); | |
99 $subKey->setCanEncrypt(true); | |
100 $subKey->setHasPrivate(true); | |
101 $key->addSubKey($subKey); | |
102 // }}} | |
103 // {{{ second-keypair@example.com | |
104 $key = new Crypt_GPG_Key(); | |
105 $expectedKeys[] = $key; | |
106 | |
107 $userId = new Crypt_GPG_UserId(); | |
108 $userId->setName('Second Keypair Test Key'); | |
109 $userId->setComment('do not encrypt important data with this key'); | |
110 $userId->setEmail('second-keypair@example.com'); | |
111 $key->addUserId($userId); | |
112 | |
113 $subKey = new Crypt_GPG_SubKey(); | |
114 $subKey->setId('03CC890AFA1DAD4B'); | |
115 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); | |
116 $subKey->setFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B'); | |
117 $subKey->setLength(1024); | |
118 $subKey->setCreationDate(1221785821); | |
119 $subKey->setExpirationDate(0); | |
120 $subKey->setUsage(Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_CERTIFY); | |
121 $subKey->setHasPrivate(true); | |
122 $key->addSubKey($subKey); | |
123 | |
124 $subKey = new Crypt_GPG_SubKey(); | |
125 $subKey->setId('B2F54E4757E22450'); | |
126 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); | |
127 $subKey->setFingerprint('C641EE162B46B810E8089153B2F54E4757E22450'); | |
128 $subKey->setLength(2048); | |
129 $subKey->setCreationDate(1221785825); | |
130 $subKey->setExpirationDate(0); | |
131 $subKey->setCanSign(false); | |
132 $subKey->setCanEncrypt(true); | |
133 $subKey->setHasPrivate(true); | |
134 $key->addSubKey($subKey); | |
135 // }}} | |
136 // {{{ public-only@example.com | |
137 $key = new Crypt_GPG_Key(); | |
138 $expectedKeys[] = $key; | |
139 | |
140 $userId = new Crypt_GPG_UserId(); | |
141 $userId->setName('Public Only Test Key'); | |
142 $userId->setComment('do not encrypt important data with this key'); | |
143 $userId->setEmail('public-only@example.com'); | |
144 $key->addUserId($userId); | |
145 | |
146 $subKey = new Crypt_GPG_SubKey(); | |
147 $subKey->setId('ABA81EF54E8C0DEB'); | |
148 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); | |
149 $subKey->setFingerprint('F83118CB6F5892DC1C3E936DABA81EF54E8C0DEB'); | |
150 $subKey->setLength(1024); | |
151 $subKey->setCreationDate(1221785826); | |
152 $subKey->setExpirationDate(0); | |
153 $subKey->setUsage(Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_CERTIFY); | |
154 $subKey->setHasPrivate(false); | |
155 $key->addSubKey($subKey); | |
156 | |
157 $subKey = new Crypt_GPG_SubKey(); | |
158 $subKey->setId('BA4984433CDF4169'); | |
159 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); | |
160 $subKey->setFingerprint('B68C9DB020181C798047A6E7BA4984433CDF4169'); | |
161 $subKey->setLength(2048); | |
162 $subKey->setCreationDate(1221785832); | |
163 $subKey->setExpirationDate(0); | |
164 $subKey->setCanSign(false); | |
165 $subKey->setCanEncrypt(true); | |
166 $subKey->setHasPrivate(false); | |
167 $key->addSubKey($subKey); | |
168 // }}} | |
169 // {{{ no-passphrase@example.com | |
170 $key = new Crypt_GPG_Key(); | |
171 $expectedKeys[] = $key; | |
172 | |
173 $userId = new Crypt_GPG_UserId(); | |
174 $userId->setName('No Passphrase Public and Private Test Key'); | |
175 $userId->setComment('do not encrypt important data with this key'); | |
176 $userId->setEmail('no-passphrase@example.com'); | |
177 $key->addUserId($userId); | |
178 | |
179 $subKey = new Crypt_GPG_SubKey(); | |
180 $subKey->setId('94563FB398ADA6B2'); | |
181 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); | |
182 $subKey->setFingerprint('1EC9C5DBF239DD0A3A4FCD0D94563FB398ADA6B2'); | |
183 $subKey->setLength(1024); | |
184 $subKey->setCreationDate(1221785833); | |
185 $subKey->setExpirationDate(0); | |
186 $subKey->setUsage(Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_CERTIFY); | |
187 $subKey->setHasPrivate(true); | |
188 $key->addSubKey($subKey); | |
189 | |
190 $subKey = new Crypt_GPG_SubKey(); | |
191 $subKey->setId('24BF380700C14B4F'); | |
192 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); | |
193 $subKey->setFingerprint('86DD46AC210531EE5A37567824BF380700C14B4F'); | |
194 $subKey->setLength(2048); | |
195 $subKey->setCreationDate(1221785845); | |
196 $subKey->setExpirationDate(0); | |
197 $subKey->setCanSign(false); | |
198 $subKey->setCanEncrypt(true); | |
199 $subKey->setHasPrivate(true); | |
200 $key->addSubKey($subKey); | |
201 // }}} | |
202 // {{{ multiple-subkeys@example.com | |
203 $key = new Crypt_GPG_Key(); | |
204 $expectedKeys[] = $key; | |
205 | |
206 $userId = new Crypt_GPG_UserId(); | |
207 $userId->setName('Multiple Subkeys'); | |
208 $userId->setEmail('multiple-subkeys@example.com'); | |
209 $key->addUserId($userId); | |
210 | |
211 $subKey = new Crypt_GPG_SubKey(); | |
212 $subKey->setId('B07A621DC9295765'); | |
213 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); | |
214 $subKey->setFingerprint('F9DF21B5D2DD02D3DF760270B07A621DC9295765'); | |
215 $subKey->setLength(1024); | |
216 $subKey->setCreationDate(1232605399); | |
217 $subKey->setExpirationDate(0); | |
218 $subKey->setUsage(Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_CERTIFY | Crypt_GPG_SubKey::USAGE_AUTHENTICATION); | |
219 $subKey->setHasPrivate(true); | |
220 $key->addSubKey($subKey); | |
221 | |
222 $subKey = new Crypt_GPG_SubKey(); | |
223 $subKey->setId('6F941ACC362453DA'); | |
224 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); | |
225 $subKey->setFingerprint('A728EE198BA2FB5C7B1C8B896F941ACC362453DA'); | |
226 $subKey->setLength(2048); | |
227 $subKey->setCreationDate(1232605407); | |
228 $subKey->setExpirationDate(0); | |
229 $subKey->setCanSign(false); | |
230 $subKey->setCanEncrypt(true); | |
231 $subKey->setHasPrivate(true); | |
232 $key->addSubKey($subKey); | |
233 | |
234 $subKey = new Crypt_GPG_SubKey(); | |
235 $subKey->setId('2921E0D3FF5B0F4A'); | |
236 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_RSA); | |
237 $subKey->setFingerprint('E1363DCE4863B824813AB2702921E0D3FF5B0F4A'); | |
238 $subKey->setLength(2048); | |
239 $subKey->setCreationDate(1232605437); | |
240 $subKey->setExpirationDate(0); | |
241 $subKey->setCanSign(false); | |
242 $subKey->setCanEncrypt(true); | |
243 $subKey->setHasPrivate(true); | |
244 $key->addSubKey($subKey); | |
245 // }}} | |
246 | |
247 $keys = $this->gpg->getKeys(); | |
248 $this->assertEquals($expectedKeys, $keys); | |
249 } | |
250 | |
251 // }}} | |
252 // {{{ testGetKeysWithKeyId() | |
253 | |
254 /** | |
255 * @group get-keys | |
256 */ | |
257 public function testGetKeysWithKeyId() | |
258 { | |
259 $keyId = 'first-keypair@example.com'; | |
260 $expectedKeys = array(); | |
261 | |
262 // {{{ first-keypair@example.com | |
263 $key = new Crypt_GPG_Key(); | |
264 $expectedKeys[] = $key; | |
265 | |
266 $userId = new Crypt_GPG_UserId(); | |
267 $userId->setName('First Keypair Test Key'); | |
268 $userId->setComment('do not encrypt important data with this key'); | |
269 $userId->setEmail('first-keypair@example.com'); | |
270 $key->addUserId($userId); | |
271 | |
272 $subKey = new Crypt_GPG_SubKey(); | |
273 $subKey->setId('C097D9EC94C06363'); | |
274 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); | |
275 $subKey->setFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
276 $subKey->setLength(1024); | |
277 $subKey->setCreationDate(1221785805); | |
278 $subKey->setExpirationDate(0); | |
279 $subKey->setUsage(Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_CERTIFY); | |
280 $subKey->setHasPrivate(true); | |
281 $key->addSubKey($subKey); | |
282 | |
283 $subKey = new Crypt_GPG_SubKey(); | |
284 $subKey->setId('9F93F9116728EF12'); | |
285 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); | |
286 $subKey->setFingerprint('C9C65B3BBF040E40D0EA27B79F93F9116728EF12'); | |
287 $subKey->setLength(2048); | |
288 $subKey->setCreationDate(1221785821); | |
289 $subKey->setExpirationDate(0); | |
290 $subKey->setCanSign(false); | |
291 $subKey->setCanEncrypt(true); | |
292 $subKey->setHasPrivate(true); | |
293 $key->addSubKey($subKey); | |
294 // }}} | |
295 | |
296 $keys = $this->gpg->getKeys($keyId); | |
297 $this->assertEquals($expectedKeys, $keys); | |
298 } | |
299 | |
300 // }}} | |
301 // {{{ testGetKeysNone() | |
302 | |
303 /** | |
304 * @group get-keys | |
305 */ | |
306 public function testGetKeysNone() | |
307 { | |
308 $keyId = 'non-existent-key@example.com'; | |
309 $expectedKeys = array(); | |
310 $keys = $this->gpg->getKeys($keyId); | |
311 $this->assertEquals($expectedKeys, $keys); | |
312 } | |
313 | |
314 // }}} | |
315 } | |
316 | |
317 ?> |