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/*.php
tests/*.sh
tests/pubring.gpg
tests/pubring.kbx
tests/random_seed
tests/secring.gpg
tests/sshcontrol
tests/trustdb.gpg

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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"); ?>
--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);

View file

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

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"); ?>
--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);

View file

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

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

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