Mercurial > hg > rc1
comparison vendor/pear/crypt_gpg/tests/DeletePrivateKeyTest.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 * Private key deletion 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 DeletePrivateKeyTestCase | |
| 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 private key deletion abilities 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 DeletePrivateKeyTestCase extends Crypt_GPG_TestCase | |
| 59 { | |
| 60 // {{{ testDeletePrivateKey() | |
| 61 | |
| 62 /** | |
| 63 * @group delete-private | |
| 64 */ | |
| 65 public function testDeletePrivateKey() | |
| 66 { | |
| 67 $keyId = 'first-keypair@example.com'; | |
| 68 $this->gpg->deletePrivateKey($keyId); | |
| 69 | |
| 70 $expectedKeys = array(); | |
| 71 | |
| 72 // {{{ first-keypair@example.com | |
| 73 $key = new Crypt_GPG_Key(); | |
| 74 $expectedKeys[] = $key; | |
| 75 | |
| 76 $userId = new Crypt_GPG_UserId(); | |
| 77 $userId->setName('First Keypair Test Key'); | |
| 78 $userId->setComment('do not encrypt important data with this key'); | |
| 79 $userId->setEmail('first-keypair@example.com'); | |
| 80 $key->addUserId($userId); | |
| 81 | |
| 82 $subKey = new Crypt_GPG_SubKey(); | |
| 83 $subKey->setId('C097D9EC94C06363'); | |
| 84 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); | |
| 85 $subKey->setFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 86 $subKey->setLength(1024); | |
| 87 $subKey->setCreationDate(1221785805); | |
| 88 $subKey->setExpirationDate(0); | |
| 89 $subKey->setUsage(Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_CERTIFY); | |
| 90 $subKey->setHasPrivate(false); | |
| 91 $key->addSubKey($subKey); | |
| 92 | |
| 93 $subKey = new Crypt_GPG_SubKey(); | |
| 94 $subKey->setId('9F93F9116728EF12'); | |
| 95 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); | |
| 96 $subKey->setFingerprint('C9C65B3BBF040E40D0EA27B79F93F9116728EF12'); | |
| 97 $subKey->setLength(2048); | |
| 98 $subKey->setCreationDate(1221785821); | |
| 99 $subKey->setExpirationDate(0); | |
| 100 $subKey->setCanSign(false); | |
| 101 $subKey->setCanEncrypt(true); | |
| 102 $subKey->setHasPrivate(false); | |
| 103 $key->addSubKey($subKey); | |
| 104 // }}} | |
| 105 | |
| 106 $keys = $this->gpg->getKeys($keyId); | |
| 107 $this->assertEquals($expectedKeys, $keys); | |
| 108 } | |
| 109 | |
| 110 // }}} | |
| 111 // {{{ testDeletePrivateKeyNotFoundException() | |
| 112 | |
| 113 /** | |
| 114 * @expectedException Crypt_GPG_KeyNotFoundException | |
| 115 * | |
| 116 * @group delete-private | |
| 117 */ | |
| 118 public function testDeletePrivateKeyNotFoundException() | |
| 119 { | |
| 120 $keyId = 'non-existent-key@example.com'; | |
| 121 $this->gpg->deletePrivateKey($keyId); | |
| 122 } | |
| 123 | |
| 124 // }}} | |
| 125 // {{{ testDeletePrivateKeyNotFoundException_public_only() | |
| 126 | |
| 127 /** | |
| 128 * @expectedException Crypt_GPG_KeyNotFoundException | |
| 129 * | |
| 130 * @group delete-private | |
| 131 */ | |
| 132 public function testDeletePrivateKeyNotFoundException_public_only() | |
| 133 { | |
| 134 $keyId = 'public-only@example.com'; | |
| 135 $this->gpg->deletePrivateKey($keyId); | |
| 136 } | |
| 137 | |
| 138 // }}} | |
| 139 } | |
| 140 | |
| 141 ?> |
