Commit 6cd9888f authored by Alexis Reigel's avatar Alexis Reigel

store gpg return directory locally

parent 3a9f210b
...@@ -44,19 +44,23 @@ module Gitlab ...@@ -44,19 +44,23 @@ module Gitlab
def using_tmp_keychain def using_tmp_keychain
Dir.mktmpdir do |dir| Dir.mktmpdir do |dir|
@original_dirs ||= [GPGME::Engine.dirinfo('homedir')] previous_dir = current_home_dir
@original_dirs.push(dir)
GPGME::Engine.home_dir = dir GPGME::Engine.home_dir = dir
return_value = yield return_value = yield
@original_dirs.pop GPGME::Engine.home_dir = previous_dir
GPGME::Engine.home_dir = @original_dirs[-1]
return_value return_value
end end
end end
# 1. Returns the custom home directory if one has been set by calling
# `GPGME::Engine.home_dir=`
# 2. Returns the default home directory otherwise
def current_home_dir
GPGME::Engine.info.first.home_dir || GPGME::Engine.dirinfo('homedir')
end
end end
end end
...@@ -43,6 +43,28 @@ describe Gitlab::Gpg do ...@@ -43,6 +43,28 @@ describe Gitlab::Gpg do
).to eq [] ).to eq []
end end
end end
describe '.current_home_dir' do
let(:default_home_dir) { GPGME::Engine.dirinfo('homedir') }
it 'returns the default value when no explicit home dir has been set' do
expect(described_class.current_home_dir).to eq default_home_dir
end
it 'returns the explicitely set home dir' do
GPGME::Engine.home_dir = '/tmp/gpg'
expect(described_class.current_home_dir).to eq '/tmp/gpg'
GPGME::Engine.home_dir = GPGME::Engine.dirinfo('homedir')
end
it 'returns the default value when explicitely setting the home dir to nil' do
GPGME::Engine.home_dir = nil
expect(described_class.current_home_dir).to eq default_home_dir
end
end
end end
describe Gitlab::Gpg::CurrentKeyChain do describe Gitlab::Gpg::CurrentKeyChain do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment