Skip to content

Commit bef4299

Browse files
authored
Ensure SSOCredentials expiration is a time (#2876)
1 parent 062dc1a commit bef4299

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Ensure `SSOCredentials` `#expiration` is a `Time` (#2874)
5+
46
3.176.0 (2023-06-28)
57
------------------
68

gems/aws-sdk-core/lib/aws-sdk-core/sso_credentials.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def refresh
158158
c.secret_access_key,
159159
c.session_token
160160
)
161-
@expiration = c.expiration
161+
@expiration = Time.at(c.expiration / 1000.0)
162162
end
163163

164164
def sso_cache_file

gems/aws-sdk-core/spec/aws/sso_credentials_spec.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ module Aws
1212
)
1313
end
1414

15-
let(:in_one_hour) { Time.now + 60 * 60 }
16-
let(:one_hour_ago) { Time.now - 60 * 60 }
15+
let(:time) { Time.at(Time.now.to_i) }
16+
let(:in_one_hour) { time + 60 * 60 }
17+
let(:one_hour_ago) { time - 60 * 60 }
1718
let(:expiration) { in_one_hour }
1819

1920
let(:sso_resp) do
2021
{
2122
role_credentials: {
22-
access_key_id: 'akid',
23-
secret_access_key: 'secret',
24-
session_token: 'session',
25-
expiration: expiration.to_i
23+
access_key_id: 'akid',
24+
secret_access_key: 'secret',
25+
session_token: 'session',
26+
expiration: expiration.to_i * 1000
2627
}
2728
}
2829
end
@@ -135,6 +136,14 @@ def mock_token_file(start_url, cached_token)
135136
sso_creds.credentials
136137
end
137138
end
139+
140+
describe '#expiration' do
141+
it 'parses expiration as Time' do
142+
sso_creds = SSOCredentials.new(sso_opts)
143+
expect(sso_creds.expiration).to be_a(Time)
144+
expect(sso_creds.expiration).to eq(expiration)
145+
end
146+
end
138147
end
139148

140149
context 'legacy profile' do

0 commit comments

Comments
 (0)