spec/beaker/hypervisor/aws_sdk_spec.rb in beaker-aws-0.3.0 vs spec/beaker/hypervisor/aws_sdk_spec.rb in beaker-aws-0.4.0
- old
+ new
@@ -8,10 +8,11 @@
allow_any_instance_of( Beaker::AwsSdk ).
to receive(:load_fog_credentials).
and_return({
:access_key => fog_file_contents[:default][:aws_access_key_id],
:secret_key => fog_file_contents[:default][:aws_secret_access_key],
+ :session_token => fog_file_contents[:default][:aws_session_token],
})
# This is needed because the EC2 api looks up a local endpoints.json file
FakeFS.deactivate!
@@ -58,23 +59,48 @@
it 'from .fog file' do
creds = aws.load_fog_credentials
expect( creds[:access_key] ).to eq("IMANACCESSKEY")
expect( creds[:secret_key] ).to eq("supersekritkey")
+ expect( creds[:session_token] ).to eq('somecrazylongsupersessiontoken!#%^^*(%$^&@$%#!!#$asd;fjapugfrejklvznb;jdgfjiadvij')
end
it 'from environment variables' do
ENV['AWS_ACCESS_KEY_ID'] = "IMANACCESSKEY"
ENV['AWS_SECRET_ACCESS_KEY'] = "supersekritkey"
creds = aws.load_env_credentials
expect( creds[:access_key] ).to eq("IMANACCESSKEY")
expect( creds[:secret_key] ).to eq("supersekritkey")
+ expect( creds[:session_token] ).to be_nil
end
+
+ it 'from environment variables with session_token' do
+ ENV['AWS_ACCESS_KEY_ID'] = "IMANACCESSKEY"
+ ENV['AWS_SECRET_ACCESS_KEY'] = "supersekritkey"
+ ENV['AWS_SESSION_TOKEN'] = 'somesuperlongsessiontokenspecialcharsblah!#%$#@$^!@qewpofudjsvjm'
+
+ creds = aws.load_env_credentials
+ expect( creds[:access_key] ).to eq("IMANACCESSKEY")
+ expect( creds[:secret_key] ).to eq("supersekritkey")
+ expect( creds[:session_token] ).to eq('somesuperlongsessiontokenspecialcharsblah!#%$#@$^!@qewpofudjsvjm')
+ end
+
end
+ context 'dont read fog credentials' do
+ let(:options) { make_opts.merge({ 'use_fog_credentials' => false }) }
+
+ it 'not using fog' do
+ creds = aws.load_env_credentials
+ expect( creds[:access_key] ).to eq(nil)
+ expect( creds[:secret_key] ).to eq(nil)
+ expect( options[:use_fog_credentials] ).to eq(false)
+ end
+ end
+
describe '#provision' do
before :each do
expect(aws).to receive(:launch_all_nodes)
expect(aws).to receive(:add_tags)
expect(aws).to receive(:populate_dns)
@@ -624,15 +650,16 @@
end
it 'sets the the vmhostname to the beaker config name for each host' do
options[:use_beaker_hostnames] = true
@hosts.each do |host|
- host[:name] = "prettyponyprincess"
+ host.instance_eval("@name = 'prettyponyprincess'")
end
expect(set_hostnames).to eq(@hosts)
@hosts.each do |host|
- expect(host[:vmhostname]).to eq(host[:name])
+ expect(host[:vmhostname]).not_to eq(nil)
+ expect(host[:vmhostname]).to eq(host.name)
expect(host[:vmhostname]).to eq(host.hostname)
end
end
end
@@ -947,15 +974,23 @@
end
end
describe '#load_fog_credentials' do
# Receive#and_call_original below allows us to test the core load_fog_credentials method
- let(:creds) { {:access_key => 'awskey', :secret_key => 'awspass'} }
let(:dot_fog) { '.fog' }
subject(:load_fog_credentials) { aws.load_fog_credentials(dot_fog) }
it 'returns loaded fog credentials' do
+ creds = {:access_key => 'awskey', :secret_key => 'awspass', :session_token => nil}
fog_hash = {:default => {:aws_access_key_id => 'awskey', :aws_secret_access_key => 'awspass'}}
+ expect(aws).to receive(:load_fog_credentials).and_call_original
+ expect(YAML).to receive(:load_file).and_return(fog_hash)
+ expect(load_fog_credentials).to eq(creds)
+ end
+
+ it 'returns loaded fog credentials with session token' do
+ creds = {:access_key => 'awskey', :secret_key => 'awspass', :session_token => 'sometoken'}
+ fog_hash = {:default => {:aws_access_key_id => 'awskey', :aws_secret_access_key => 'awspass', :aws_session_token => 'sometoken'}}
expect(aws).to receive(:load_fog_credentials).and_call_original
expect(YAML).to receive(:load_file).and_return(fog_hash)
expect(load_fog_credentials).to eq(creds)
end