mirror of
https://github.com/php-gnupg/php-gnupg.git
synced 2024-11-22 14:27:09 +00:00
Improve tests and make them independent
This commit is contained in:
parent
a0ffb76eca
commit
3d298a4f38
26 changed files with 152 additions and 82 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -63,8 +63,10 @@ tests/*.log
|
|||
tests/*.out
|
||||
tests/*.php
|
||||
tests/*.sh
|
||||
tests/pubring.gpg
|
||||
tests/pubring.kbx
|
||||
tests/random_seed
|
||||
tests/secring.gpg
|
||||
tests/sshcontrol
|
||||
tests/trustdb.gpg
|
||||
|
||||
|
|
|
@ -4,12 +4,11 @@ import a new key into the keyring
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
@unlink (dirname(__FILE__)."/pubring.gpg");
|
||||
@unlink (dirname(__FILE__)."/secring.gpg");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_clear_files();
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg -> import($testkey);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg->import($testkey);
|
||||
var_dump($ret);
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
|
@ -4,16 +4,18 @@ encrypt and decrypt a text
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg -> addencryptkey($fingerprint);
|
||||
$enc = $gpg -> encrypt($plaintext);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg->addencryptkey($fingerprint);
|
||||
$enc = $gpg->encrypt($plaintext);
|
||||
$gpg = NULL;
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> adddecryptkey($fingerprint, $passphrase);
|
||||
$ret = $gpg -> decrypt ($enc);
|
||||
$gpg->adddecryptkey($fingerprint, $passphrase);
|
||||
$ret = $gpg->decrypt($enc);
|
||||
|
||||
var_dump($ret);
|
||||
?>
|
||||
|
|
|
@ -4,19 +4,21 @@ encryptsign and decryptverify a text
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg -> addencryptkey($fingerprint);
|
||||
$gpg -> addsignkey($fingerprint, $passphrase);
|
||||
$enc = $gpg -> encryptsign($plaintext);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg->addencryptkey($fingerprint);
|
||||
$gpg->addsignkey($fingerprint, $passphrase);
|
||||
$enc = $gpg->encryptsign($plaintext);
|
||||
|
||||
$gpg = NULL;
|
||||
$plaintext = false;
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> adddecryptkey($fingerprint, $passphrase);
|
||||
$ret = $gpg -> decryptverify ($enc, $plaintext);
|
||||
$gpg->adddecryptkey($fingerprint, $passphrase);
|
||||
$ret = $gpg->decryptverify ($enc, $plaintext);
|
||||
|
||||
var_dump($ret);
|
||||
var_dump($plaintext);
|
||||
|
|
|
@ -4,10 +4,12 @@ export a key
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg -> export($fingerprint);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg->export($fingerprint);
|
||||
var_dump($ret);
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
|
|
@ -4,10 +4,12 @@ get keyinfo
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg -> keyinfo($fingerprint);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg->keyinfo($fingerprint);
|
||||
var_dump($ret);
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
|
@ -4,10 +4,12 @@ list signatures
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg -> listsignatures($fingerprint);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg->listsignatures($fingerprint);
|
||||
var_dump($ret);
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
|
@ -4,18 +4,20 @@ sign a text with sigmode SIG_MODE_CLEAR
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg -> setsignmode(gnupg::SIG_MODE_CLEAR);
|
||||
$gpg -> addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg -> sign($plaintext);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg->setsignmode(gnupg::SIG_MODE_CLEAR);
|
||||
$gpg->addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg->sign($plaintext);
|
||||
|
||||
$gpg = NULL;
|
||||
|
||||
$gpg = new gnupg();
|
||||
$tmp = false;
|
||||
$ret = $gpg -> verify($ret, false, $tmp);
|
||||
$ret = $gpg->verify($ret, false, $tmp);
|
||||
|
||||
var_dump($ret);
|
||||
var_dump($tmp);
|
||||
|
|
|
@ -4,18 +4,20 @@ sign a text with mode SIG_MODE_DETACH
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg -> setsignmode(gnupg::SIG_MODE_DETACH);
|
||||
$gpg -> addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg -> sign($plaintext);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg->setsignmode(gnupg::SIG_MODE_DETACH);
|
||||
$gpg->addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg->sign($plaintext);
|
||||
|
||||
$gpg = NULL;
|
||||
|
||||
$gpg = new gnupg();
|
||||
$tmp = false;
|
||||
$ret = $gpg -> verify($plaintext, $ret);
|
||||
$ret = $gpg->verify($plaintext, $ret);
|
||||
|
||||
var_dump($ret);
|
||||
var_dump($plaintext);
|
||||
|
|
|
@ -4,19 +4,21 @@ sign a text with mode SIG_MODE_DETACH and without armored output
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg -> setarmor(0);
|
||||
$gpg -> setsignmode(gnupg::SIG_MODE_DETACH);
|
||||
$gpg -> addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg -> sign($plaintext);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg->setarmor(0);
|
||||
$gpg->setsignmode(gnupg::SIG_MODE_DETACH);
|
||||
$gpg->addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg->sign($plaintext);
|
||||
|
||||
$gpg = NULL;
|
||||
|
||||
$gpg = new gnupg();
|
||||
$tmp = false;
|
||||
$ret = $gpg -> verify($plaintext, $ret);
|
||||
$ret = $gpg->verify($plaintext, $ret);
|
||||
|
||||
var_dump($ret);
|
||||
var_dump($plaintext);
|
||||
|
|
|
@ -4,19 +4,21 @@ sign a text with mode SIG_MODE_NORMAL
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg -> setsignmode(gnupg::SIG_MODE_NORMAL);
|
||||
$gpg -> addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg -> sign($plaintext);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg->setsignmode(gnupg::SIG_MODE_NORMAL);
|
||||
$gpg->addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg->sign($plaintext);
|
||||
|
||||
$gpg = NULL;
|
||||
|
||||
$gpg = new gnupg();
|
||||
$tmp = false;
|
||||
$plaintext = false;
|
||||
$ret = $gpg -> verify($ret, false, $plaintext);
|
||||
$ret = $gpg->verify($ret, false, $plaintext);
|
||||
|
||||
var_dump($ret);
|
||||
var_dump($plaintext);
|
||||
|
|
|
@ -4,20 +4,22 @@ sign a text with mode SIG_MODE_NORMAL and without armored output
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg -> setarmor(0);
|
||||
$gpg -> setsignmode(gnupg::SIG_MODE_NORMAL);
|
||||
$gpg -> addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg -> sign($plaintext);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$gpg->setarmor(0);
|
||||
$gpg->setsignmode(gnupg::SIG_MODE_NORMAL);
|
||||
$gpg->addsignkey($fingerprint, $passphrase);
|
||||
$ret = $gpg->sign($plaintext);
|
||||
|
||||
$gpg = NULL;
|
||||
|
||||
$gpg = new gnupg();
|
||||
//$ret = $gpg -> verify($plaintext, $ret);
|
||||
//$ret = $gpg->verify($plaintext, $ret);
|
||||
$plaintext = false;
|
||||
$ret = $gpg -> verify($ret, false, $plaintext);
|
||||
$ret = $gpg->verify($ret, false, $plaintext);
|
||||
|
||||
var_dump($ret);
|
||||
var_dump($plaintext);
|
||||
|
|
|
@ -4,10 +4,12 @@ delete a key from the keyring
|
|||
<?php if(!class_exists("gnupg")) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg -> seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg -> deletekey($fingerprint,true);
|
||||
$gpg->seterrormode(gnupg::ERROR_WARNING);
|
||||
$ret = $gpg->deletekey($fingerprint,true);
|
||||
var_dump($ret);
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
import a new key into the keyring
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
@unlink (dirname(__FILE__)."/pubring.gpg");
|
||||
@unlink (dirname(__FILE__)."/secring.gpg");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_clear_files();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
$ret = gnupg_import($gpg, $testkey);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
encrypt and decrypt a text
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
gnupg_addencryptkey($gpg, $fingerprint);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
encryptsign and decryptverify a text
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
gnupg_addencryptkey($gpg, $fingerprint);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
export a key
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
$ret = gnupg_export($gpg, $fingerprint);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
get keyinfo
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
$ret = gnupg_keyinfo($gpg, $fingerprint);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
list signatures
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
$ret = gnupg_listsignatures($gpg, $fingerprint);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
sign a text with sigmode SIG_MODE_CLEAR
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
gnupg_setsignmode($gpg, GNUPG_SIG_MODE_CLEAR);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
sign a text with mode SIG_MODE_DETACH
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
gnupg_setsignmode($gpg, GNUPG_SIG_MODE_DETACH);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
sign a text with mode SIG_MODE_DETACH and without armored output
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
gnupg_setarmor($gpg, 0);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
sign a text with mode SIG_MODE_NORMAL
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
gnupg_setsignmode($gpg, GNUPG_SIG_MODE_NORMAL);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
sign a text with mode SIG_MODE_NORMAL and without armored output
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
gnupg_setarmor($gpg, 0);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
delete a key from the keyring
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/vars.inc");
|
||||
require_once dirname(__FILE__) . "/vars.inc";
|
||||
gnupg_test_import();
|
||||
|
||||
$gpg = gnupg_init();
|
||||
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
||||
$ret = gnupg_deletekey($gpg, $fingerprint,true);
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
putenv("GNUPGHOME=".dirname(__FILE__));
|
||||
error_reporting (E_ALL);
|
||||
putenv("GNUPGHOME=" . dirname(__FILE__));
|
||||
error_reporting(E_ALL);
|
||||
$fingerprint = "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E";
|
||||
$passphrase = "blabla";
|
||||
|
||||
$plaintext = "foo bar";
|
||||
$secringfile = dirname(__FILE__) . "/secring.gpg";
|
||||
$pubringfile = dirname(__FILE__) . "/pubring.gpg";
|
||||
|
||||
$testkey =<<<EOF
|
||||
-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||
|
@ -35,4 +36,28 @@ BjoYSlJsrQm0AJ4m57ArwLXA7WXk5iQbMWlvhWCq4g==
|
|||
=awlp
|
||||
-----END PGP PRIVATE KEY BLOCK-----
|
||||
EOF;
|
||||
|
||||
function gnupg_test_clear_files() {
|
||||
global $secringfile, $pubringfile;
|
||||
|
||||
if (is_file($secringfile)) {
|
||||
unlink($secringfile);
|
||||
}
|
||||
if (is_file($pubringfile)) {
|
||||
unlink($pubringfile);
|
||||
}
|
||||
}
|
||||
|
||||
function gnupg_test_import() {
|
||||
global $secringfile, $testkey;
|
||||
|
||||
if (!file_exists($secringfile) || !filesize($secringfile)) {
|
||||
$gpg = new gnupg();
|
||||
return $gpg->import($testkey);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
|
Loading…
Reference in a new issue