Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure SSOCredentials expiration is a time #2876

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
mullermp marked this conversation as resolved.
Show resolved Hide resolved
expect(sso_creds.expiration).to eq(expiration)
end
end
end

context 'legacy profile' do
Expand Down