From 179fa24ab9f231634139a3facc290eedb00a322d Mon Sep 17 00:00:00 2001 From: Jason Davis-Cooke Date: Thu, 26 Feb 2015 08:56:43 -0500 Subject: [PATCH] Save zanzifile passwords to disk --- lib/zanzibar.rb | 2 +- lib/zanzibar/actions/bundle.rb | 5 ++--- spec/lib/zanzibar_spec.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/zanzibar.rb b/lib/zanzibar.rb index 7a040a9..fa01f6f 100644 --- a/lib/zanzibar.rb +++ b/lib/zanzibar.rb @@ -139,7 +139,7 @@ module Zanzibar ## Write the password to a file. Intended for use with a Zanzifile def save_password_to_file(password, path, name) File.open(File.join(path, name), 'wb') do |file| - file.puts password + file.print Base64.strict_encode64(password) end end diff --git a/lib/zanzibar/actions/bundle.rb b/lib/zanzibar/actions/bundle.rb index 998c239..4ef1f81 100644 --- a/lib/zanzibar/actions/bundle.rb +++ b/lib/zanzibar/actions/bundle.rb @@ -44,7 +44,7 @@ module Zanzibar end def ensure_secrets_path - FileUtils.mkdir_p(@settings['secret_dir']) + FileUtils.mkdir_p(@settings['secret_dir']) unless @settings['secret_dir'] == nil end def resolved_file? @@ -85,14 +85,13 @@ module Zanzibar downloaded_secrets = {} remote_secrets.each do |key, secret| - puts "Downloading #{key} - #{secret['id']}" downloaded_secrets[key] = download_one_secret(secret['id'], secret['label'], @settings['secret_dir'], args, secret['name'] || "#{secret['id']}_password") - debug { "Downloaded secret: #{key} to #{secret['path']}..." } + debug { "Downloaded secret: #{key} to #{@settings['secret_dir']}..." } end downloaded_secrets diff --git a/spec/lib/zanzibar_spec.rb b/spec/lib/zanzibar_spec.rb index 27d9bd6..00a4a31 100644 --- a/spec/lib/zanzibar_spec.rb +++ b/spec/lib/zanzibar_spec.rb @@ -104,6 +104,17 @@ describe 'Zanzibar Test' do File.delete('attachment.txt') end + it 'should save a password to a file' do + stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx') + .to_return(body: AUTH_XML, status: 200).then + .to_return(body: SECRET_XML, status: 200) + + client.get_password_and_save(1234, '.', 'zanziTestPassword') + expect(File.exist? 'zanziTestPassword') + expect(File.read('zanziTestPassword')).to eq(Base64.strict_encode64('zanziUserPassword')) + File.delete('zanziTestPassword') + end + it 'should use environment variables for credentials' do ENV['ZANZIBAR_USER'] = 'environment_user' ENV['ZANZIBAR_PASSWORD'] = 'environment_password'