commit 5a18265274b7789442c64e8b2d051ef3a68659a8
parent f31d1e5c31f69722fc530b1354952a1909ee778e
Author: Clint Byrum <clint@ubuntu.com>
Date: Thu, 17 Nov 2011 00:42:54 -0800
More assertions, testing verify. Fixes for length.
Diffstat:
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -136,7 +136,7 @@ EOS
else
crypto = GPGME::Crypto.new
gpg_opts[:mode] = GPGME::SIG_MODE_DETACH
- crypto.sign(format_payload(payload), gpg_opts)
+ sig = crypto.sign(format_payload(payload), gpg_opts).read
end
rescue GPGME::Error => exc
raise Error, gpgme_exc_msg(exc.message)
@@ -144,7 +144,7 @@ EOS
# if the key (or gpg-agent) is not available GPGME does not complain
# but just returns a zero length string. Let's catch that
- if sig.respond_to?('length') && sig.length == 0
+ if sig.length == 0
raise Error, gpgme_exc_msg("GPG failed to generate signature: check that gpg-agent is running and your key is available.")
end
@@ -183,7 +183,7 @@ EOS
# if the key (or gpg-agent) is not available GPGME does not complain
# but just returns a zero length string. Let's catch that
- if cipher.respond_to?('length') && !cipher.length == 0
+ if cipher.length == 0
raise Error, gpgme_exc_msg("GPG failed to generate cipher text: check that gpg-agent is running and your key is available.")
end
diff --git a/test/test_crypto.rb b/test/test_crypto.rb
@@ -57,6 +57,9 @@ class TestCryptoManager < Test::Unit::TestCase
if CryptoManager.have_crypto? then
signed = CryptoManager.sign @from_email,@to_email,"ABCDEFG"
assert_instance_of RMail::Message, signed
+ assert_equal "ABCDEFG", signed.body[0]
+ assert signed.body[1].body.length > 0 , "signature length must be > 0"
+ assert (signed.body[1].body.include? "-----BEGIN PGP SIGNATURE-----") , "Expecting PGP armored data"
end
end
@@ -64,6 +67,7 @@ class TestCryptoManager < Test::Unit::TestCase
if CryptoManager.have_crypto? then
encrypted = CryptoManager.encrypt @from_email, [@to_email], "ABCDEFG"
assert_instance_of RMail::Message, encrypted
+ assert (encrypted.body[1].body.include? "-----BEGIN PGP MESSAGE-----") , "Expecting PGP armored data"
end
end
@@ -71,6 +75,7 @@ class TestCryptoManager < Test::Unit::TestCase
if CryptoManager.have_crypto? then
encrypted = CryptoManager.sign_and_encrypt @from_email, [@to_email], "ABCDEFG"
assert_instance_of RMail::Message, encrypted
+ assert (encrypted.body[1].body.include? "-----BEGIN PGP MESSAGE-----") , "Expecting PGP armored data"
end
end
@@ -87,6 +92,15 @@ class TestCryptoManager < Test::Unit::TestCase
assert_equal "ABCDEFG" , decrypted[2].body
end
end
+
+ def test_verify
+ if CryptoManager.have_crypto?
+ signed = CryptoManager.sign @from_email, @to_email, "ABCDEFG"
+ assert_instance_of RMail::Message, signed
+ assert_instance_of String, (signed.body[1].body)
+ CryptoManager.verify signed.body[0], signed.body[1], true
+ end
+ end
end