Save username and password to a Normariffic yaml file
This commit is contained in:
@@ -2,6 +2,7 @@ require 'zanzibar/version'
|
||||
require 'savon'
|
||||
require 'io/console'
|
||||
require 'fileutils'
|
||||
require 'yaml'
|
||||
|
||||
module Zanzibar
|
||||
##
|
||||
@@ -124,9 +125,11 @@ module Zanzibar
|
||||
end
|
||||
|
||||
## Get the password, save it to a file, and return the path to the file.
|
||||
def get_password_and_save(scrt_id, path, name)
|
||||
password = get_password(scrt_id)
|
||||
save_password_to_file(password, path, name)
|
||||
def get_username_and_password_and_save(scrt_id, path, name)
|
||||
secret_items = get_secret(scrt_id)[:secret][:items][:secret_item]
|
||||
password = get_secret_item_by_field_name(secret_items, 'Password')[:value]
|
||||
username = get_secret_item_by_field_name(secret_items, 'Username')[:value]
|
||||
save_username_and_password_to_file(password, username, path, name)
|
||||
return File.join(path, name)
|
||||
end
|
||||
|
||||
@@ -137,9 +140,10 @@ module Zanzibar
|
||||
end
|
||||
|
||||
## Write the password to a file. Intended for use with a Zanzifile
|
||||
def save_password_to_file(password, path, name)
|
||||
def save_username_and_password_to_file(password, username, path, name)
|
||||
user_pass = {'username' => username.to_s, 'password' => password.to_s}.to_yaml
|
||||
File.open(File.join(path, name), 'wb') do |file|
|
||||
file.print password
|
||||
file.print user_pass
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ module Zanzibar
|
||||
|
||||
def download_one_secret(scrt_id, label, path, args, name = nil)
|
||||
if label == 'Password'
|
||||
path = zanzibar(args).get_password_and_save(scrt_id, path, name)
|
||||
path = zanzibar(args).get_username_and_password_and_save(scrt_id, path, name)
|
||||
{ path: path, hash: Digest::MD5.file(path).hexdigest }
|
||||
else
|
||||
path = zanzibar(args).download_secret_file(scrt_id: scrt_id,
|
||||
|
||||
@@ -104,15 +104,15 @@ describe 'Zanzibar Test' do
|
||||
File.delete('attachment.txt')
|
||||
end
|
||||
|
||||
it 'should save a password to a file' do
|
||||
it 'should save credentials 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('zanziUserPassword')
|
||||
File.delete('zanziTestPassword')
|
||||
client.get_username_and_password_and_save(1234, '.', 'zanziTestCreds')
|
||||
expect(File.exist? 'zanziTestCreds')
|
||||
expect(File.read('zanziTestCreds')).to eq({'username' => 'ZanziUser', 'password' => 'zanziUserPassword'}.to_yaml)
|
||||
File.delete('zanziTestCreds')
|
||||
end
|
||||
|
||||
it 'should use environment variables for credentials' do
|
||||
|
||||
Reference in New Issue
Block a user