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 aebd3d9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ before_install:
- sudo mknod -m 0666 /dev/random c 1 9
- echo HRNGDEVICE=/dev/urandom | sudo tee /etc/default/rng-tools
- sudo /etc/init.d/rng-tools restart
- gpg --version
- gpg2 --version
- gpgconf --list-options gpg-agent

script: travis_wait bundle exec rake TESTOPTS="-v"

Expand Down
10 changes: 5 additions & 5 deletions test/crypto_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@
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

Expand All @@ -155,10 +155,10 @@
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
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def ensure_keys(proto)
dir = Dir.mktmpdir
GPGME::Engine.home_dir = dir
DIRS.push(dir)
IO.popen(["gpgconf", "--change-options", "gpg-agent"]) {|io|
io.write("allow-loopback-pinentry:2:1\n")
}
remove_all_keys
import_keys
end
Expand Down

0 comments on commit aebd3d9

Please sign in to comment.