mirror of
https://github.com/aws-actions/configure-aws-credentials.git
synced 2026-09-04 06:15:07 +09:00
Various fixes
Remove file-based env vars Add support for session credentials Add account ID as an output Remove testing actions workflow
This commit is contained in:
+33
-16
@@ -1,12 +1,19 @@
|
||||
const core = require('@actions/core');
|
||||
const io = require('@actions/io');
|
||||
|
||||
const run = require('.');
|
||||
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/io');
|
||||
|
||||
describe('Setup AWS', () => {
|
||||
const mockStsCallerIdentity = jest.fn();
|
||||
jest.mock('aws-sdk', () => {
|
||||
return {
|
||||
STS: jest.fn(() => ({
|
||||
getCallerIdentity: mockStsCallerIdentity
|
||||
}))
|
||||
};
|
||||
});
|
||||
|
||||
describe('Configure AWS Credentials', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
@@ -16,38 +23,48 @@ describe('Setup AWS', () => {
|
||||
.mockReturnValueOnce('MY-AWS-ACCESS-KEY-ID') // aws-access-key-id
|
||||
.mockReturnValueOnce('MY-AWS-SECRET-ACCESS-KEY') // aws-secret-access-key
|
||||
.mockReturnValueOnce('us-east-2') // aws-default-region
|
||||
.mockReturnValueOnce('json'); // aws-default-output
|
||||
.mockReturnValueOnce('MY-AWS-SESSION-TOKEN'); // aws-session-token
|
||||
|
||||
mockStsCallerIdentity.mockImplementation(() => {
|
||||
return {
|
||||
promise() {
|
||||
return Promise.resolve({ Account: '123456789012' });
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
test('exports env vars', async () => {
|
||||
await run();
|
||||
expect(core.exportVariable).toHaveBeenCalledTimes(6);
|
||||
expect(core.exportVariable).toHaveBeenCalledTimes(5);
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'MY-AWS-ACCESS-KEY-ID');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'MY-AWS-SECRET-ACCESS-KEY');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SESSION_TOKEN', 'MY-AWS-SESSION-TOKEN');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_REGION', 'us-east-2');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_OUTPUT', 'json');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_CONFIG_FILE', '/runner/home/.aws/config');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SHARED_CREDENTIALS_FILE', '/runner/home/.aws/credentials');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_REGION', 'us-east-2');
|
||||
expect(core.setOutput).toHaveBeenCalledWith('aws-account-id', '123456789012');
|
||||
});
|
||||
|
||||
test('aws can be configured for a different region', async () => {
|
||||
test('session token is optional', async () => {
|
||||
core.getInput = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce('MY-AWS-ACCESS-KEY-ID') // aws-access-key-id
|
||||
.mockReturnValueOnce('MY-AWS-SECRET-ACCESS-KEY') // aws-secret-access-key
|
||||
.mockReturnValueOnce('eu-west-1') // aws-default-region
|
||||
.mockReturnValueOnce('json'); // aws-default-output
|
||||
.mockReturnValueOnce('eu-west-1'); // aws-default-region
|
||||
|
||||
await run();
|
||||
expect(core.exportVariable).toHaveBeenCalledTimes(4);
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'MY-AWS-ACCESS-KEY-ID');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'MY-AWS-SECRET-ACCESS-KEY');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_REGION', 'eu-west-1');
|
||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_REGION', 'eu-west-1');
|
||||
expect(core.setOutput).toHaveBeenCalledWith('aws-account-id', '123456789012');
|
||||
});
|
||||
|
||||
test('error is caught by core.setFailed', async () => {
|
||||
io.mkdirP = jest
|
||||
.fn()
|
||||
.mockImplementation(() => {
|
||||
throw new Error();
|
||||
});
|
||||
mockStsCallerIdentity.mockImplementation(() => {
|
||||
throw new Error();
|
||||
});
|
||||
|
||||
await run();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user