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,9 +4,8 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

View file

@ -4,7 +4,9 @@ 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);

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

@ -3,8 +3,9 @@ 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;
}
?> ?>