Rubocop cleanup

This commit is contained in:
Jason Davis-Cooke
2015-01-19 07:31:47 -05:00
parent b2e4aaa5e1
commit b0efb7e27f
8 changed files with 331 additions and 345 deletions

View File

@@ -7,8 +7,9 @@ group :test do
gem 'savon_spec' gem 'savon_spec'
gem 'rspec' gem 'rspec'
gem 'webmock' gem 'webmock'
gem "codeclimate-test-reporter" gem 'codeclimate-test-reporter'
gem 'zanzibar', path: '.' gem 'zanzibar', path: '.'
gem 'rubocop'
end end
# Specify your gem's dependencies in zanzibar.gemspec # Specify your gem's dependencies in zanzibar.gemspec

View File

@@ -1,8 +1,11 @@
require "bundler/gem_tasks" require 'bundler/gem_tasks'
require "bundler/setup" # load up our gem environment (incl. local zanzibar) require 'bundler/setup' # load up our gem environment (incl. local zanzibar)
require 'rspec/core/rake_task' require 'rspec/core/rake_task'
require 'zanzibar/version' require 'zanzibar/version'
require 'rubocop/rake_task'
task :default => [:test]
task default: [:test]
RSpec::Core::RakeTask.new(:test)
RSpec::Core::RakeTask.new(:test)
RuboCop::RakeTask.new

View File

@@ -1,70 +1,69 @@
#! ruby #! ruby
require 'zanzibar' require 'zanzibar'
require 'optparse' require 'optparse'
options = { options = {
:domain => 'local' domain: 'local'
} }
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: zamioculcas -d domain [-w wsdl] [-k] [-p] [secret_id]" opts.banner = 'Usage: zamioculcas -d domain [-w wsdl] [-k] [-p] [secret_id]'
opts.on("-d", "--domain DOMAIN", "Specify domain") do |v| opts.on('-d', '--domain DOMAIN', 'Specify domain') do |v|
options[:domain] = v options[:domain] = v
end end
opts.on("-w", "--wsdl WSDL", "Specify WSDL location") do |v| opts.on('-w', '--wsdl WSDL', 'Specify WSDL location') do |v|
options[:wsdl] = v options[:wsdl] = v
end end
opts.on("-s", "--server SERVER", "Secret server hostname or IP") do |v| opts.on('-s', '--server SERVER', 'Secret server hostname or IP') do |v|
options[:server] = v options[:server] = v
end end
opts.on("-k", "--no-check-certificate", "Don't run SSL certificate checks") do |v| opts.on('-k', '--no-check-certificate', "Don't run SSL certificate checks") do |_v|
options[:globals] = {:ssl_verify_mode => :none} options[:globals] = { ssl_verify_mode: :none }
end end
opts.on("-p", "--password PASSWORD", "Specify password") do |v| opts.on('-p', '--password PASSWORD', 'Specify password') do |v|
options[:pwd] = v options[:pwd] = v
end end
opts.on("-t", "--type TYPE", "Specify the type of secret") do |v| opts.on('-t', '--type TYPE', 'Specify the type of secret') do |v|
options[:type] = v options[:type] = v
end end
opts.on("-u", "--user USER", "Specify the username") do |v| opts.on('-u', '--user USER', 'Specify the username') do |v|
options[:username] = v options[:username] = v
end end
end.parse!
end.parse!
fail OptionParser::MissingArgument if options[:server].nil?
raise OptionParser::MissingArgument if options[:server].nil? options[:type] = 'password' if options[:type].nil?
options[:type] = "password" if options[:type].nil?
unless STDIN.tty? || options[:pwd]
unless STDIN.tty? || options[:pwd] options[:pwd] = $stdin.read.strip
options[:pwd] = $stdin.read.strip end
end
secret_id = Integer(ARGV.pop)
secret_id = Integer(ARGV.pop) unless secret_id
if(!secret_id) fail 'no secret!'
fail "no secret!" end
end
unless options[:wsdl] || options[:server].nil?
unless options[:wsdl] || options[:server].nil? options[:wsdl] = "https://#{options[:server]}/webservices/sswebservice.asmx?wsdl"
options[:wsdl] = "https://#{options[:server]}/webservices/sswebservice.asmx?wsdl" end
end
scrt = Zanzibar::Zanzibar.new(options)
scrt = Zanzibar::Zanzibar.new(options)
case options[:type]
case options[:type] when 'password'
when "password" $stdout.write "#{scrt.get_password(secret_id)}\n"
$stdout.write "#{scrt.get_password(secret_id)}\n" when 'privatekey'
when "privatekey" scrt.download_private_key(scrt_id: secret_id)
scrt.download_private_key(:scrt_id=>secret_id) when 'publickey'
when "publickey" scrt.download_public_key(scrt_id: secret_id)
scrt.download_public_key(:scrt_id=>secret_id) else
else $stderr.write "#{options[:type]} is not a known type."
$stderr.write "#{options[:type]} is not a known type." end
end

