@@ -13,6 +13,14 @@ module Aws
1313 '..' , 'fixtures' , 'credentials' , 'mock_shared_config' ) )
1414 }
1515
16+ let ( :imds_url ) {
17+ 'http://169.254.169.254/latest/meta-data/iam/security-credentials/'
18+ }
19+
20+ let ( :imds_token_url ) {
21+ 'http://169.254.169.254/latest/api/token'
22+ }
23+
1624 describe "default behavior" do
1725 before ( :each ) do
1826 stub_const ( 'ENV' , { } )
@@ -56,28 +64,32 @@ module Aws
5664 "AR_TOKEN"
5765 )
5866 client = Aws ::S3 ::Client . new ( profile : "ar_plus_creds" , region : "us-east-1" )
59- expect ( client . config . credentials . access_key_id ) . to eq ( "AR_AKID" )
67+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "AR_AKID" )
6068 end
6169
6270 it 'prefers shared credential file static credentials over shared config' do
6371 client = Aws ::S3 ::Client . new ( profile : "credentials_first" , region : "us-east-1" )
64- expect ( client . config . credentials . access_key_id ) . to eq ( "ACCESS_KEY_CRD" )
72+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "ACCESS_KEY_CRD" )
6573 end
6674
6775 it 'will source static credentials from shared config after shared credentials' do
6876 client = Aws ::S3 ::Client . new ( profile : "incomplete_cred" , region : "us-east-1" )
69- expect ( client . config . credentials . access_key_id ) . to eq ( "ACCESS_KEY_SC1" )
77+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "ACCESS_KEY_SC1" )
7078 end
7179
7280 it 'attempts to fetch metadata credentials last' do
73- stub_request (
74- :get ,
75- "http://169.254.169.254/latest/meta-data/iam/security-credentials/"
76- ) . to_return ( :status => 200 , :body => "profile-name\n " )
77- stub_request (
78- :get ,
79- "http://169.254.169.254/latest/meta-data/iam/security-credentials/profile-name"
80- ) . to_return ( :status => 200 , :body => <<-JSON . strip )
81+ stub_request ( :put , imds_token_url )
82+ . to_return (
83+ :status => 200 ,
84+ :body => "my-token\n " ,
85+ :headers => { "x-aws-ec2-metadata-token-ttl-seconds" => "21600" }
86+ )
87+ stub_request ( :get , imds_url )
88+ . with ( :headers => { "x-aws-ec2-metadata-token" => "my-token" } )
89+ . to_return ( :status => 200 , :body => "profile-name\n " )
90+ stub_request ( :get , "#{ imds_url } profile-name" )
91+ . with ( :headers => { "x-aws-ec2-metadata-token" => "my-token" } )
92+ . to_return ( :status => 200 , :body => <<-JSON . strip )
8193{
8294 "Code" : "Success",
8395 "LastUpdated" : "2013-11-22T20:03:48Z",
@@ -89,11 +101,11 @@ module Aws
89101}
90102JSON
91103 client = Aws ::S3 ::Client . new ( profile : "nonexistant" , region : "us-east-1" )
92- expect ( client . config . credentials . access_key_id ) . to eq ( "akid-md" )
104+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "akid-md" )
93105 end
94106
95107 describe 'Assume Role Resolution' do
96- it 'will not assume a role without source_profile present' do
108+ it 'will not assume a role without a source present' do
97109 expect {
98110 Aws ::S3 ::Client . new ( profile : "ar_no_src" , region : "us-east-1" )
99111 } . to raise_error ( Errors ::NoSourceProfileError )
@@ -114,7 +126,7 @@ module Aws
114126 "AR_TOKEN"
115127 )
116128 client = Aws ::S3 ::Client . new ( profile : "assumerole_sc" , region : "us-east-1" )
117- expect ( client . config . credentials . access_key_id ) . to eq ( "AR_AKID" )
129+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "AR_AKID" )
118130 end
119131
120132 it 'will then try to assume a role from shared config' do
@@ -126,7 +138,7 @@ module Aws
126138 "AR_TOKEN"
127139 )
128140 client = Aws ::S3 ::Client . new ( profile : "ar_from_self" , region : "us-east-1" )
129- expect ( client . config . credentials . access_key_id ) . to eq ( "AR_AKID" )
141+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "AR_AKID" )
130142 end
131143
132144 it 'will assume a role from config using source credentials in shared credentials' do
@@ -138,9 +150,10 @@ module Aws
138150 "AR_TOKEN"
139151 )
140152 client = Aws ::S3 ::Client . new ( profile : "creds_from_sc" , region : "us-east-1" )
141- expect ( client . config . credentials . access_key_id ) . to eq ( "AR_AKID" )
153+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "AR_AKID" )
142154 end
143155 end
156+
144157 end
145158
146159 describe "AWS_SDK_CONFIG_OPT_OUT set" do
@@ -165,7 +178,7 @@ module Aws
165178 profile : "fooprofile" ,
166179 region : "us-east-1"
167180 )
168- expect ( client . config . credentials . access_key_id ) . to eq ( "ACCESS_DIRECT" )
181+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "ACCESS_DIRECT" )
169182 end
170183
171184 it 'prefers ENV credentials over shared config' do
@@ -174,7 +187,7 @@ module Aws
174187 "AWS_SECRET_ACCESS_KEY" => "SECRET_ENV_STUB"
175188 } )
176189 client = Aws ::S3 ::Client . new ( profile : "fooprofile" , region : "us-east-1" )
177- expect ( client . config . credentials . access_key_id ) . to eq ( "AKID_ENV_STUB" )
190+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "AKID_ENV_STUB" )
178191 end
179192
180193 it 'will not load credentials from shared config' do
@@ -188,14 +201,18 @@ module Aws
188201 end
189202
190203 it 'attempts to fetch metadata credentials last' do
191- stub_request (
192- :get ,
193- "http://169.254.169.254/latest/meta-data/iam/security-credentials/"
194- ) . to_return ( :status => 200 , :body => "profile-name\n " )
195- stub_request (
196- :get ,
197- "http://169.254.169.254/latest/meta-data/iam/security-credentials/profile-name"
198- ) . to_return ( :status => 200 , :body => <<-JSON . strip )
204+ stub_request ( :put , imds_token_url )
205+ . to_return (
206+ :status => 200 ,
207+ :body => "my-token\n " ,
208+ :headers => { "x-aws-ec2-metadata-token-ttl-seconds" => "21600" }
209+ )
210+ stub_request ( :get , imds_url )
211+ . with ( :headers => { "x-aws-ec2-metadata-token" => "my-token" } )
212+ . to_return ( :status => 200 , :body => "profile-name\n " )
213+ stub_request ( :get , "#{ imds_url } profile-name" )
214+ . with ( :headers => { "x-aws-ec2-metadata-token" => "my-token" } )
215+ . to_return ( :status => 200 , :body => <<-JSON . strip )
199216{
200217 "Code" : "Success",
201218 "LastUpdated" : "2013-11-22T20:03:48Z",
@@ -207,7 +224,7 @@ module Aws
207224}
208225JSON
209226 client = Aws ::S3 ::Client . new ( profile : "nonexistant" , region : "us-east-1" )
210- expect ( client . config . credentials . access_key_id ) . to eq ( "akid-md" )
227+ expect ( client . config . credentials . credentials . access_key_id ) . to eq ( "akid-md" )
211228 end
212229 end
213230
0 commit comments