Skip to content

Commit

Permalink
fix: throws error even when valid credentials are present
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwoodworth committed Aug 30, 2023
1 parent 6c962b9 commit ac71d77
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export async function run() {
!roleChaining &&
!(process.env['AWS_ACCESS_KEY_ID'] && process.env['AWS_SECRET_ACCESS_KEY'])
) {
throw new Error('Could not determine how to assume credentials. Please check your inputs and try again.');
// Proceed if credentials are picked up
await credentialsClient.validateCredentials();
sourceAccountId = await exportAccountId(credentialsClient, maskAccountId);
}

if (AccessKeyId || roleChaining || (process.env['AWS_ACCESS_KEY_ID'] && process.env['AWS_SECRET_ACCESS_KEY'])) {
Expand Down
7 changes: 4 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe('Configure AWS Credentials', () => {
await run();

expect(core.setFailed).toHaveBeenCalledWith(
'Could not determine how to assume credentials. Please check your inputs and try again.'
'Credentials could not be loaded, please check your action inputs: Could not load credentials from any providers'
);
});

Expand All @@ -217,7 +217,7 @@ describe('Configure AWS Credentials', () => {
await run();

expect(core.setFailed).toHaveBeenCalledWith(
'Could not determine how to assume credentials. Please check your inputs and try again.'
'Credentials could not be loaded, please check your action inputs: Access key ID empty after loading credentials'
);
});

Expand Down Expand Up @@ -508,6 +508,7 @@ describe('Configure AWS Credentials', () => {
});

test('GH OIDC check fails if token is not set', async () => {
(fromEnv as jest.Mock).mockReset();
process.env['ACTIONS_ID_TOKEN_REQUEST_TOKEN'] = undefined;
process.env['GITHUB_ACTIONS'] = 'true';
jest.spyOn(core, 'getInput').mockImplementation(
Expand All @@ -524,7 +525,7 @@ describe('Configure AWS Credentials', () => {
' If you are not trying to authenticate with OIDC and the action is working successfully, you can ignore this message.'
);
expect(core.setFailed).toHaveBeenCalledWith(
'Could not determine how to assume credentials. Please check your inputs and try again.'
'Credentials could not be loaded, please check your action inputs: provider is not a function'
);
});

Expand Down

0 comments on commit ac71d77

Please sign in to comment.