Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Add test for AWS config and credentials files
Browse files Browse the repository at this point in the history
  • Loading branch information
alexconst committed Feb 5, 2016
1 parent cb922a9 commit 1d29d81
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
86 changes: 86 additions & 0 deletions spec/vagrant-aws/config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
require "vagrant-aws/config"
require 'rspec/its'

# remove deprecation warnings
# (until someone decides to update the whole spec file to rspec 3.4)
RSpec.configure do |config|
# ...
config.mock_with :rspec do |c|
c.syntax = [:should, :expect]
end
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
end

describe VagrantPlugins::AWS::Config do
let(:instance) { described_class.new }

Expand Down Expand Up @@ -110,6 +122,80 @@
end
end


describe "getting credentials from AWS profile" do
let(:filename_cfg) { "/.aws/config" }
let(:filename_keys) { "/.aws/credentials" }
#let(:data_cfg) { "[default]\nregion=eu-west-1\noutput=text" }
#let(:data_keys) { "[default]\naws_access_key_id=AKI\naws_secret_access_key=foobar" }
let(:data_cfg) {
"[default]
region=eu-west-1
output=json
[profile user1]
region=us-east-1
output=text
[profile user2]
region=us-east-1
output=text
[profile user3]
region=us-west-2
output=text
" }
let(:data_keys) {
"[default]
aws_access_key_id=AKIdefault
aws_secret_access_key=PASSdefault
[user1]
aws_access_key_id=AKIuser1
aws_secret_access_key=PASSuser1
[user2]
aws_access_key_id=AKIuser2
aws_secret_access_key=PASSuser2
aws_session_token=TOKuser2
[user3]
aws_access_key_id=AKIuser3
aws_secret_access_key=PASSuser3
aws_session_token= TOKuser3
" }
context "without EC2 credential environment variables and fallback to default profile" do
## ENV has been nuked so ENV['HOME'] will be a empty string
subject do
allow(File).to receive(:read).with(filename_cfg).and_return(data_cfg)
allow(File).to receive(:read).with(filename_keys).and_return(data_keys)
instance.tap do |o|
o.finalize!
end
end
its("access_key_id") { should == "AKIdefault" }
its("secret_access_key") { should == "PASSdefault" }
its("session_token") { should be_nil }
end

context "without EC2 credential environment variables and chosing a profile" do
## ENV has been nuked so ENV['HOME'] will be a empty string
subject do
allow(File).to receive(:read).with(filename_cfg).and_return(data_cfg)
allow(File).to receive(:read).with(filename_keys).and_return(data_keys)
instance.aws_profile = "user3"
instance.tap do |o|
o.finalize!
end
end
its("access_key_id") { should == "AKIuser3" }
its("secret_access_key") { should == "PASSuser3" }
its("session_token") { should == "TOKuser3" }
its("region") { should == "us-west-2" }
end
end


describe "region config" do
let(:config_access_key_id) { "foo" }
let(:config_ami) { "foo" }
Expand Down
3 changes: 2 additions & 1 deletion vagrant-aws.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "fog", "~> 1.22"

s.add_development_dependency "rake"
s.add_development_dependency "rspec", "~> 2.12"
# rspec 3.4 to mock File
s.add_development_dependency "rspec", "~> 3.4"
s.add_development_dependency "rspec-its"

# The following block of code determines the files that should be included
Expand Down

0 comments on commit 1d29d81

Please sign in to comment.