Improve tests and make them independent

This commit is contained in:
Jakub Zelenka 2016-12-11 19:36:15 +00:00
parent a0ffb76eca
commit 3d298a4f38
26 changed files with 152 additions and 82 deletions

2
.gitignore vendored
View file

@ -63,8 +63,10 @@ tests/*.log
tests/*.out tests/*.out
tests/*.php tests/*.php
tests/*.sh tests/*.sh
tests/pubring.gpg
tests/pubring.kbx tests/pubring.kbx
tests/random_seed tests/random_seed
tests/secring.gpg
tests/sshcontrol tests/sshcontrol
tests/trustdb.gpg tests/trustdb.gpg

View file

@ -4,12 +4,11 @@ import a new key into the keyring
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
@unlink (dirname(__FILE__)."/pubring.gpg"); gnupg_test_clear_files();
@unlink (dirname(__FILE__)."/secring.gpg");
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg -> import($testkey); $ret = $gpg->import($testkey);
var_dump($ret); var_dump($ret);
?> ?>
--EXPECT-- --EXPECT--

View file

@ -4,16 +4,18 @@ encrypt and decrypt a text
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$gpg -> addencryptkey($fingerprint); $gpg->addencryptkey($fingerprint);
$enc = $gpg -> encrypt($plaintext); $enc = $gpg->encrypt($plaintext);
$gpg = NULL; $gpg = NULL;
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> adddecryptkey($fingerprint, $passphrase); $gpg->adddecryptkey($fingerprint, $passphrase);
$ret = $gpg -> decrypt ($enc); $ret = $gpg->decrypt($enc);
var_dump($ret); var_dump($ret);
?> ?>

View file

@ -4,19 +4,21 @@ encryptsign and decryptverify a text
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$gpg -> addencryptkey($fingerprint); $gpg->addencryptkey($fingerprint);
$gpg -> addsignkey($fingerprint, $passphrase); $gpg->addsignkey($fingerprint, $passphrase);
$enc = $gpg -> encryptsign($plaintext); $enc = $gpg->encryptsign($plaintext);
$gpg = NULL; $gpg = NULL;
$plaintext = false; $plaintext = false;
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> adddecryptkey($fingerprint, $passphrase); $gpg->adddecryptkey($fingerprint, $passphrase);
$ret = $gpg -> decryptverify ($enc, $plaintext); $ret = $gpg->decryptverify ($enc, $plaintext);
var_dump($ret); var_dump($ret);
var_dump($plaintext); var_dump($plaintext);

View file

@ -4,10 +4,12 @@ export a key
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg -> export($fingerprint); $ret = $gpg->export($fingerprint);
var_dump($ret); var_dump($ret);
?> ?>
--EXPECTF-- --EXPECTF--

View file

@ -4,10 +4,12 @@ get keyinfo
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg -> keyinfo($fingerprint); $ret = $gpg->keyinfo($fingerprint);
var_dump($ret); var_dump($ret);
?> ?>
--EXPECT-- --EXPECT--

View file

@ -4,10 +4,12 @@ list signatures
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg -> listsignatures($fingerprint); $ret = $gpg->listsignatures($fingerprint);
var_dump($ret); var_dump($ret);
?> ?>
--EXPECT-- --EXPECT--

View file

@ -4,18 +4,20 @@ sign a text with sigmode SIG_MODE_CLEAR
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$gpg -> setsignmode(gnupg::SIG_MODE_CLEAR); $gpg->setsignmode(gnupg::SIG_MODE_CLEAR);
$gpg -> addsignkey($fingerprint, $passphrase); $gpg->addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext); $ret = $gpg->sign($plaintext);
$gpg = NULL; $gpg = NULL;
$gpg = new gnupg(); $gpg = new gnupg();
$tmp = false; $tmp = false;
$ret = $gpg -> verify($ret, false, $tmp); $ret = $gpg->verify($ret, false, $tmp);
var_dump($ret); var_dump($ret);
var_dump($tmp); var_dump($tmp);

View file

@ -4,18 +4,20 @@ sign a text with mode SIG_MODE_DETACH
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$gpg -> setsignmode(gnupg::SIG_MODE_DETACH); $gpg->setsignmode(gnupg::SIG_MODE_DETACH);
$gpg -> addsignkey($fingerprint, $passphrase); $gpg->addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext); $ret = $gpg->sign($plaintext);
$gpg = NULL; $gpg = NULL;
$gpg = new gnupg(); $gpg = new gnupg();
$tmp = false; $tmp = false;
$ret = $gpg -> verify($plaintext, $ret); $ret = $gpg->verify($plaintext, $ret);
var_dump($ret); var_dump($ret);
var_dump($plaintext); var_dump($plaintext);

View file

@ -4,19 +4,21 @@ sign a text with mode SIG_MODE_DETACH and without armored output
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$gpg -> setarmor(0); $gpg->setarmor(0);
$gpg -> setsignmode(gnupg::SIG_MODE_DETACH); $gpg->setsignmode(gnupg::SIG_MODE_DETACH);
$gpg -> addsignkey($fingerprint, $passphrase); $gpg->addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext); $ret = $gpg->sign($plaintext);
$gpg = NULL; $gpg = NULL;
$gpg = new gnupg(); $gpg = new gnupg();
$tmp = false; $tmp = false;
$ret = $gpg -> verify($plaintext, $ret); $ret = $gpg->verify($plaintext, $ret);
var_dump($ret); var_dump($ret);
var_dump($plaintext); var_dump($plaintext);

View file

@ -4,19 +4,21 @@ sign a text with mode SIG_MODE_NORMAL
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$gpg -> setsignmode(gnupg::SIG_MODE_NORMAL); $gpg->setsignmode(gnupg::SIG_MODE_NORMAL);
$gpg -> addsignkey($fingerprint, $passphrase); $gpg->addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext); $ret = $gpg->sign($plaintext);
$gpg = NULL; $gpg = NULL;
$gpg = new gnupg(); $gpg = new gnupg();
$tmp = false; $tmp = false;
$plaintext = false; $plaintext = false;
$ret = $gpg -> verify($ret, false, $plaintext); $ret = $gpg->verify($ret, false, $plaintext);
var_dump($ret); var_dump($ret);
var_dump($plaintext); var_dump($plaintext);

View file

@ -4,20 +4,22 @@ sign a text with mode SIG_MODE_NORMAL and without armored output
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$gpg -> setarmor(0); $gpg->setarmor(0);
$gpg -> setsignmode(gnupg::SIG_MODE_NORMAL); $gpg->setsignmode(gnupg::SIG_MODE_NORMAL);
$gpg -> addsignkey($fingerprint, $passphrase); $gpg->addsignkey($fingerprint, $passphrase);
$ret = $gpg -> sign($plaintext); $ret = $gpg->sign($plaintext);
$gpg = NULL; $gpg = NULL;
$gpg = new gnupg(); $gpg = new gnupg();
//$ret = $gpg -> verify($plaintext, $ret); //$ret = $gpg->verify($plaintext, $ret);
$plaintext = false; $plaintext = false;
$ret = $gpg -> verify($ret, false, $plaintext); $ret = $gpg->verify($ret, false, $plaintext);
var_dump($ret); var_dump($ret);
var_dump($plaintext); var_dump($plaintext);

View file

@ -4,10 +4,12 @@ delete a key from the keyring
<?php if(!class_exists("gnupg")) die("skip"); ?> <?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg -> seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg -> deletekey($fingerprint,true); $ret = $gpg->deletekey($fingerprint,true);
var_dump($ret); var_dump($ret);
?> ?>
--EXPECT-- --EXPECT--

View file

@ -2,9 +2,9 @@
import a new key into the keyring import a new key into the keyring
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
@unlink (dirname(__FILE__)."/pubring.gpg"); gnupg_test_clear_files();
@unlink (dirname(__FILE__)."/secring.gpg");
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
$ret = gnupg_import($gpg, $testkey); $ret = gnupg_import($gpg, $testkey);

View file

@ -2,7 +2,9 @@
encrypt and decrypt a text encrypt and decrypt a text
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
gnupg_addencryptkey($gpg, $fingerprint); gnupg_addencryptkey($gpg, $fingerprint);

View file

@ -2,7 +2,9 @@
encryptsign and decryptverify a text encryptsign and decryptverify a text
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
gnupg_addencryptkey($gpg, $fingerprint); gnupg_addencryptkey($gpg, $fingerprint);

View file

@ -2,7 +2,9 @@
export a key export a key
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
$ret = gnupg_export($gpg, $fingerprint); $ret = gnupg_export($gpg, $fingerprint);

View file

@ -2,7 +2,9 @@
get keyinfo get keyinfo
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
$ret = gnupg_keyinfo($gpg, $fingerprint); $ret = gnupg_keyinfo($gpg, $fingerprint);

View file

@ -2,7 +2,9 @@
list signatures list signatures
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
$ret = gnupg_listsignatures($gpg, $fingerprint); $ret = gnupg_listsignatures($gpg, $fingerprint);

View file

@ -2,7 +2,9 @@
sign a text with sigmode SIG_MODE_CLEAR sign a text with sigmode SIG_MODE_CLEAR
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
gnupg_setsignmode($gpg, GNUPG_SIG_MODE_CLEAR); gnupg_setsignmode($gpg, GNUPG_SIG_MODE_CLEAR);

View file

@ -2,7 +2,9 @@
sign a text with mode SIG_MODE_DETACH sign a text with mode SIG_MODE_DETACH
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
gnupg_setsignmode($gpg, GNUPG_SIG_MODE_DETACH); gnupg_setsignmode($gpg, GNUPG_SIG_MODE_DETACH);

View file

@ -2,7 +2,9 @@
sign a text with mode SIG_MODE_DETACH and without armored output sign a text with mode SIG_MODE_DETACH and without armored output
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
gnupg_setarmor($gpg, 0); gnupg_setarmor($gpg, 0);

View file

@ -2,7 +2,9 @@
sign a text with mode SIG_MODE_NORMAL sign a text with mode SIG_MODE_NORMAL
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
gnupg_setsignmode($gpg, GNUPG_SIG_MODE_NORMAL); gnupg_setsignmode($gpg, GNUPG_SIG_MODE_NORMAL);

View file

@ -2,7 +2,9 @@
sign a text with mode SIG_MODE_NORMAL and without armored output sign a text with mode SIG_MODE_NORMAL and without armored output
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
gnupg_setarmor($gpg, 0); gnupg_setarmor($gpg, 0);

View file

@ -2,7 +2,9 @@
delete a key from the keyring delete a key from the keyring
--FILE-- --FILE--
<?php <?php
require_once(dirname(__FILE__)."/vars.inc"); require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
$ret = gnupg_deletekey($gpg, $fingerprint,true); $ret = gnupg_deletekey($gpg, $fingerprint,true);

View file

@ -1,10 +1,11 @@
<?php <?php
putenv("GNUPGHOME=".dirname(__FILE__)); putenv("GNUPGHOME=" . dirname(__FILE__));
error_reporting (E_ALL); error_reporting(E_ALL);
$fingerprint = "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"; $fingerprint = "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E";
$passphrase = "blabla"; $passphrase = "blabla";
$plaintext = "foo bar"; $plaintext = "foo bar";
$secringfile = dirname(__FILE__) . "/secring.gpg";
$pubringfile = dirname(__FILE__) . "/pubring.gpg";
$testkey =<<<EOF $testkey =<<<EOF
-----BEGIN PGP PRIVATE KEY BLOCK----- -----BEGIN PGP PRIVATE KEY BLOCK-----
@ -35,4 +36,28 @@ BjoYSlJsrQm0AJ4m57ArwLXA7WXk5iQbMWlvhWCq4g==
=awlp =awlp
-----END PGP PRIVATE KEY BLOCK----- -----END PGP PRIVATE KEY BLOCK-----
EOF; 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;
}
?> ?>