From 3b60a9cf008322fabae32ca1e0c2d525a5a64585 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Wed, 16 Nov 2011 23:33:00 -0800 Subject: [PATCH 1/8] encryption works, decryption still broken --- test/test_crypto.rb | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 test/test_crypto.rb diff --git a/test/test_crypto.rb b/test/test_crypto.rb new file mode 100755 index 000000000..600d9ddb0 --- /dev/null +++ b/test/test_crypto.rb @@ -0,0 +1,73 @@ +#!/usr/bin/ruby + +# tests for sup's crypto libs +# +# Copyright Clint Byrum 2011. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +require 'tmpdir' +require 'test/unit' +require 'rmail/message' +require 'sup/util' +require 'sup/hook' +require 'sup/contact' +require 'sup/person' +require 'sup/account' +require 'sup/crypto' +require 'stringio' + +module Redwood + +# These are all singletons +CryptoManager.init +Dir.mktmpdir('sup-test') do|f| + HookManager.init f +end +am = {:default=> {:name => "bob", :email=>"bob@foo.nowhere"}} +AccountManager.init am +print CryptoManager.have_crypto? + +class TestCryptoManager < Test::Unit::TestCase + + def setup + end + + def teardown + end + + def test_sign + if CryptoManager.have_crypto? then + signed = CryptoManager.sign "bob@foo.nowhere","alice@bar.anywhere","ABCDEFG" + assert_instance_of RMail::Message, signed + end + end + + + def test_encrypt + if CryptoManager.have_crypto? then + from_email = Person.from_address("bob@foo.nowhere").email + to_email = Person.from_address("alice@bar.anywhere").email + + encrypted = CryptoManager.encrypt from_email, [to_email], "ABCDEFG" + assert_instance_of RMail::Message, encrypted + end + end + + +end + +end From 61b0e9b56188a294a0ac99f3cb90c3ef70f3dcf5 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Thu, 17 Nov 2011 00:14:56 -0800 Subject: [PATCH 2/8] all tests pass on gpgme 1.0.7 and 2.0.0 --- lib/sup/crypto.rb | 43 +++++++++++++++++++++++++++++++++++-------- test/test_crypto.rb | 34 +++++++++++++++++++++++++++------- 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb index 477466976..d2e6d76bd 100644 --- a/lib/sup/crypto.rb +++ b/lib/sup/crypto.rb @@ -64,10 +64,17 @@ def initialize @gpgme_present = begin begin - GPGME.check_version({:protocol => GPGME::PROTOCOL_OpenPGP}) + begin + GPGME.check_version({:protocol => GPGME::PROTOCOL_OpenPGP}) + rescue TypeError + GPGME.check_version(nil) + end true rescue GPGME::Error false + rescue ArgumentError + # gpgme 2.0.0 raises this due to the hash->string conversion + false end rescue NameError false @@ -81,7 +88,11 @@ def initialize # if gpg2 is available, it will start gpg-agent if required if (bin = `which gpg2`.chomp) =~ /\S/ - GPGME.set_engine_info GPGME::PROTOCOL_OpenPGP, bin, nil + if GPGME.respond_to?('set_engine_info') + GPGME.set_engine_info GPGME::PROTOCOL_OpenPGP, bin, nil + else + GPGME.gpgme_set_engine_info GPGME::PROTOCOL_OpenPGP, bin, nil + end else # check if the gpg-options hook uses the passphrase_callback # if it doesn't then check if gpg agent is present @@ -120,14 +131,20 @@ def sign from, to, payload {:operation => "sign", :options => gpg_opts}) || gpg_opts begin - sig = GPGME.detach_sign(format_payload(payload), gpg_opts) + if GPGME.respond_to?('detach_sign') + sig = GPGME.detach_sign(format_payload(payload), gpg_opts) + else + crypto = GPGME::Crypto.new + gpg_opts[:mode] = GPGME::SIG_MODE_DETACH + crypto.sign(format_payload(payload), gpg_opts) + end rescue GPGME::Error => exc raise Error, gpgme_exc_msg(exc.message) end # 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.length == 0 + if sig.respond_to?('length') && 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 @@ -153,14 +170,20 @@ def encrypt from, to, payload, sign=false recipients = to + [from] recipients = HookManager.run("gpg-expand-keys", { :recipients => recipients }) || recipients begin - cipher = GPGME.encrypt(recipients, format_payload(payload), gpg_opts) + if GPGME.respond_to?('encrypt') + cipher = GPGME.encrypt(recipients, format_payload(payload), gpg_opts) + else + crypto = GPGME::Crypto.new + gpg_opts[:recipients] = recipients + cipher = crypto.encrypt(format_payload(payload), gpg_opts).read + end rescue GPGME::Error => exc raise Error, gpgme_exc_msg(exc.message) end # 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.length == 0 + if cipher.respond_to?('length') && !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 @@ -262,7 +285,11 @@ def decrypt payload, armor=false # a RubyMail::Message object {:operation => "decrypt", :options => gpg_opts}) || gpg_opts ctx = GPGME::Ctx.new(gpg_opts) cipher_data = GPGME::Data.from_str(format_payload(payload)) - plain_data = GPGME::Data.empty + if GPGME::Data.respond_to?('empty') + plain_data = GPGME::Data.empty + else + plain_data = GPGME::Data.empty! + end begin ctx.decrypt_verify(cipher_data, plain_data) rescue GPGME::Error => exc @@ -330,7 +357,7 @@ def unknown_status lines=[] def gpgme_exc_msg msg err_msg = "Exception in GPGME call: #{msg}" - info err_msg + #info err_msg err_msg end diff --git a/test/test_crypto.rb b/test/test_crypto.rb index 600d9ddb0..fa64d6822 100755 --- a/test/test_crypto.rb +++ b/test/test_crypto.rb @@ -22,11 +22,13 @@ require 'tmpdir' require 'test/unit' require 'rmail/message' +require 'rmail/parser' require 'sup/util' require 'sup/hook' require 'sup/contact' require 'sup/person' require 'sup/account' +require 'sup/message-chunks' require 'sup/crypto' require 'stringio' @@ -37,13 +39,15 @@ module Redwood Dir.mktmpdir('sup-test') do|f| HookManager.init f end -am = {:default=> {:name => "bob", :email=>"bob@foo.nowhere"}} +am = {:default=> {:name => "", :email=>ENV['EMAIL']}} AccountManager.init am -print CryptoManager.have_crypto? class TestCryptoManager < Test::Unit::TestCase def setup + @from_email = ENV['EMAIL'] + # Change this or import my public key to make these tests work. + @to_email = 'clint@ubuntu.com' end def teardown @@ -51,22 +55,38 @@ def teardown def test_sign if CryptoManager.have_crypto? then - signed = CryptoManager.sign "bob@foo.nowhere","alice@bar.anywhere","ABCDEFG" + signed = CryptoManager.sign @from_email,@to_email,"ABCDEFG" assert_instance_of RMail::Message, signed end end - def test_encrypt if CryptoManager.have_crypto? then - from_email = Person.from_address("bob@foo.nowhere").email - to_email = Person.from_address("alice@bar.anywhere").email + encrypted = CryptoManager.encrypt @from_email, [@to_email], "ABCDEFG" + assert_instance_of RMail::Message, encrypted + end + end - encrypted = CryptoManager.encrypt from_email, [to_email], "ABCDEFG" + def test_sign_and_encrypt + if CryptoManager.have_crypto? then + encrypted = CryptoManager.sign_and_encrypt @from_email, [@to_email], "ABCDEFG" assert_instance_of RMail::Message, encrypted end end + def test_decrypt + if CryptoManager.have_crypto? then + encrypted = CryptoManager.encrypt @from_email, [@to_email], "ABCDEFG" + assert_instance_of RMail::Message, encrypted + assert_instance_of String, (encrypted.body[1].body) + decrypted = CryptoManager.decrypt encrypted.body[1], true + assert_instance_of Array, decrypted + assert_instance_of Chunk::CryptoNotice, decrypted[0] + assert_instance_of Chunk::CryptoNotice, decrypted[1] + assert_instance_of RMail::Message, decrypted[2] + assert_equal "ABCDEFG" , decrypted[2].body + end + end end From 3b43db227d6ba80bf073b9f0ef19d69bf927a164 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Thu, 17 Nov 2011 00:42:54 -0800 Subject: [PATCH 3/8] More assertions, testing verify. Fixes for length. --- lib/sup/crypto.rb | 6 +++--- test/test_crypto.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb index d2e6d76bd..b747b8985 100644 --- a/lib/sup/crypto.rb +++ b/lib/sup/crypto.rb @@ -136,7 +136,7 @@ def sign from, to, payload 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 @@ def sign from, to, payload # 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 @@ def encrypt from, to, payload, sign=false # 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 index fa64d6822..7af6e40ac 100755 --- a/test/test_crypto.rb +++ b/test/test_crypto.rb @@ -57,6 +57,9 @@ def test_sign 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 @@ def test_encrypt 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 @@ def test_sign_and_encrypt 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 @@ def test_decrypt 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 From cf80df4d9abb0689a7c2874368302adac7002754 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Mon, 12 Aug 2013 12:36:30 +0200 Subject: [PATCH 4/8] Update patch for develop: Use test-keys and adapt tests for test-suite Generated (and checked in) two test gpg keys (test/gnupg_test_home) which are used for testing the crypto suite with gpgme 2.0. The keys expire after 1 year today. They were generated using gpg --gen-key, to create new keys: 0. Set the GNUPGHOME environment variable to: /full/path/test/gnupg_test_home/ 1. Generate receiver keys for email: sup-test-2@foo.bar (no password) 2. Export key 3. Move keyrings to receiver_*.gpg 4. Generate sender keys for email: sup-test-1@foo.bar (no password) 5. Update test/gnupg_test_home/gpg.conf with deafult-key to represent the new sender key. --- .gitignore | 4 ++ bin/sup | 2 - lib/sup/crypto.rb | 2 - test/gnupg_test_home/gpg.conf | 1 + test/gnupg_test_home/pubring.gpg | Bin 0 -> 1945 bytes test/gnupg_test_home/receiver_pubring.gpg | Bin 0 -> 718 bytes test/gnupg_test_home/receiver_secring.gpg | Bin 0 -> 1382 bytes test/gnupg_test_home/receiver_trustdb.gpg | Bin 0 -> 1280 bytes test/gnupg_test_home/secring.gpg | Bin 0 -> 2529 bytes test/gnupg_test_home/sup-test-2@foo.bar.asc | 20 ++++++++ test/gnupg_test_home/trustdb.gpg | Bin 0 -> 1360 bytes test/test_crypto.rb | 51 +++++++++----------- 12 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 test/gnupg_test_home/gpg.conf create mode 100644 test/gnupg_test_home/pubring.gpg create mode 100644 test/gnupg_test_home/receiver_pubring.gpg create mode 100644 test/gnupg_test_home/receiver_secring.gpg create mode 100644 test/gnupg_test_home/receiver_trustdb.gpg create mode 100644 test/gnupg_test_home/secring.gpg create mode 100644 test/gnupg_test_home/sup-test-2@foo.bar.asc create mode 100644 test/gnupg_test_home/trustdb.gpg mode change 100755 => 100644 test/test_crypto.rb diff --git a/.gitignore b/.gitignore index d727f5329..8c0e90c73 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ sup-exception-log.txt # bundler stuff Gemfile.lock .bundle + +# generated file for gnupg test +test/gnupg_test_home/random_seed + diff --git a/bin/sup b/bin/sup index 73b570d5d..3342647fd 100755 --- a/bin/sup +++ b/bin/sup @@ -10,8 +10,6 @@ require 'ncursesw' no_gpgme = false begin - # gpgme broke its API in 2.0, so make sure we have the old version for now. - gem 'gpgme', '=1.0.8' require 'gpgme' rescue LoadError no_gpgme = true diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb index b747b8985..b7f46c819 100644 --- a/lib/sup/crypto.rb +++ b/lib/sup/crypto.rb @@ -1,6 +1,4 @@ begin - # gpgme broke its API in 2.0, so make sure we have the old version for now. - gem 'gpgme', '=1.0.8' require 'gpgme' rescue LoadError end diff --git a/test/gnupg_test_home/gpg.conf b/test/gnupg_test_home/gpg.conf new file mode 100644 index 000000000..b590914f2 --- /dev/null +++ b/test/gnupg_test_home/gpg.conf @@ -0,0 +1 @@ +default-key 789E7011 diff --git a/test/gnupg_test_home/pubring.gpg b/test/gnupg_test_home/pubring.gpg new file mode 100644 index 0000000000000000000000000000000000000000..3f604d70ef760cbb41d24d2756b35e881fad40b1 GIT binary patch literal 1945 zcma)+X*d)L8-{1b7-JCG4iTdc;aD@FY-LG9*1@3cX31`tEE#LEar#jTt^7H%oT-W>SdG7bl0&;-Op;S>I6tFhwu~i>PA_y>$i5&@0 zdgi>9QrGos=2yY5**>Bp%LFMyz|8^@?&boCC{vlk1FBsS#wJ?Qf8Ut@)ITs$(|1K( z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aAAQrQUyKFxzm?%ti9@)3{G{Z|z>TB`?wul`>lS zj}!(F>s?9Eyq-<$J3C}+=EM4_e&2F2m^7Z;oKXB89VgC9G|s8u+RK)e-9w9_1G^4z zO+{ze)x$2?z5IBxN!|BN+6!A$E@u5^cE@pp7&o3doGCcmQyn0rWyL%0zj~eFY8Wla zxph`xaE+O29!eVXHLMdapPF?q`NNciFZRj_**K&S$dGF7;K&3vDtgd~%cT`_ONfEA zC^Go9cMW$+&pf>!n797!vx^Ev8HxDKb3vWe5*E`mY{S=PcP=gJ%OCcYcbWICfB=xt1RQRTTXv#13USv2);?tDw8du8KB1wR<%T-q91y=~L? kC*C6sSy*uexoMpTrr7`&)*86!c)dr1gY1R@jVI0h3;q3I@c;k- literal 0 HcmV?d00001 diff --git a/test/gnupg_test_home/receiver_pubring.gpg b/test/gnupg_test_home/receiver_pubring.gpg new file mode 100644 index 0000000000000000000000000000000000000000..84cbdc3f8383da7dda519dec2289e1405aed6a3c GIT binary patch literal 718 zcmbQy%M!$~rG}A(;n9IY*1az-ig?J~5dInUv978obtlWw?-?8$E#kTNyy0Qp%5~L# z%7xl~iLUFR$BbkTzlxL!%o2N}z!}T7=6=o3V#D>bR!nQWF0{mK_eQTK;{)H5N+-)r zcldZd(Rowr;R}mDMHNW2WKKA3+aoruaCdfU(&`V9q5J<9E}#6VeNXFc20=y!#w~Wi zr3DHhsl_D!wdhsF);+?*Wj%uI}Iq8v<|T-+>TOw5c-a*Ryk4GdhI0y+$m zb%j|)6Ap{AFdU!A{J`IqX~m+I_xv~Cz4mP3$&N?Yc;|=vO)$|q`HRu_x0QZ{MgQcM zn_drgRR<<(ST5@Px8q&x^#c>0UNhOCW50Nk!D*A%NBTJy9($YiA=Y#M^q!q}PZh3H zjl2d*46zIE+1ZTk5 znH$a24$Mq=Q`&iT`nlra{_8JR_4vEdGm8c(JZ!2PE}3a+?&JCBnl+&PmPwo;~BEtOXb9?bUxRhsiznh zzW(q(*?fhWr-^p%6C2J@uJ%3W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!CIkCOA-|T#nEX?CNmd6|H5y1-2MfB8Dbs}f@@*J!^wWJu`Bl*0s!_)mmd{Q z8}&F2|2c+-IeT^#`o6ET*YGX1N0(t6BYooiSph8}La;LP_gvpk25dvcU`OSWlteJZ zEXYXxCbPQMe`=f7yQZA`X^4MYT%A0rpSC6#oX>{gg=0^nQvuyEmnWk^X+ z40OcdC>iLT_e#$v)+8CtxZL!unIed#1Q-DV01pKMQV6ts0vikk2?60VfB*^!5G(*0 zesOAYkk!=$0L{!rUpd5I-Ghy6Rzxn~M0g0X2|ZYu!_GTr4m6euoyYTbervXho9D%nVC+yRZTP03^k2cmMzZ literal 0 HcmV?d00001 diff --git a/test/gnupg_test_home/receiver_trustdb.gpg b/test/gnupg_test_home/receiver_trustdb.gpg new file mode 100644 index 0000000000000000000000000000000000000000..937117c75dddcd3a3fae000107b3f41f9a7b1bde GIT binary patch literal 1280 zcmZQfFGy!*W@Ke#Vqgg3*s>w`nJCeP>MMeRV9bof87J=p1H^Ro0H|}N^G47Lx^{s+MIF1^ zW)dvC(tQ)$ZDjiqJ!cfA)z86K)Kf`AtpQ{#FDElW#_VW*f$ybvleZA6Qy;;5h_mG5 zU8tbzfauHT8{@^+XPp2M0RRC22l@hCpXZ^U(wD4w#O~5$Q*69@4pSm|8oz?g$=>0sUslIvM5sT8=lOxYhe!@J zc0Os?X zAfDF3M=`dL!s$Y-fu>_pwDh8$qhhq2_S+ZNbroIviAR+sX|Xz|7tRBzmXQPhK+_=)|GtNuTGx;pAQtK+yV2W%hRAXOV0sDAB#KGU zeq5mFuB=-Ioc|s5W^~6e1wV-jP)cOwY~h?@VESNUs2@B7w#*Li1m6!4Hv{zNouzvCbN=E|YIkMT}u^i(~wxDNtKZ#1)ARLMh&78YssNr$vJQ+044 zRAqB?AX8;-WMy(7F(4>ZWpi{Ob7gL1WpW^EWqBzeJact$Ep%mbbS*JJW^ZpUVqtPV zi2*(Y69EDMDFp&j2(upo8v_Li0pT-%2MY-Z2Ll2D1{DYb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=(5DLUW-29&(6*JEwJZ z`M{g)ZUv{(SYZrpG=vN}Wh1Vnqrw8=Vd@pFXb`uMsIKFStWmHg3)SDk88(yV`o(94 zqRi7ak995OYK1vzn+}6yU13(y1gJVighF11_cvasPd_fW UaSGofFY_|q%3Egye_@&j0KYyed;kCd literal 0 HcmV?d00001 diff --git a/test/test_crypto.rb b/test/test_crypto.rb old mode 100755 new mode 100644 index 7af6e40ac..5cf32cabd --- a/test/test_crypto.rb +++ b/test/test_crypto.rb @@ -1,56 +1,52 @@ -#!/usr/bin/ruby - # tests for sup's crypto libs # # Copyright Clint Byrum 2011. All Rights Reserved. +# Copyright Sup Developers 2013. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. -require 'tmpdir' -require 'test/unit' -require 'rmail/message' -require 'rmail/parser' -require 'sup/util' -require 'sup/hook' -require 'sup/contact' -require 'sup/person' -require 'sup/account' -require 'sup/message-chunks' -require 'sup/crypto' +require 'test_helper' +require 'sup' require 'stringio' +require 'tmpdir' module Redwood -# These are all singletons -CryptoManager.init -Dir.mktmpdir('sup-test') do|f| - HookManager.init f -end -am = {:default=> {:name => "", :email=>ENV['EMAIL']}} -AccountManager.init am - -class TestCryptoManager < Test::Unit::TestCase +class TestCryptoManager < ::Minitest::Unit::TestCase def setup - @from_email = ENV['EMAIL'] - # Change this or import my public key to make these tests work. - @to_email = 'clint@ubuntu.com' + @from_email = 'sup-test-1@foo.bar' + @to_email = 'sup-test-2@foo.bar' + # Use test gnupg setup + @orig_gnupghome = ENV['GNUPGHOME'] + ENV['GNUPGHOME'] = File.join(File.dirname(__FILE__), 'gnupg_test_home') + + CryptoManager.init + @path = Dir.mktmpdir + HookManager.init @path + am = {:default=> {:name => "test", :email=> 'sup-test-1@foo.bar'}} + AccountManager.init am end def teardown + ENV['GNUPGHOME'] = @orig_gnupghome + + CryptoManager.deinstantiate! + HookManager.deinstantiate! + AccountManager.deinstantiate! end def test_sign @@ -101,7 +97,6 @@ def test_verify CryptoManager.verify signed.body[0], signed.body[1], true end end - end end From 880af0e389fe6877e9e58ded846ec52a5e3a1cb2 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Mon, 12 Aug 2013 13:07:51 +0200 Subject: [PATCH 5/8] Add gpgme dependency and install gnupg in travis test --- .travis.yml | 2 +- sup.gemspec | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb82f57e7..56ee8f5c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ rvm: before_install: - sudo apt-get update -qq - - sudo apt-get install -qq uuid-dev uuid libncursesw5-dev libncursesw5 + - sudo apt-get install -qq uuid-dev uuid libncursesw5-dev libncursesw5 gnupg script: bundle exec rake travis diff --git a/sup.gemspec b/sup.gemspec index 0d3f1b83c..207d2480c 100644 --- a/sup.gemspec +++ b/sup.gemspec @@ -53,6 +53,7 @@ SUP: Please run `sup-psych-ify-config-files` to migrate from 0.13 to 0.14 s.add_runtime_dependency "locale", "~> 2.0" s.add_runtime_dependency "chronic", "~> 0.9.1" s.add_runtime_dependency "unicode", "~> 0.4.4" + s.add_runtime_dependency "gpgme" s.add_development_dependency "bundler", "~> 1.3" s.add_development_dependency "rake" From 056c709191723e28c7086ae49979c79c0ef082d2 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Mon, 12 Aug 2013 13:34:02 +0200 Subject: [PATCH 6/8] Re-organize sup Managers initializations --- test/test_crypto.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/test_crypto.rb b/test/test_crypto.rb index 5cf32cabd..402a35153 100644 --- a/test/test_crypto.rb +++ b/test/test_crypto.rb @@ -34,19 +34,22 @@ def setup @orig_gnupghome = ENV['GNUPGHOME'] ENV['GNUPGHOME'] = File.join(File.dirname(__FILE__), 'gnupg_test_home') - CryptoManager.init @path = Dir.mktmpdir - HookManager.init @path + Redwood::HookManager.init File.join(@path, 'hooks') + am = {:default=> {:name => "test", :email=> 'sup-test-1@foo.bar'}} - AccountManager.init am + Redwood::AccountManager.init am + + Redwood::CryptoManager.init end def teardown - ENV['GNUPGHOME'] = @orig_gnupghome - CryptoManager.deinstantiate! - HookManager.deinstantiate! AccountManager.deinstantiate! + HookManager.deinstantiate! + FileUtils.rm_r @path + + ENV['GNUPGHOME'] = @orig_gnupghome end def test_sign From 60b27dce9ba09344142e0e0a55cb21043e07a870 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Mon, 12 Aug 2013 13:36:23 +0200 Subject: [PATCH 7/8] Gnupg seems to be standard, add gpgme as development dependency --- .travis.yml | 2 +- sup.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 56ee8f5c1..bb82f57e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ rvm: before_install: - sudo apt-get update -qq - - sudo apt-get install -qq uuid-dev uuid libncursesw5-dev libncursesw5 gnupg + - sudo apt-get install -qq uuid-dev uuid libncursesw5-dev libncursesw5 script: bundle exec rake travis diff --git a/sup.gemspec b/sup.gemspec index 207d2480c..f8bdc8739 100644 --- a/sup.gemspec +++ b/sup.gemspec @@ -53,11 +53,11 @@ SUP: Please run `sup-psych-ify-config-files` to migrate from 0.13 to 0.14 s.add_runtime_dependency "locale", "~> 2.0" s.add_runtime_dependency "chronic", "~> 0.9.1" s.add_runtime_dependency "unicode", "~> 0.4.4" - s.add_runtime_dependency "gpgme" s.add_development_dependency "bundler", "~> 1.3" s.add_development_dependency "rake" s.add_development_dependency "minitest", "~> 4.7" s.add_development_dependency "rr", "~> 1.0.5" + s.add_development_dependency "gpgme" end end From cd7f37b21edeea5a4efa04f3a2d8e2b846e837fe Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Mon, 12 Aug 2013 13:59:47 +0200 Subject: [PATCH 8/8] Print no-crypto notice in test, add travis dep to gnupg2 --- .travis.yml | 2 +- lib/sup/crypto.rb | 1 + sup.gemspec | 2 +- test/test_crypto.rb | 4 ++++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb82f57e7..a5d3138d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ rvm: before_install: - sudo apt-get update -qq - - sudo apt-get install -qq uuid-dev uuid libncursesw5-dev libncursesw5 + - sudo apt-get install -qq uuid-dev uuid libncursesw5-dev libncursesw5 gnupg2 script: bundle exec rake travis diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb index b7f46c819..8f042cd5a 100644 --- a/lib/sup/crypto.rb +++ b/lib/sup/crypto.rb @@ -119,6 +119,7 @@ def initialize end def have_crypto?; @not_working_reason.nil? end + def not_working_reason; @not_working_reason end def sign from, to, payload return unknown_status(@not_working_reason) unless @not_working_reason.nil? diff --git a/sup.gemspec b/sup.gemspec index f8bdc8739..aeb95f596 100644 --- a/sup.gemspec +++ b/sup.gemspec @@ -58,6 +58,6 @@ SUP: Please run `sup-psych-ify-config-files` to migrate from 0.13 to 0.14 s.add_development_dependency "rake" s.add_development_dependency "minitest", "~> 4.7" s.add_development_dependency "rr", "~> 1.0.5" - s.add_development_dependency "gpgme" + s.add_development_dependency "gpgme", ">= 2.0.2" end end diff --git a/test/test_crypto.rb b/test/test_crypto.rb index 402a35153..ae5b6eb8b 100644 --- a/test/test_crypto.rb +++ b/test/test_crypto.rb @@ -41,6 +41,10 @@ def setup Redwood::AccountManager.init am Redwood::CryptoManager.init + + if not CryptoManager.have_crypto? + warn "No crypto set up, crypto will not be tested. Reason: #{CryptoManager.not_working_reason}" + end end def teardown