Skip to content

Commit

Permalink
fix(cli): doesn't support plugins that return initially empty credent…
Browse files Browse the repository at this point in the history
…ials (#32552)

Plugins that return V2 credentials objects, return credentials that are self-refreshing. Those credentials can start out empty, which is perfectly valid.

We shouldn't reject them if they are.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored and HBobertz committed Dec 17, 2024
1 parent 4eac959 commit 7ee9b90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/api/aws-auth/credential-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function isV3Provider(x: PluginProviderResult): x is SDKv3CompatibleCredentialPr
}

function isV2Credentials(x: PluginProviderResult): x is SDKv2CompatibleCredentials {
return !!(x && typeof x === 'object' && x.accessKeyId && (x as SDKv2CompatibleCredentials).getPromise);
return !!(x && typeof x === 'object' && (x as SDKv2CompatibleCredentials).getPromise);
}

function isV3Credentials(x: PluginProviderResult): x is SDKv3CompatibleCredentials {
Expand Down
20 changes: 20 additions & 0 deletions packages/aws-cdk/test/api/plugin/credential-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ test('plugin can return V2 compatible credential-provider', async () => {
expect(getPromise).toHaveBeenCalled();
});

test('plugin can return V2 compatible credential-provider with initially empty keys', async () => {
// GIVEN
mockCredentialFunction(() => Promise.resolve({
accessKeyId: '',
secretAccessKey: '',
expired: false,
getPromise() {
this.accessKeyId = 'keyid';
return Promise.resolve({});
},
}));

// WHEN
const creds = await fetchNow();

await expect(creds).toEqual(expect.objectContaining({
accessKeyId: 'keyid',
}));
});

test('plugin must not return something that is not a credential', async () => {
// GIVEN
mockCredentialFunction(() => Promise.resolve({
Expand Down

0 comments on commit 7ee9b90

Please sign in to comment.