Skip to content

Commit

Permalink
Ensure SSOCredentials expiration is a time (#2876)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextwoods authored Jun 29, 2023
1 parent 062dc1a commit bef4299
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Ensure `SSOCredentials` `#expiration` is a `Time` (#2874)

3.176.0 (2023-06-28)
------------------

Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/sso_credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def refresh
c.secret_access_key,
c.session_token
)
@expiration = c.expiration
@expiration = Time.at(c.expiration / 1000.0)
end

def sso_cache_file
Expand Down
21 changes: 15 additions & 6 deletions gems/aws-sdk-core/spec/aws/sso_credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ module Aws
)
end

let(:in_one_hour) { Time.now + 60 * 60 }
let(:one_hour_ago) { Time.now - 60 * 60 }
let(:time) { Time.at(Time.now.to_i) }
let(:in_one_hour) { time + 60 * 60 }
let(:one_hour_ago) { time - 60 * 60 }
let(:expiration) { in_one_hour }

let(:sso_resp) do
{
role_credentials: {
access_key_id: 'akid',
secret_access_key: 'secret',
session_token: 'session',
expiration: expiration.to_i
access_key_id: 'akid',
secret_access_key: 'secret',
session_token: 'session',
expiration: expiration.to_i * 1000
}
}
end
Expand Down Expand Up @@ -135,6 +136,14 @@ def mock_token_file(start_url, cached_token)
sso_creds.credentials
end
end

describe '#expiration' do
it 'parses expiration as Time' do
sso_creds = SSOCredentials.new(sso_opts)
expect(sso_creds.expiration).to be_a(Time)
expect(sso_creds.expiration).to eq(expiration)
end
end
end

context 'legacy profile' do
Expand Down

0 comments on commit bef4299

Please sign in to comment.