diff --git a/gems/aws-sdk-core/CHANGELOG.md b/gems/aws-sdk-core/CHANGELOG.md index 44e95976791..2bf6e4d9181 100644 --- a/gems/aws-sdk-core/CHANGELOG.md +++ b/gems/aws-sdk-core/CHANGELOG.md @@ -1,6 +1,8 @@ Unreleased Changes ------------------ +* Issue - Ensure `SSOCredentials` `#expiration` is a `Time` (#2874) + 3.176.0 (2023-06-28) ------------------ diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/sso_credentials.rb b/gems/aws-sdk-core/lib/aws-sdk-core/sso_credentials.rb index 8557a84dbe2..5613d357470 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/sso_credentials.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/sso_credentials.rb @@ -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 diff --git a/gems/aws-sdk-core/spec/aws/sso_credentials_spec.rb b/gems/aws-sdk-core/spec/aws/sso_credentials_spec.rb index 1f1d8b438da..0ebd50cf557 100644 --- a/gems/aws-sdk-core/spec/aws/sso_credentials_spec.rb +++ b/gems/aws-sdk-core/spec/aws/sso_credentials_spec.rb @@ -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 @@ -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