Skip to content

Commit

Permalink
test: Use loopback pinentry
Browse files Browse the repository at this point in the history
  • Loading branch information
ueno committed Nov 30, 2018
1 parent 2a9ba02 commit c6108ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions test/crypto_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,28 @@
it "requires a password to decrypt" do
crypto = GPGME::Crypto.new
encrypted_data = crypto.encrypt TEXT[:plain],
:symmetric => true, :password => "gpgme"
:symmetric => true, :password => "gpgme", :pinentry_mode => GPGME::PINENTRY_MODE_LOOPBACK

assert_raises GPGME::Error::BadPassphrase do
crypto.decrypt encrypted_data
crypto.decrypt encrypted_data, :pinentry_mode => GPGME::PINENTRY_MODE_LOOPBACK
end
end

it "can encrypt and decrypt with the same password" do
crypto = GPGME::Crypto.new :symmetric => true, :password => "gpgme"
crypto = GPGME::Crypto.new :symmetric => true, :password => "gpgme", :pinentry_mode => GPGME::PINENTRY_MODE_LOOPBACK
encrypted_data = crypto.encrypt TEXT[:plain]
plain = crypto.decrypt encrypted_data
plain = crypto.decrypt encrypted_data, :pinentry_mode => GPGME::PINENTRY_MODE_LOOPBACK

assert_equal "Hi there", plain.read
end

it "but breaks with different ones" do
crypto = GPGME::Crypto.new
encrypted_data = crypto.encrypt TEXT[:plain],
:symmetric => true, :password => "gpgme"
:symmetric => true, :password => "gpgme", :pinentry_mode => GPGME::PINENTRY_MODE_LOOPBACK

assert_raises GPGME::Error::DecryptFailed do
crypto.decrypt encrypted_data, :password => "wrong one"
crypto.decrypt encrypted_data, :password => "wrong one", :pinentry_mode => GPGME::PINENTRY_MODE_LOOPBACK
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions test/ctx_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
input = GPGME::Data.new(TEXT[:passwored])
output = GPGME::Data.new

GPGME::Ctx.new(:password => 'gpgme') do |ctx|
GPGME::Ctx.new(:password => 'gpgme', :pinentry_mode => GPGME::PINENTRY_MODE_LOOPBACK) do |ctx|
ctx.decrypt_verify input, output

output.seek 0
Expand Down Expand Up @@ -113,7 +113,8 @@ def checking_value(value,par2,par3,par4,fd)

options = {
:passphrase_callback => method(:checking_value),
:passphrase_callback_value => "superman"
:passphrase_callback_value => "superman",
:pinentry_mode => GPGME::PINENTRY_MODE_LOOPBACK
}

GPGME::Ctx.new(options) do |ctx|
Expand Down

0 comments on commit c6108ef

Please sign in to comment.