View File

@@ -1,19 +1,16 @@
require "zanzibar/version" require 'zanzibar/version'
require 'savon' require 'savon'
require 'io/console' require 'io/console'
require 'fileutils' require 'fileutils'
module Zanzibar module Zanzibar
## ##
# Class for interacting with Secret Server # Class for interacting with Secret Server
class Zanzibar class Zanzibar
## ##
# @param args{:domain, :wsdl, :pwd, :username, :globals{}} # @param args{:domain, :wsdl, :pwd, :username, :globals{}}
def initialize(args = {}) def initialize(args = {})
if args[:username] if args[:username]
@@username = args[:username] @@username = args[:username]
else else
@@ -26,7 +23,7 @@ module Zanzibar
@@wsdl = get_wsdl_location @@wsdl = get_wsdl_location
end end
if args[:pwd] if args[:pwd]
@@password = args[:pwd] @@password = args[:pwd]
else else
@@password = prompt_for_password @@password = prompt_for_password
end end
@@ -43,7 +40,7 @@ module Zanzibar
# @param globals{}, optional # @param globals{}, optional
def init_client(globals = {}) def init_client(globals = {})
globals = {} if globals == nil globals = {} if globals.nil?
@@client = Savon.client(globals) do @@client = Savon.client(globals) do
wsdl @@wsdl wsdl @@wsdl
end end
@@ -54,39 +51,36 @@ module Zanzibar
def prompt_for_password def prompt_for_password
puts "Please enter password for #{@@username}:" puts "Please enter password for #{@@username}:"
return STDIN.noecho(&:gets).chomp STDIN.noecho(&:gets).chomp
end end
## Gets the wsdl document location if none is provided in the constructor ## Gets the wsdl document location if none is provided in the constructor
# @return [String] the location of the WDSL document # @return [String] the location of the WDSL document
def prompt_for_wsdl_location def prompt_for_wsdl_location
puts "Enter the URL of the Secret Server WSDL:" puts 'Enter the URL of the Secret Server WSDL:'
return STDIN.gets.chomp STDIN.gets.chomp
end end
## Gets the domain of the Secret Server installation if none is provided in the constructor ## Gets the domain of the Secret Server installation if none is provided in the constructor
# @return [String] the domain of the secret server installation # @return [String] the domain of the secret server installation
def prompt_for_domain def prompt_for_domain
puts "Enter the domain of your Secret Server:" puts 'Enter the domain of your Secret Server:'
return STDIN.gets.chomp STDIN.gets.chomp
end end
## Get an authentication token for interacting with Secret Server. These are only good for about 10 minutes so just get a new one each time. ## Get an authentication token for interacting with Secret Server. These are only good for about 10 minutes so just get a new one each time.
# Will raise an error if there is an issue with the authentication. # Will raise an error if there is an issue with the authentication.
# @return the authentication token for the current user. # @return the authentication token for the current user.
def get_token def get_token
begin response = @@client.call(:authenticate, message: { username: @@username, password: @@password, organization: '', domain: @@domain })
response = @@client.call(:authenticate, message: { username: @@username, password: @@password, organization: "", domain: @@domain }) .hash[:envelope][:body][:authenticate_response][:authenticate_result]
.hash[:envelope][:body][:authenticate_response][:authenticate_result] fail "Error generating the authentication token for user #{@@username}: #{response[:errors][:string]}" if response[:errors]
raise "Error generating the authentication token for user #{@@username}: #{response[:errors][:string]}" if response[:errors] response[:token]
response[:token] rescue Savon::Error => err
rescue Savon::Error => err raise "There was an error generating the authentiaton token for user #{@@username}: #{err}"
raise "There was an error generating the authentiaton token for user #{@@username}: #{err}"
end
end end
## Get a secret returned as a hash ## Get a secret returned as a hash
@@ -95,13 +89,11 @@ module Zanzibar
# @return [Hash] the secret hash retrieved from the wsdl # @return [Hash] the secret hash retrieved from the wsdl
def get_secret(scrt_id, token = nil) def get_secret(scrt_id, token = nil)
begin secret = @@client.call(:get_secret, message: { token: token || get_token, secretId: scrt_id }).hash[:envelope][:body][:get_secret_response][:get_secret_result]
secret = @@client.call(:get_secret, message: { token: token || get_token, secretId: scrt_id}).hash[:envelope][:body][:get_secret_response][:get_secret_result] fail "There was an error getting secret #{scrt_id}: #{secret[:errors][:string]}" if secret[:errors]
raise "There was an error getting secret #{scrt_id}: #{secret[:errors][:string]}" if secret[:errors] return secret
return secret rescue Savon::Error => err
rescue Savon::Error => err raise "There was an error getting the secret with id #{scrt_id}: #{err}"
raise "There was an error getting the secret with id #{scrt_id}: #{err}"
end
end end
## Retrieve a simple password from a secret ## Retrieve a simple password from a secret
@@ -110,13 +102,11 @@ module Zanzibar
# @return [String] the password for the given secret # @return [String] the password for the given secret
def get_password(scrt_id) def get_password(scrt_id)
begin secret = get_secret(scrt_id)
secret = get_secret(scrt_id) secret_items = secret[:secret][:items][:secret_item]
secret_items = secret[:secret][:items][:secret_item] return get_secret_item_by_field_name(secret_items, 'Password')[:value]
return get_secret_item_by_field_name(secret_items,"Password")[:value] rescue Savon::Error => err
rescue Savon::Error => err raise "There was an error getting the password for secret #{scrt_id}: #{err}"
raise "There was an error getting the password for secret #{scrt_id}: #{err}"
end
end end
def write_secret_to_file(path, secret_response) def write_secret_to_file(path, secret_response)
@@ -151,23 +141,21 @@ module Zanzibar
# Raise on error # Raise on error
# @param [Hash] args, :scrt_id, :type (one of "Private Key", "Public Key", "Attachment"), :scrt_item_id - optional, :path - optional # @param [Hash] args, :scrt_id, :type (one of "Private Key", "Public Key", "Attachment"), :scrt_item_id - optional, :path - optional
def download_secret_file(args = {}) def download_secret_file(args = {})
token = get_token token = get_token
FileUtils.mkdir_p(args[:path]) if args[:path] FileUtils.mkdir_p(args[:path]) if args[:path]
path = args[:path] ? args[:path] : '.' ## The File.join below doesn't handle nils well, so let's take that possibility away. path = args[:path] ? args[:path] : '.' ## The File.join below doesn't handle nils well, so let's take that possibility away.
begin begin
response = @@client.call(:download_file_attachment_by_item_id, message: response = @@client.call(:download_file_attachment_by_item_id, message:
{ token: token, secretId: args[:scrt_id], secretItemId: args[:scrt_item_id] || get_scrt_item_id(args[:scrt_id], args[:type], token)}) { token: token, secretId: args[:scrt_id], secretItemId: args[:scrt_item_id] || get_scrt_item_id(args[:scrt_id], args[:type], token) })
.hash[:envelope][:body][:download_file_attachment_by_item_id_response][:download_file_attachment_by_item_id_result] .hash[:envelope][:body][:download_file_attachment_by_item_id_response][:download_file_attachment_by_item_id_result]
raise "There was an error getting the #{args[:type]} for secret #{args[:scrt_id]}: #{response[:errors][:string]}" if response[:errors] fail "There was an error getting the #{args[:type]} for secret #{args[:scrt_id]}: #{response[:errors][:string]}" if response[:errors]
write_secret_to_file(path, response) write_secret_to_file(path, response)
rescue Savon::Error => err rescue Savon::Error => err
raise "There was an error getting the #{args[:type]} for secret #{args[:scrt_id]}: #{err}" raise "There was an error getting the #{args[:type]} for secret #{args[:scrt_id]}: #{err}"
end end
end end
## Methods to maintain backwards compatibility ## Methods to maintain backwards compatibility
def download_private_key(args = {}) def download_private_key(args = {})
args[:type] = 'Private Key' args[:type] = 'Private Key'
@@ -183,6 +171,5 @@ module Zanzibar
args[:type] = 'Attachment' args[:type] = 'Attachment'
download_secret_file(args) download_secret_file(args)
end end
end end
end end

