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

fix(cli): allow credential plugins to return null for expiration #32554

Merged
merged 1 commit into from
Dec 17, 2024
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: 1 addition & 1 deletion packages/aws-cdk/lib/api/aws-auth/provider-caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export function makeCachingProvider(provider: AwsCredentialIdentityProvider): Aw

export function credentialsAboutToExpire(token: AwsCredentialIdentity) {
const expiryMarginSecs = 5;
return token.expiration !== undefined && token.expiration.getTime() - Date.now() < expiryMarginSecs * 1000;
return !!token.expiration && token.expiration.getTime() - Date.now() < expiryMarginSecs * 1000;
}
10 changes: 10 additions & 0 deletions packages/aws-cdk/test/api/plugin/credential-plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CredentialPlugins } from '../../../lib/api/aws-auth/credential-plugins';
import { credentialsAboutToExpire } from '../../../lib/api/aws-auth/provider-caching';
import { CredentialProviderSource, Mode, SDKv3CompatibleCredentials } from '../../../lib/api/plugin/credential-provider-source';
import { PluginHost, markTesting } from '../../../lib/api/plugin/plugin';

Expand Down Expand Up @@ -134,6 +135,15 @@ test('plugin must not return something that is not a credential', async () => {
await expect(fetchNow()).rejects.toThrow(/Plugin returned a value that/);
});

test('token expiration is allowed to be null', () => {
expect(credentialsAboutToExpire({
accessKeyId: 'key',
secretAccessKey: 'secret',
// This is not allowed according to the `.d.ts` contract, but it can happen in reality
expiration: null as any,
})).toEqual(false);
});

function mockCredentialFunction(p: CredentialProviderSource['getProvider']) {
mockCredentialPlugin({
name: 'test',
Expand Down
Loading