diff --git a/src/index.ts b/src/index.ts index 51bab626..aac1ca5f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,7 +61,7 @@ export async function run() { const unsetCurrentCredentials = getBooleanInput('unset-current-credentials', { required: false }); let disableRetry = getBooleanInput('disable-retry', { required: false }); const specialCharacterWorkaround = getBooleanInput('special-characters-workaround', { required: false }); - const useExistingCredentials = core.getInput('use-existing-credentials', { required: false }); + const useExistingCredentials = getBooleanInput('use-existing-credentials', { required: false }); let maxRetries = Number.parseInt(core.getInput('retry-max-attempts', { required: false })) || 12; const expectedAccountIds = core .getInput('allowed-account-ids', { required: false }) diff --git a/test/index.test.ts b/test/index.test.ts index 4a946233..eec4e10c 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -648,6 +648,20 @@ describe('Configure AWS Credentials', {}, () => { await run(); expect(core.setFailed).not.toHaveBeenCalled(); }); + it('gets new creds if user explicitly said not to use existing credentials', {}, async () => { + vi.mocked(core.getInput).mockImplementation(mocks.getInput(mocks.USE_EXISTING_CREDENTIALS_FALSE_INPUTS)); + vi.mocked(core.getIDToken).mockResolvedValue('testoidctoken'); + process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'fake-token'; + // Valid existing credentials are available, but should be ignored + mockedSTSClient.on(GetCallerIdentityCommand).resolves(mocks.outputs.GET_CALLER_IDENTITY); + mockedSTSClient.on(AssumeRoleWithWebIdentityCommand).resolvesOnce(mocks.outputs.STS_CREDENTIALS); + await run(); + expect(core.notice).not.toHaveBeenCalledWith('Pre-existing credentials are valid. No need to generate new ones.'); + expect(core.info).toHaveBeenCalledWith('Assuming role with OIDC'); + expect(mockedSTSClient.commandCalls(AssumeRoleWithWebIdentityCommand)).toHaveLength(1); + expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'STSAWSACCESSKEYID'); + expect(core.setFailed).not.toHaveBeenCalled(); + }); it("doesn't export credentials as environment variables if told not to", {}, async () => { mockedSTSClient.on(AssumeRoleWithWebIdentityCommand).resolvesOnce(mocks.outputs.STS_CREDENTIALS); // Credentials are validated (and their account resolved) even when not exported to the diff --git a/test/mockinputs.test.ts b/test/mockinputs.test.ts index 68ee8a04..59aed1ca 100644 --- a/test/mockinputs.test.ts +++ b/test/mockinputs.test.ts @@ -91,6 +91,11 @@ const inputs = { 'output-env-credentials': 'false', 'output-credentials': 'true', }, + USE_EXISTING_CREDENTIALS_FALSE_INPUTS: { + 'aws-region': 'fake-region-1', + 'use-existing-credentials': 'false', + 'role-to-assume': 'arn:aws:iam::111111111111:role/MY-ROLE', + }, }; const envs = {