View File

@@ -1,3 +1,3 @@
module Zanzibar module Zanzibar
VERSION = "0.1.10" VERSION = '0.1.10'
end end

View File

@@ -1,97 +1,95 @@
# This file was generated by the `rspec --init` command. Conventionally, all # This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this # The generated `.rspec` file contains `--require spec_helper` which will cause this
# file to always be loaded, without a need to explicitly require it in any files. # file to always be loaded, without a need to explicitly require it in any files.
# #
# Given that it is always loaded, you are encouraged to keep this file as # Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file # light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an # will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making # individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs # a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need it. # the additional setup, and require it from the spec files that actually need it.
# #
# The `.rspec` file also contains a few flags that are not defaults but that # The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want. # users commonly want.
# #
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require 'webmock/rspec' require 'webmock/rspec'
require "codeclimate-test-reporter" require 'codeclimate-test-reporter'
CodeClimate::TestReporter.start CodeClimate::TestReporter.start
RSpec.configure do |config| RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate # rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest # assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer. # assertions if you prefer.
config.expect_with :rspec do |expectations| config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description` # This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods # and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.: # defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description # be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4" # # => "be bigger than 2 and smaller than 4"
# ...rather than: # ...rather than:
# # => "be bigger than 2" # # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end end
# rspec-mocks config goes here. You can use an alternate test double # rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here. # library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks| config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on # Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to # a real object. This is generally recommended, and will default to
# `true` in RSpec 4. # `true` in RSpec 4.
mocks.verify_partial_doubles = true mocks.verify_partial_doubles = true
end end
config.after(:suite) do config.after(:suite) do
WebMock.disable_net_connect!(:allow => 'codeclimate.com') WebMock.disable_net_connect!(allow: 'codeclimate.com')
end end
# The settings below are suggested to provide a good initial experience # The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content. # with RSpec, but feel free to customize to your heart's content.
=begin # # These two settings work together to allow you to limit a spec run
# These two settings work together to allow you to limit a spec run # # to individual examples or groups you care about by tagging them with
# to individual examples or groups you care about by tagging them with # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
# `:focus` metadata. When nothing is tagged with `:focus`, all examples # # get run.
# get run. # config.filter_run :focus
config.filter_run :focus # config.run_all_when_everything_filtered = true
config.run_all_when_everything_filtered = true #
# # Limits the available syntax to the non-monkey patched syntax that is recommended.
# Limits the available syntax to the non-monkey patched syntax that is recommended. # # For more details, see:
# For more details, see: # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching # config.disable_monkey_patching!
config.disable_monkey_patching! #
# # This setting enables warnings. It's recommended, but in some cases may
# This setting enables warnings. It's recommended, but in some cases may # # be too noisy due to issues in dependencies.
# be too noisy due to issues in dependencies. # config.warnings = true
config.warnings = true #
# # Many RSpec users commonly either run the entire suite or an individual
# Many RSpec users commonly either run the entire suite or an individual # # file, and it's useful to allow more verbose output when running an
# file, and it's useful to allow more verbose output when running an # # individual spec file.
# individual spec file. # if config.files_to_run.one?
if config.files_to_run.one? # # Use the documentation formatter for detailed output,
# Use the documentation formatter for detailed output, # # unless a formatter has already been configured
# unless a formatter has already been configured # # (e.g. via a command-line flag).
# (e.g. via a command-line flag). # config.default_formatter = 'doc'
config.default_formatter = 'doc' # end
end #
# # Print the 10 slowest examples and example groups at the
# Print the 10 slowest examples and example groups at the # # end of the spec run, to help surface which specs are running
# end of the spec run, to help surface which specs are running # # particularly slow.
# particularly slow. # config.profile_examples = 10
config.profile_examples = 10 #
# # Run specs in random order to surface order dependencies. If you find an
# Run specs in random order to surface order dependencies. If you find an # # order dependency and want to debug it, you can fix the order by providing
# order dependency and want to debug it, you can fix the order by providing # # the seed, which is printed after each run.
# the seed, which is printed after each run. # # --seed 1234
# --seed 1234 # config.order = :random
config.order = :random #
# # Seed global randomization in this process using the `--seed` CLI option.
# Seed global randomization in this process using the `--seed` CLI option. # # Setting this allows you to use `--seed` to deterministically reproduce
# Setting this allows you to use `--seed` to deterministically reproduce # # test failures related to randomization by passing the same `--seed` value
# test failures related to randomization by passing the same `--seed` value # # as the one that triggered the failure.
# as the one that triggered the failure. # Kernel.srand config.seed
Kernel.srand config.seed end
=end
end

View File

@@ -1,116 +1,113 @@
require 'zanzibar' require 'zanzibar'
require 'savon' require 'savon'
require 'webmock' require 'webmock'
require 'rspec' require 'rspec'
require 'webmock/rspec' require 'webmock/rspec'
include WebMock::API include WebMock::API
describe "Zanzibar Test" do describe 'Zanzibar Test' do
client = Zanzibar::Zanzibar.new(domain: 'zanzitest.net', pwd: 'password', wsdl: 'spec/scrt.wsdl')
client = Zanzibar::Zanzibar.new(:domain => "zanzitest.net", :pwd=>'password', :wsdl => "spec/scrt.wsdl") auth_xml = File.read('spec/responses/authenticate_response.xml')
auth_xml = File.read('spec/responses/authenticate_response.xml') secret_xml = File.read('spec/responses/get_secret_response.xml')
secret_xml = File.read('spec/responses/get_secret_response.xml') secret_with_key_xml = File.read('spec/responses/get_secret_with_keys_response.xml')
secret_with_key_xml = File.read('spec/responses/get_secret_with_keys_response.xml') secret_with_attachment_xml = File.read('spec/responses/get_secret_with_attachment_response.xml')
secret_with_attachment_xml = File.read('spec/responses/get_secret_with_attachment_response.xml') private_key_xml = File.read('spec/responses/download_private_key_response.xml')
private_key_xml = File.read('spec/responses/download_private_key_response.xml') public_key_xml = File.read('spec/responses/download_public_key_response.xml')
public_key_xml = File.read('spec/responses/download_public_key_response.xml') attachment_xml = File.read('spec/responses/attachment_response.xml')
attachment_xml = File.read('spec/responses/attachment_response.xml')
it 'should return an auth token' do
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
it 'should return an auth token' do .to_return(body: auth_xml, status: 200)
stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
to_return(:body => auth_xml, :status => 200) expect(client.get_token).to eq('imatoken')
end
expect(client.get_token).to eq("imatoken")
end it 'should get a secret' do
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
it 'should get a secret' do .to_return(body: auth_xml, status: 200).then
stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx"). .to_return(body: secret_xml, status: 200)
to_return(:body => auth_xml, :status => 200).then.
to_return(:body => secret_xml, :status => 200) expect(client.get_secret(1234)[:secret][:name]).to eq('Zanzi Test Secret')
end
expect(client.get_secret(1234)[:secret][:name]).to eq("Zanzi Test Secret")
end it 'should get a password' do
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
it 'should get a password' do .to_return(body: auth_xml, status: 200).then
stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx"). .to_return(body: secret_xml, status: 200)
to_return(:body => auth_xml, :status => 200).then.
to_return(:body => secret_xml, :status => 200) expect(client.get_password(1234)).to eq('zanziUserPassword')
end
expect(client.get_password(1234)).to eq("zanziUserPassword")
end it 'should download a private key' do
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
it 'should download a private key' do .to_return(body: auth_xml, status: 200).then
stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx"). .to_return(body: secret_with_key_xml, status: 200).then
to_return(:body => auth_xml, :status => 200).then. .to_return(body: private_key_xml, status: 200)
to_return(:body => secret_with_key_xml, :status => 200).then.
to_return(:body => private_key_xml, :status => 200) client.download_secret_file(scrt_id: 2345, type: 'Private Key')
expect(File.exist? 'zanzi_key')
client.download_secret_file(:scrt_id => 2345, :type => 'Private Key') expect(File.read('zanzi_key')).to eq("-----BEGIN RSA PRIVATE KEY -----\nzanzibarTestPassword\n-----END RSA PRIVATE KEY-----\n")
expect(File.exist? 'zanzi_key') File.delete('zanzi_key')
expect(File.read('zanzi_key')).to eq("-----BEGIN RSA PRIVATE KEY -----\nzanzibarTestPassword\n-----END RSA PRIVATE KEY-----\n") end
File.delete('zanzi_key')
end it 'should download a private key legacy' do
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
it 'should download a private key legacy' do .to_return(body: auth_xml, status: 200).then
stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx"). .to_return(body: secret_with_key_xml, status: 200).then
to_return(:body => auth_xml, :status => 200).then. .to_return(body: private_key_xml, status: 200)
to_return(:body => secret_with_key_xml, :status => 200).then.
to_return(:body => private_key_xml, :status => 200) client.download_private_key(scrt_id: 2345)
expect(File.exist? 'zanzi_key')
client.download_private_key(:scrt_id => 2345) expect(File.read('zanzi_key')).to eq("-----BEGIN RSA PRIVATE KEY -----\nzanzibarTestPassword\n-----END RSA PRIVATE KEY-----\n")
expect(File.exist? 'zanzi_key') File.delete('zanzi_key')
expect(File.read('zanzi_key')).to eq("-----BEGIN RSA PRIVATE KEY -----\nzanzibarTestPassword\n-----END RSA PRIVATE KEY-----\n") end
File.delete('zanzi_key')
end it 'should download a public key' do
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
.to_return(body: auth_xml, status: 200).then
it 'should download a public key' do .to_return(body: secret_with_key_xml, status: 200).then
stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx"). .to_return(body: public_key_xml, status: 200)
to_return(:body => auth_xml, :status => 200).then.
to_return(:body => secret_with_key_xml, :status => 200).then. client.download_secret_file(scrt_id: 2345, type: 'Public Key')
to_return(:body => public_key_xml, :status => 200) expect(File.exist? 'zanzi_key.pub')
expect(File.read('zanzi_key.pub')).to eq("1234PublicKey5678==\n")
client.download_secret_file(:scrt_id => 2345, :type => 'Public Key') File.delete('zanzi_key.pub')
expect(File.exist? 'zanzi_key.pub') end
expect(File.read('zanzi_key.pub')).to eq("1234PublicKey5678==\n")
File.delete('zanzi_key.pub') it 'should download a public key legacy' do
end stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
.to_return(body: auth_xml, status: 200).then
it 'should download a public key legacy' do .to_return(body: secret_with_key_xml, status: 200).then
stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx"). .to_return(body: public_key_xml, status: 200)
to_return(:body => auth_xml, :status => 200).then.
to_return(:body => secret_with_key_xml, :status => 200).then. client.download_public_key(scrt_id: 2345)
to_return(:body => public_key_xml, :status => 200) expect(File.exist? 'zanzi_key.pub')
expect(File.read('zanzi_key.pub')).to eq("1234PublicKey5678==\n")
client.download_public_key(:scrt_id => 2345) File.delete('zanzi_key.pub')
expect(File.exist? 'zanzi_key.pub') end
expect(File.read('zanzi_key.pub')).to eq("1234PublicKey5678==\n")
File.delete('zanzi_key.pub') it 'should download an attachment' do
end stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
.to_return(body: auth_xml, status: 200).then
it 'should download an attachment' do .to_return(body: secret_with_attachment_xml, status: 200).then
stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx"). .to_return(body: attachment_xml, status: 200)
to_return(:body => auth_xml, :status => 200).then.
to_return(:body => secret_with_attachment_xml, :status => 200).then. client.download_secret_file(scrt_id: 3456, type: 'Attachment')
to_return(:body => attachment_xml, :status => 200) expect(File.exist? 'attachment.txt')
expect(File.read('attachment.txt')).to eq("I am a secret attachment\n")
client.download_secret_file(:scrt_id => 3456, :type => 'Attachment') File.delete('attachment.txt')
expect(File.exist? 'attachment.txt') end
expect(File.read('attachment.txt')).to eq("I am a secret attachment\n")
File.delete('attachment.txt') it 'should download an attachment legacy' do
end stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
.to_return(body: auth_xml, status: 200).then
it 'should download an attachment legacy' do .to_return(body: secret_with_attachment_xml, status: 200).then
stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx"). .to_return(body: attachment_xml, status: 200)
to_return(:body => auth_xml, :status => 200).then.
to_return(:body => secret_with_attachment_xml, :status => 200).then. client.download_attachment(scrt_id: 3456)
to_return(:body => attachment_xml, :status => 200) expect(File.exist? 'attachment.txt')
expect(File.read('attachment.txt')).to eq("I am a secret attachment\n")
client.download_attachment(:scrt_id => 3456) File.delete('attachment.txt')
expect(File.exist? 'attachment.txt') end
expect(File.read('attachment.txt')).to eq("I am a secret attachment\n") end
File.delete('attachment.txt')
end
end

View File

@@ -4,22 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'zanzibar/version' require 'zanzibar/version'
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = "zanzibar" spec.name = 'zanzibar'
spec.version = Zanzibar::VERSION spec.version = Zanzibar::VERSION
spec.authors = ["Jason Davis-Cooke"] spec.authors = ['Jason Davis-Cooke']
spec.email = ["jdaviscooke@cimpress.com"] spec.email = ['jdaviscooke@cimpress.com']
spec.summary = "Retrieve secrets from Secret Server" spec.summary = 'Retrieve secrets from Secret Server'
spec.description = "Programatically get secrets from Secret Server via the Web Service API" spec.description = 'Programatically get secrets from Secret Server via the Web Service API'
spec.homepage = "https://github.com/Cimpress-MCP/zanzibar" spec.homepage = 'https://github.com/Cimpress-MCP/zanzibar'
spec.license = "Apache 2.0" spec.license = 'Apache 2.0'
spec.files = `git ls-files -z`.split("\x0") spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"] spec.require_paths = ['lib']
spec.add_dependency "rubyntlm", "~> 0.4.0" spec.add_dependency 'rubyntlm', '~> 0.4.0'
spec.add_development_dependency "bundler", "~> 1.7" spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency 'rake', '~> 10.0'
spec.add_runtime_dependency "savon", "~> 2.8.0" spec.add_development_dependency 'rubocop', '~>0.18.1'
spec.add_runtime_dependency 'savon', '~> 2.8.0'
end end