From 4aabe3c9664a728cf5226c42e293053c6eaf38a6 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Thu, 17 May 2018 20:15:14 +0100 Subject: [PATCH] Refactore all test to be independent --- tests/gnupg_oo_deletekey.phpt | 21 ++++++++++++++ tests/gnupg_oo_encrypt.phpt | 22 +++++++++----- tests/gnupg_oo_encryptsign.phpt | 25 +++++++++------- tests/gnupg_oo_export.phpt | 14 ++++++--- ..._0001_import.phpt => gnupg_oo_import.phpt} | 17 +++++++---- tests/gnupg_oo_keyinfo.phpt | 13 +++++++-- tests/gnupg_oo_listsignatures.phpt | 15 +++++++--- tests/gnupg_oo_sign_clear.phpt | 19 ++++++++---- tests/gnupg_oo_sign_detach.phpt | 19 ++++++++---- tests/gnupg_oo_sign_detach_nonarmor.phpt | 23 ++++++++++----- tests/gnupg_oo_sign_normal.phpt | 21 +++++++++----- tests/gnupg_oo_sign_normal_noarmor.phpt | 29 +++++++++++-------- tests/gnupg_oo_zzz_deletekey.phpt | 14 --------- tests/gnupg_res_0001_import.phpt | 15 +++++++--- ...eletekey.phpt => gnupg_res_deletekey.phpt} | 11 ++++++- tests/gnupg_res_encrypt.phpt | 11 ++++++- tests/gnupg_res_encryptsign.phpt | 11 ++++++- tests/gnupg_res_export.phpt | 12 ++++++-- tests/gnupg_res_keyinfo.phpt | 11 ++++++- tests/gnupg_res_listsignatures.phpt | 11 ++++++- tests/gnupg_res_sign_clear.phpt | 13 +++++++-- tests/gnupg_res_sign_detach.phpt | 13 +++++++-- tests/gnupg_res_sign_detach_nonarmor.phpt | 11 ++++++- tests/gnupg_res_sign_normal.phpt | 11 ++++++- tests/gnupg_res_sign_normal_noarmor.phpt | 11 ++++++- tests/gnupgt.inc | 21 ++++++++++++++ 26 files changed, 306 insertions(+), 108 deletions(-) create mode 100644 tests/gnupg_oo_deletekey.phpt rename tests/{gnupg_oo_0001_import.phpt => gnupg_oo_import.phpt} (68%) delete mode 100644 tests/gnupg_oo_zzz_deletekey.phpt rename tests/{gnupg_res_zzz_deletekey.phpt => gnupg_res_deletekey.phpt} (53%) create mode 100644 tests/gnupgt.inc diff --git a/tests/gnupg_oo_deletekey.phpt b/tests/gnupg_oo_deletekey.phpt new file mode 100644 index 0000000..6366752 --- /dev/null +++ b/tests/gnupg_oo_deletekey.phpt @@ -0,0 +1,21 @@ +--TEST-- +delete a key from the keyring +--SKIPIF-- + +--FILE-- +seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->deletekey($fingerprint,true); +var_dump($ret); +?> +--EXPECT-- +bool(true) +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_encrypt.phpt b/tests/gnupg_oo_encrypt.phpt index be415af..b32be83 100644 --- a/tests/gnupg_oo_encrypt.phpt +++ b/tests/gnupg_oo_encrypt.phpt @@ -4,18 +4,24 @@ encrypt and decrypt a text --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> addencryptkey($fingerprint); -$enc = $gpg -> encrypt($plaintext); -$gpg = NULL; +require_once "gnupgt.inc"; +gnupgt::import_key(); $gpg = new gnupg(); -$gpg -> adddecryptkey($fingerprint, $passphrase); -$ret = $gpg -> decrypt ($enc); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$gpg->addencryptkey($fingerprint); +$enc = $gpg->encrypt($plaintext); + +$gpg = new gnupg(); +$gpg->adddecryptkey($fingerprint, $passphrase); +$ret = $gpg->decrypt($enc); var_dump($ret); ?> --EXPECTF-- string(7) "foo bar" +--CLEAN-- + diff --git a/tests/gnupg_oo_encryptsign.phpt b/tests/gnupg_oo_encryptsign.phpt index 801697b..d0de745 100644 --- a/tests/gnupg_oo_encryptsign.phpt +++ b/tests/gnupg_oo_encryptsign.phpt @@ -4,19 +4,19 @@ encryptsign and decryptverify a text --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> addencryptkey($fingerprint); -$gpg -> addsignkey($fingerprint, $passphrase); -$enc = $gpg -> encryptsign($plaintext); +require_once "gnupgt.inc"; +gnupgt::import_key(); + +$gpg = new gnupg(); +$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); @@ -38,3 +38,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_export.phpt b/tests/gnupg_oo_export.phpt index d94117f..cf0630b 100644 --- a/tests/gnupg_oo_export.phpt +++ b/tests/gnupg_oo_export.phpt @@ -4,15 +4,16 @@ export a key --FILE-- seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> export($fingerprint); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->export($fingerprint); var_dump($ret); ?> --EXPECTF-- string(%d) "-----BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v1 mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3 afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z @@ -36,3 +37,8 @@ drhhPQJw1AY6GEpSbK0JtACeJuewK8C1wO1l5OYkGzFpb4VgquI= =twR+ -----END PGP PUBLIC KEY BLOCK----- " +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_0001_import.phpt b/tests/gnupg_oo_import.phpt similarity index 68% rename from tests/gnupg_oo_0001_import.phpt rename to tests/gnupg_oo_import.phpt index 2c866d0..66f0e03 100644 --- a/tests/gnupg_oo_0001_import.phpt +++ b/tests/gnupg_oo_import.phpt @@ -1,15 +1,15 @@ ---TEST--n +--TEST-- import a new key into the keyring --SKIPIF-- --FILE-- seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> import($testkey); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->import($testkey); var_dump($ret); ?> --EXPECT-- @@ -33,3 +33,8 @@ array(9) { ["fingerprint"]=> string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" } +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_keyinfo.phpt b/tests/gnupg_oo_keyinfo.phpt index 9beb553..79ad9c6 100644 --- a/tests/gnupg_oo_keyinfo.phpt +++ b/tests/gnupg_oo_keyinfo.phpt @@ -4,10 +4,12 @@ get keyinfo --FILE-- seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> keyinfo($fingerprint); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->keyinfo($fingerprint); var_dump($ret); ?> --EXPECT-- @@ -99,3 +101,8 @@ array(1) { } } } +--CLEAN-- + diff --git a/tests/gnupg_oo_listsignatures.phpt b/tests/gnupg_oo_listsignatures.phpt index e8ea9ca..19db17b 100644 --- a/tests/gnupg_oo_listsignatures.phpt +++ b/tests/gnupg_oo_listsignatures.phpt @@ -1,13 +1,15 @@ ---TEST--n +--TEST-- list signatures --SKIPIF-- --FILE-- seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> listsignatures($fingerprint); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->listsignatures($fingerprint); var_dump($ret); ?> --EXPECT-- @@ -35,3 +37,8 @@ array(1) { } } } +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_clear.phpt b/tests/gnupg_oo_sign_clear.phpt index 2caefc9..40b3e84 100644 --- a/tests/gnupg_oo_sign_clear.phpt +++ b/tests/gnupg_oo_sign_clear.phpt @@ -4,18 +4,20 @@ sign a text with sigmode SIG_MODE_CLEAR --FILE-- 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); @@ -38,3 +40,8 @@ array(1) { } string(8) "foo bar " +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_detach.phpt b/tests/gnupg_oo_sign_detach.phpt index 79f81f2..feb9e30 100644 --- a/tests/gnupg_oo_sign_detach.phpt +++ b/tests/gnupg_oo_sign_detach.phpt @@ -4,18 +4,20 @@ sign a text with mode SIG_MODE_DETACH --FILE-- 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); @@ -37,3 +39,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_detach_nonarmor.phpt b/tests/gnupg_oo_sign_detach_nonarmor.phpt index 60f4e00..4642aaf 100644 --- a/tests/gnupg_oo_sign_detach_nonarmor.phpt +++ b/tests/gnupg_oo_sign_detach_nonarmor.phpt @@ -1,22 +1,24 @@ ---TEST--n +--TEST-- sign a text with mode SIG_MODE_DETACH and without armored output --SKIPIF-- --FILE-- 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); @@ -38,3 +40,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_normal.phpt b/tests/gnupg_oo_sign_normal.phpt index 4faf400..58d0117 100644 --- a/tests/gnupg_oo_sign_normal.phpt +++ b/tests/gnupg_oo_sign_normal.phpt @@ -1,22 +1,24 @@ ---TEST--n +--TEST-- sign a text with mode SIG_MODE_NORMAL --SKIPIF-- --FILE-- 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); @@ -38,3 +40,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_normal_noarmor.phpt b/tests/gnupg_oo_sign_normal_noarmor.phpt index 0651ce8..ee42f47 100644 --- a/tests/gnupg_oo_sign_normal_noarmor.phpt +++ b/tests/gnupg_oo_sign_normal_noarmor.phpt @@ -1,23 +1,23 @@ ---TEST--n +--TEST-- sign a text with mode SIG_MODE_NORMAL and without armored output --SKIPIF-- --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> setarmor(0); -$gpg -> setsignmode(gnupg::SIG_MODE_NORMAL); -$gpg -> addsignkey($fingerprint, $passphrase); -$ret = $gpg -> sign($plaintext); - -$gpg = NULL; +require_once "gnupgt.inc"; +gnupgt::import_key(); $gpg = new gnupg(); -//$ret = $gpg -> verify($plaintext, $ret); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$gpg->setarmor(0); +$gpg->setsignmode(gnupg::SIG_MODE_NORMAL); +$gpg->addsignkey($fingerprint, $passphrase); +$ret = $gpg->sign($plaintext); + +$gpg = new gnupg(); +//$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); @@ -39,3 +39,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_zzz_deletekey.phpt b/tests/gnupg_oo_zzz_deletekey.phpt deleted file mode 100644 index 46f6da0..0000000 --- a/tests/gnupg_oo_zzz_deletekey.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST--n -delete a key from the keyring ---SKIPIF-- - ---FILE-- - seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> deletekey($fingerprint,true); -var_dump($ret); -?> ---EXPECT-- -bool(true) diff --git a/tests/gnupg_res_0001_import.phpt b/tests/gnupg_res_0001_import.phpt index 7eb5160..6c6e672 100644 --- a/tests/gnupg_res_0001_import.phpt +++ b/tests/gnupg_res_0001_import.phpt @@ -1,10 +1,12 @@ ---TEST--n +--TEST-- import a new key into the keyring +--SKIPIF-- + --FILE-- string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" } +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_zzz_deletekey.phpt b/tests/gnupg_res_deletekey.phpt similarity index 53% rename from tests/gnupg_res_zzz_deletekey.phpt rename to tests/gnupg_res_deletekey.phpt index 460a2d0..0718809 100644 --- a/tests/gnupg_res_zzz_deletekey.phpt +++ b/tests/gnupg_res_deletekey.phpt @@ -1,8 +1,12 @@ --TEST--n delete a key from the keyring +--SKIPIF-- + --FILE-- --EXPECT-- bool(true) +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_encrypt.phpt b/tests/gnupg_res_encrypt.phpt index f8fc809..fe5b155 100644 --- a/tests/gnupg_res_encrypt.phpt +++ b/tests/gnupg_res_encrypt.phpt @@ -1,8 +1,12 @@ --TEST-- encrypt and decrypt a text +--SKIPIF-- + --FILE-- --EXPECTF-- string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_encryptsign.phpt b/tests/gnupg_res_encryptsign.phpt index 553c4d1..b6df88e 100644 --- a/tests/gnupg_res_encryptsign.phpt +++ b/tests/gnupg_res_encryptsign.phpt @@ -1,8 +1,12 @@ --TEST-- encryptsign and decryptverify a text +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_export.phpt b/tests/gnupg_res_export.phpt index ddfe58e..1fb879a 100644 --- a/tests/gnupg_res_export.phpt +++ b/tests/gnupg_res_export.phpt @@ -1,8 +1,12 @@ --TEST-- export a key +--SKIPIF-- + --FILE-- --EXPECTF-- string(%d) "-----BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v1 mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3 afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z @@ -34,3 +37,8 @@ drhhPQJw1AY6GEpSbK0JtACeJuewK8C1wO1l5OYkGzFpb4VgquI= =twR+ -----END PGP PUBLIC KEY BLOCK----- " +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_keyinfo.phpt b/tests/gnupg_res_keyinfo.phpt index 7decec3..5644f5f 100644 --- a/tests/gnupg_res_keyinfo.phpt +++ b/tests/gnupg_res_keyinfo.phpt @@ -1,8 +1,12 @@ --TEST--n get keyinfo +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_listsignatures.phpt b/tests/gnupg_res_listsignatures.phpt index af11391..ee7b4ad 100644 --- a/tests/gnupg_res_listsignatures.phpt +++ b/tests/gnupg_res_listsignatures.phpt @@ -1,8 +1,12 @@ --TEST--n list signatures +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_clear.phpt b/tests/gnupg_res_sign_clear.phpt index 6314c36..19d02c8 100644 --- a/tests/gnupg_res_sign_clear.phpt +++ b/tests/gnupg_res_sign_clear.phpt @@ -1,16 +1,18 @@ --TEST--n sign a text with sigmode SIG_MODE_CLEAR +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_detach.phpt b/tests/gnupg_res_sign_detach.phpt index 6583ef7..8bf0a63 100644 --- a/tests/gnupg_res_sign_detach.phpt +++ b/tests/gnupg_res_sign_detach.phpt @@ -1,16 +1,18 @@ --TEST--n sign a text with mode SIG_MODE_DETACH +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_detach_nonarmor.phpt b/tests/gnupg_res_sign_detach_nonarmor.phpt index 0055a5a..19785e1 100644 --- a/tests/gnupg_res_sign_detach_nonarmor.phpt +++ b/tests/gnupg_res_sign_detach_nonarmor.phpt @@ -1,8 +1,12 @@ --TEST--n sign a text with mode SIG_MODE_DETACH and without armored output +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_normal.phpt b/tests/gnupg_res_sign_normal.phpt index 8333ff7..825cc0d 100644 --- a/tests/gnupg_res_sign_normal.phpt +++ b/tests/gnupg_res_sign_normal.phpt @@ -1,8 +1,12 @@ --TEST--n sign a text with mode SIG_MODE_NORMAL +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_normal_noarmor.phpt b/tests/gnupg_res_sign_normal_noarmor.phpt index 324eef8..8cee2a9 100644 --- a/tests/gnupg_res_sign_normal_noarmor.phpt +++ b/tests/gnupg_res_sign_normal_noarmor.phpt @@ -1,8 +1,12 @@ --TEST--n sign a text with mode SIG_MODE_NORMAL and without armored output +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupgt.inc b/tests/gnupgt.inc new file mode 100644 index 0000000..7b3363f --- /dev/null +++ b/tests/gnupgt.inc @@ -0,0 +1,21 @@ +import($testkey); + } + + static function delete_key() + { + @unlink(__DIR__ . "/pubring.gpg"); + @unlink(__DIR__ . "/secring.gpg"); + } +} \ No newline at end of file