From dc666cc84066fc7af511126bd831d5290accbdf3 Mon Sep 17 00:00:00 2001 From: Thilo Raufeisen Date: Thu, 18 May 2006 19:32:32 +0000 Subject: [PATCH] tests --- tests/0001_gnupg_import_oo.phpt | 33 +++++++++ tests/gnupg_encrypt_oo.phpt | 20 ++++++ tests/gnupg_encryptsign_oo.phpt | 38 +++++++++++ tests/gnupg_export_oo.phpt | 36 ++++++++++ tests/gnupg_keyinfo_oo.phpt | 97 +++++++++++++++++++++++++++ tests/gnupg_listsignatures_oo.phpt | 35 ++++++++++ tests/gnupg_sign_clear_oo.phpt | 38 +++++++++++ tests/gnupg_sign_detach_nonarmor.phpt | 38 +++++++++++ tests/gnupg_sign_detach_oo.phpt | 37 ++++++++++ tests/gnupg_sign_normal.phpt | 38 +++++++++++ tests/gnupg_sign_normal_nonarmor.phpt | 39 +++++++++++ tests/vars.inc | 38 +++++++++++ 12 files changed, 487 insertions(+) create mode 100644 tests/0001_gnupg_import_oo.phpt create mode 100644 tests/gnupg_encrypt_oo.phpt create mode 100644 tests/gnupg_encryptsign_oo.phpt create mode 100644 tests/gnupg_export_oo.phpt create mode 100644 tests/gnupg_keyinfo_oo.phpt create mode 100644 tests/gnupg_listsignatures_oo.phpt create mode 100644 tests/gnupg_sign_clear_oo.phpt create mode 100644 tests/gnupg_sign_detach_nonarmor.phpt create mode 100644 tests/gnupg_sign_detach_oo.phpt create mode 100644 tests/gnupg_sign_normal.phpt create mode 100644 tests/gnupg_sign_normal_nonarmor.phpt create mode 100644 tests/vars.inc diff --git a/tests/0001_gnupg_import_oo.phpt b/tests/0001_gnupg_import_oo.phpt new file mode 100644 index 0000000..01946d5 --- /dev/null +++ b/tests/0001_gnupg_import_oo.phpt @@ -0,0 +1,33 @@ +--TEST--n +import a new key into the keyring +--FILE-- + seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg -> import($testkey); +var_dump($ret); +?> +--EXPECT-- +array(9) { + ["imported"]=> + int(1) + ["unchanged"]=> + int(0) + ["newuserids"]=> + int(0) + ["newsubkeys"]=> + int(0) + ["secretimported"]=> + int(1) + ["secretunchanged"]=> + int(0) + ["newsignatures"]=> + int(0) + ["skippedkeys"]=> + int(0) + ["fingerprint"]=> + string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" +} diff --git a/tests/gnupg_encrypt_oo.phpt b/tests/gnupg_encrypt_oo.phpt new file mode 100644 index 0000000..8962ed1 --- /dev/null +++ b/tests/gnupg_encrypt_oo.phpt @@ -0,0 +1,20 @@ +--TEST-- +encrypt and decrypt a text +--FILE-- + seterrormode(gnupg::ERROR_WARNING); +$gpg -> addencryptkey($fingerprint); +$enc = $gpg -> encrypt($plaintext); + +$gpg = NULL; + +$gpg = new gnupg(); +$gpg -> adddecryptkey($fingerprint, $passphrase); +$ret = $gpg -> decrypt ($enc); + +var_dump($ret); +?> +--EXPECTF-- +string(7) "foo bar" diff --git a/tests/gnupg_encryptsign_oo.phpt b/tests/gnupg_encryptsign_oo.phpt new file mode 100644 index 0000000..fa3be4f --- /dev/null +++ b/tests/gnupg_encryptsign_oo.phpt @@ -0,0 +1,38 @@ +--TEST-- +encryptsign and decryptverify a text +--FILE-- + 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); + +var_dump($ret); +var_dump($plaintext); +?> +--EXPECTF-- +array(1) { + [0]=> + array(5) { + ["fingerprint"]=> + string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" + ["validity"]=> + int(0) + ["timestamp"]=> + int(%d) + ["status"]=> + int(0) + ["summary"]=> + int(0) + } +} +string(7) "foo bar" diff --git a/tests/gnupg_export_oo.phpt b/tests/gnupg_export_oo.phpt new file mode 100644 index 0000000..28654bc --- /dev/null +++ b/tests/gnupg_export_oo.phpt @@ -0,0 +1,36 @@ +--TEST-- +export a key +--FILE-- + seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg -> export($fingerprint); +var_dump($ret); +?> +--EXPECTF-- +string(1336) "-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.3 (GNU/Linux) + +mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3 +afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z +/samjTHLR+VKZ031B5/8p5Y49yvkkEyBkF1G85yeIXK0WZorKBPncRKuUwCgxOi/ +IEa+ZuqHlmlDF2LTRIBOfrkEAK+WLRMWUD0bqj1TYwnxwPWiuns32/ZXLWuPfb5o +crNt7x5LSe7wJhjyIiFhiU0qR33X/FrT2umzOxlRYfINXT9DUHDocxxbED6fxAHw +X2IDd5tWXgCkSBHn2yAneNY6ycPdS3RvqJGlYFg7cOc0kz4urjqRt9fIagzpZQtL +fXHfBACl3EWgvLhVBo5ExZbrtlOA2q0x9UGhhNaSkeBWBr2qDeZErQjMTO0+viaN +/SX0zxeWtM3z06rkUHd1DKORDRM5R7shBTv9/Quojn0gbYbOem+e1mlCe27TRxcP +yeIKk00PqbVuff9QlK9GqKEWGzsEXCmxZ160Dul3CGlf/vQZHbQkdGVzdGtleSAo +dGVzdGtleSkgPHRlc3RAZXhhbXBsZS5uZXQ+iF4EExECAB4FAkNQAKwCGwMGCwkI +BwMCAxUCAwMWAgECHgECF4AACgkQLpbxQbPdKy58pwCcDz9qEBEVt1gcKCwNay0f +m4vLqCkAn1P0KV1giECUVXBuZ5YUndDB1QqtuQENBENQAK0QBACNXzJQG4NHUJqL +PImezbl+ii+93MjMo8LpSlv9Np5ruWIKtxuqmVEe4k+r1DDmSl8hppifpRtx2hef +bDTl8Tdf5MNGvf5JE3AHYUehZ+ldjgYCOZ53fJDgKV65ZidQSGGXsRcyE7SHgMQ6 +rTL92PA2IQmkcf9xkg6xM2h55UusMwADBQP9EGQ0BAdWRUtA21/cR6F+t97KZnVS +et225UYv8azv8p8cK4R1lrZXChFadK9Kt+/My4HAx7J7zd1IPuKQ0QniuvuLT3Mw +z19B7FGXaJenwTw0P1ihtmSPq9GAOkOA4ZPhHLl9OFwIeAZzjfshRfvm0haO3vwl +xdjhwxyJ/a/JEF2ISQQYEQIACQUCQ1AArQIbDAAKCRAulvFBs90rLrBkAJ9tScp6 +drhhPQJw1AY6GEpSbK0JtACeJuewK8C1wO1l5OYkGzFpb4VgquI= +=twR+ +-----END PGP PUBLIC KEY BLOCK----- +" diff --git a/tests/gnupg_keyinfo_oo.phpt b/tests/gnupg_keyinfo_oo.phpt new file mode 100644 index 0000000..84f347e --- /dev/null +++ b/tests/gnupg_keyinfo_oo.phpt @@ -0,0 +1,97 @@ +--TEST--n +get keyinfo +--FILE-- + seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg -> keyinfo($fingerprint); +var_dump($ret); +?> +--EXPECT-- +array(1) { + [0]=> + array(8) { + ["disabled"]=> + bool(false) + ["expired"]=> + bool(false) + ["revoked"]=> + bool(false) + ["is_secret"]=> + bool(false) + ["can_sign"]=> + bool(true) + ["can_encrypt"]=> + bool(true) + ["uids"]=> + array(1) { + [0]=> + array(6) { + ["name"]=> + string(7) "testkey" + ["comment"]=> + string(7) "testkey" + ["email"]=> + string(16) "test@example.net" + ["uid"]=> + string(36) "testkey (testkey) " + ["revoked"]=> + bool(false) + ["invalid"]=> + bool(false) + } + } + ["subkeys"]=> + array(2) { + [0]=> + array(11) { + ["fingerprint"]=> + string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" + ["keyid"]=> + string(16) "2E96F141B3DD2B2E" + ["timestamp"]=> + int(1129316524) + ["expires"]=> + int(0) + ["is_secret"]=> + bool(false) + ["invalid"]=> + bool(false) + ["can_encrypt"]=> + bool(false) + ["can_sign"]=> + bool(true) + ["disabled"]=> + bool(false) + ["expired"]=> + bool(false) + ["revoked"]=> + bool(false) + } + [1]=> + array(10) { + ["keyid"]=> + string(16) "BFE8D07DDACDEAC8" + ["timestamp"]=> + int(1129316525) + ["expires"]=> + int(0) + ["is_secret"]=> + bool(false) + ["invalid"]=> + bool(false) + ["can_encrypt"]=> + bool(true) + ["can_sign"]=> + bool(false) + ["disabled"]=> + bool(false) + ["expired"]=> + bool(false) + ["revoked"]=> + bool(false) + } + } + } +} diff --git a/tests/gnupg_listsignatures_oo.phpt b/tests/gnupg_listsignatures_oo.phpt new file mode 100644 index 0000000..23f1cae --- /dev/null +++ b/tests/gnupg_listsignatures_oo.phpt @@ -0,0 +1,35 @@ +--TEST--n +list signatures +--FILE-- + seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg -> listsignatures($fingerprint); +var_dump($ret); +?> +--EXPECT-- +array(1) { + ["testkey (testkey) "]=> + array(1) { + ["2E96F141B3DD2B2E"]=> + array(8) { + ["uid"]=> + string(36) "testkey (testkey) " + ["name"]=> + string(7) "testkey" + ["email"]=> + string(16) "test@example.net" + ["comment"]=> + string(7) "testkey" + ["expires"]=> + int(0) + ["revoked"]=> + bool(false) + ["expired"]=> + bool(false) + ["invalid"]=> + bool(false) + } + } +} diff --git a/tests/gnupg_sign_clear_oo.phpt b/tests/gnupg_sign_clear_oo.phpt new file mode 100644 index 0000000..653e722 --- /dev/null +++ b/tests/gnupg_sign_clear_oo.phpt @@ -0,0 +1,38 @@ +--TEST--n +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 = NULL; + +$gpg = new gnupg(); +$tmp = false; +$ret = $gpg -> verify($ret, false, $tmp); + +var_dump($ret); +var_dump($tmp); +?> +--EXPECTF-- +array(1) { + [0]=> + array(5) { + ["fingerprint"]=> + string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" + ["validity"]=> + int(0) + ["timestamp"]=> + int(%d) + ["status"]=> + int(0) + ["summary"]=> + int(0) + } +} +string(8) "foo bar +" diff --git a/tests/gnupg_sign_detach_nonarmor.phpt b/tests/gnupg_sign_detach_nonarmor.phpt new file mode 100644 index 0000000..a9534d5 --- /dev/null +++ b/tests/gnupg_sign_detach_nonarmor.phpt @@ -0,0 +1,38 @@ +--TEST--n +sign a text with mode SIG_MODE_DETACH and without armored output +--FILE-- + 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); + +var_dump($ret); +var_dump($plaintext); +?> +--EXPECTF-- +array(1) { + [0]=> + array(5) { + ["fingerprint"]=> + string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" + ["validity"]=> + int(0) + ["timestamp"]=> + int(%d) + ["status"]=> + int(0) + ["summary"]=> + int(0) + } +} +string(7) "foo bar" diff --git a/tests/gnupg_sign_detach_oo.phpt b/tests/gnupg_sign_detach_oo.phpt new file mode 100644 index 0000000..0de3e84 --- /dev/null +++ b/tests/gnupg_sign_detach_oo.phpt @@ -0,0 +1,37 @@ +--TEST--n +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 = NULL; + +$gpg = new gnupg(); +$tmp = false; +$ret = $gpg -> verify($plaintext, $ret); + +var_dump($ret); +var_dump($plaintext); +?> +--EXPECTF-- +array(1) { + [0]=> + array(5) { + ["fingerprint"]=> + string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" + ["validity"]=> + int(0) + ["timestamp"]=> + int(%d) + ["status"]=> + int(0) + ["summary"]=> + int(0) + } +} +string(7) "foo bar" diff --git a/tests/gnupg_sign_normal.phpt b/tests/gnupg_sign_normal.phpt new file mode 100644 index 0000000..b6d3a7e --- /dev/null +++ b/tests/gnupg_sign_normal.phpt @@ -0,0 +1,38 @@ +--TEST--n +sign a text with mode SIG_MODE_NORMAL +--FILE-- + 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); + +var_dump($ret); +var_dump($plaintext); +?> +--EXPECTF-- +array(1) { + [0]=> + array(5) { + ["fingerprint"]=> + string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" + ["validity"]=> + int(0) + ["timestamp"]=> + int(%d) + ["status"]=> + int(0) + ["summary"]=> + int(0) + } +} +string(7) "foo bar" diff --git a/tests/gnupg_sign_normal_nonarmor.phpt b/tests/gnupg_sign_normal_nonarmor.phpt new file mode 100644 index 0000000..9fda443 --- /dev/null +++ b/tests/gnupg_sign_normal_nonarmor.phpt @@ -0,0 +1,39 @@ +--TEST--n +sign a text with mode SIG_MODE_NORMAL and without armored output +--FILE-- + 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); +$plaintext = false; +$ret = $gpg -> verify($ret, false, $plaintext); + +var_dump($ret); +var_dump($plaintext); +?> +--EXPECTF-- +array(1) { + [0]=> + array(5) { + ["fingerprint"]=> + string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" + ["validity"]=> + int(0) + ["timestamp"]=> + int(%d) + ["status"]=> + int(0) + ["summary"]=> + int(0) + } +} +string(7) "foo bar" diff --git a/tests/vars.inc b/tests/vars.inc new file mode 100644 index 0000000..53551d0 --- /dev/null +++ b/tests/vars.inc @@ -0,0 +1,38 @@ +