Mercurial > hg > rc1
comparison vendor/pear/crypt_gpg/tests/ExportPrivateKeyTest.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 export 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 ExportPrivateKeyTestCase | |
| 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 export 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 ExportPrivateKeyTestCase extends Crypt_GPG_TestCase | |
| 59 { | |
| 60 // {{{ testExportPrivateKey() | |
| 61 | |
| 62 /** | |
| 63 * @group export | |
| 64 */ | |
| 65 public function testExportPrivateKey() | |
| 66 { | |
| 67 $keyId = 'no-passphrase@example.com'; | |
| 68 | |
| 69 // We can't expect the key data to be identical as the one | |
| 70 // at the creation time, so we only check if it's valid format | |
| 71 $expectedKeyData = "-----END PGP PRIVATE KEY BLOCK-----"; | |
| 72 | |
| 73 // Note: This operation expects passphrase in GnuPG 2.1 < 2.1.15 | |
| 74 // because of https://bugs.gnupg.org/gnupg/issue2070. | |
| 75 | |
| 76 $keyData = $this->gpg->exportPrivateKey($keyId); | |
| 77 | |
| 78 $this->assertContains($expectedKeyData, $keyData); | |
| 79 } | |
| 80 | |
| 81 // }}} | |
| 82 // {{{ testExportPrivateKey_with_good_pass() | |
| 83 | |
| 84 /** | |
| 85 * @group export | |
| 86 */ | |
| 87 public function testExportPrivateKey_with_good_pass() | |
| 88 { | |
| 89 if (version_compare($this->gpg->getVersion(), '2.1.0', 'lt')) { | |
| 90 $this->markTestSkipped('GnuPG >= 2.1 requires passphrase to export private key.'); | |
| 91 } | |
| 92 | |
| 93 $keyId = 'first-keypair@example.com'; | |
| 94 | |
| 95 // This operation requires passphrase in GnuPG 2.1 | |
| 96 $this->gpg->addPassphrase('94C06363', 'test1'); | |
| 97 | |
| 98 $keyData = $this->gpg->exportPrivateKey($keyId); | |
| 99 | |
| 100 // Here we're really testing only the passphrase handling in GnuPG 2.1 | |
| 101 $this->assertContains('PGP PRIVATE KEY', $keyData); | |
| 102 } | |
| 103 | |
| 104 // }}} | |
| 105 // {{{ testExportPrivateKey_with_bad_pass() | |
| 106 | |
| 107 /** | |
| 108 * @expectedException Crypt_GPG_BadPassphraseException | |
| 109 * | |
| 110 * @group export | |
| 111 */ | |
| 112 public function testExportPrivateKey_with_bad_pass() | |
| 113 { | |
| 114 if (version_compare($this->gpg->getVersion(), '2.1.0', 'lt')) { | |
| 115 $this->markTestSkipped('GnuPG >= 2.1 requires passphrase to export private key.'); | |
| 116 } | |
| 117 | |
| 118 $keyId = 'first-keypair@example.com'; | |
| 119 | |
| 120 // This operation requires passphrase in GnuPG 2.1 | |
| 121 $this->gpg->addPassphrase('94C06363', 'bad'); | |
| 122 | |
| 123 $keyData = $this->gpg->exportPrivateKey($keyId); | |
| 124 } | |
| 125 | |
| 126 // }}} | |
| 127 // {{{ testExportPrivateKeyNotFoundException() | |
| 128 | |
| 129 /** | |
| 130 * @expectedException Crypt_GPG_KeyNotFoundException | |
| 131 * | |
| 132 * @group export | |
| 133 */ | |
| 134 public function testExportPrivateKeyNotFoundException() | |
| 135 { | |
| 136 $keyId = 'non-existent-key@example.com'; | |
| 137 $this->gpg->exportPrivateKey($keyId); | |
| 138 } | |
| 139 | |
| 140 // }}} | |
| 141 } | |
| 142 | |
| 143 ?> |
