mirror of
https://github.com/aws-actions/configure-aws-credentials.git
synced 2026-09-03 06:05:04 +09:00
chore: add initial tests
This commit is contained in:
Generated
+1
-1
@@ -87,7 +87,7 @@
|
|||||||
"description": "Synthesize project files",
|
"description": "Synthesize project files",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"exec": "node .projenrc.cjs"
|
"exec": "node .projenrc.js"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,7 +5,12 @@ const { NodePackageManager, NpmAccess } = require('projen/lib/javascript');
|
|||||||
|
|
||||||
const project = new GitHubActionTypeScriptProject({
|
const project = new GitHubActionTypeScriptProject({
|
||||||
defaultReleaseBranch: 'main',
|
defaultReleaseBranch: 'main',
|
||||||
devDeps: ['projen-github-action-typescript', '@aws-sdk/credential-provider-env', 'aws-sdk-client-mock', '@jest/globals'],
|
devDeps: [
|
||||||
|
'projen-github-action-typescript',
|
||||||
|
'@aws-sdk/credential-provider-env',
|
||||||
|
'aws-sdk-client-mock',
|
||||||
|
'@jest/globals',
|
||||||
|
],
|
||||||
deps: ['@aws-sdk/client-sts@^3'],
|
deps: ['@aws-sdk/client-sts@^3'],
|
||||||
name: 'configure-aws-credentials',
|
name: 'configure-aws-credentials',
|
||||||
description: 'A GitHub Action to configure AWS credentials',
|
description: 'A GitHub Action to configure AWS credentials',
|
||||||
@@ -15,9 +20,6 @@ const project = new GitHubActionTypeScriptProject({
|
|||||||
authorOrganization: true,
|
authorOrganization: true,
|
||||||
authorUrl: 'https://aws.amazon.com',
|
authorUrl: 'https://aws.amazon.com',
|
||||||
packageManager: NodePackageManager.NPM,
|
packageManager: NodePackageManager.NPM,
|
||||||
projenrcJsOptions: {
|
|
||||||
filename: '.projenrc.cjs',
|
|
||||||
},
|
|
||||||
sampleCode: false,
|
sampleCode: false,
|
||||||
actionMetadata: {
|
actionMetadata: {
|
||||||
name: '"Configure AWS Credentials" Action for GitHub Actions',
|
name: '"Configure AWS Credentials" Action for GitHub Actions',
|
||||||
@@ -130,7 +132,8 @@ const project = new GitHubActionTypeScriptProject({
|
|||||||
inlineSourceMap: true,
|
inlineSourceMap: true,
|
||||||
strict: true,
|
strict: true,
|
||||||
// Node 16 is ES2022
|
// Node 16 is ES2022
|
||||||
target: 'ES2022',
|
target: 'es2022',
|
||||||
|
module: 'commonjs',
|
||||||
outDir: 'build',
|
outDir: 'build',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -145,10 +148,14 @@ const project = new GitHubActionTypeScriptProject({
|
|||||||
bracketSpacing: true,
|
bracketSpacing: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
jestOptions: {
|
||||||
|
jestConfig: {
|
||||||
|
transform: { '^.+\\.m?[tj]sx?$': ['ts-jest', { tsconfig: 'tsconfig.dev.json' }] },
|
||||||
|
},
|
||||||
|
},
|
||||||
dependabot: true,
|
dependabot: true,
|
||||||
dependabotOptions: {
|
dependabotOptions: {
|
||||||
scheduleInterval: DependabotScheduleInterval.WEEKLY,
|
scheduleInterval: DependabotScheduleInterval.WEEKLY,
|
||||||
|
|
||||||
},
|
},
|
||||||
githubOptions: {
|
githubOptions: {
|
||||||
mergify: true,
|
mergify: true,
|
||||||
@@ -212,21 +219,12 @@ if (tsconfig) {
|
|||||||
}
|
}
|
||||||
// The default jest config does not have the correct path
|
// The default jest config does not have the correct path
|
||||||
project.jest?.addTestMatch('<rootDir>/test/**/*.(test|spec).(js|jsx|ts|tsx)');
|
project.jest?.addTestMatch('<rootDir>/test/**/*.(test|spec).(js|jsx|ts|tsx)');
|
||||||
// Future-proofing in case we decide to move to ESM
|
|
||||||
project.setScript('projen', 'node .projenrc.cjs');
|
|
||||||
// Most jest overrides. Specifically, work around the deprecation of the jest globals config
|
|
||||||
const packageJson = project.tryFindFile('package.json');
|
const packageJson = project.tryFindFile('package.json');
|
||||||
if (packageJson) {
|
if (packageJson) {
|
||||||
packageJson.addOverride('jest.transform', {
|
// The default jest config makes use of the deprecated globals.ts-jest option
|
||||||
'^.+\\.[tj]sx?$': [
|
|
||||||
'ts-jest',
|
|
||||||
{
|
|
||||||
useESM: true,
|
|
||||||
tsconfig: 'tsconfig.dev.json',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
packageJson.addOverride('jest.globals', undefined);
|
packageJson.addOverride('jest.globals', undefined);
|
||||||
|
// This is supposed to be controlled by jestConfig.preset, but it doesn't work
|
||||||
|
packageJson.addOverride('jest.preset', 'ts-jest/presets/default-legacy');
|
||||||
// The entrypoint property is supposed to manage this but it doesn't work
|
// The entrypoint property is supposed to manage this but it doesn't work
|
||||||
packageJson.addOverride('main', 'build/index.js');
|
packageJson.addOverride('main', 'build/index.js');
|
||||||
// We don't want to publish this to NPM.
|
// We don't want to publish this to NPM.
|
||||||
@@ -243,7 +241,7 @@ if (dependabotConfig) {
|
|||||||
directory: '/',
|
directory: '/',
|
||||||
'open-pull-requests-limit': 10,
|
'open-pull-requests-limit': 10,
|
||||||
'target-branch': 'v1-node16',
|
'target-branch': 'v1-node16',
|
||||||
ignore: [ { 'dependency-name': 'projen' } ],
|
ignore: [{ 'dependency-name': 'projen' }],
|
||||||
'versioning-strategy': 'lockfile-only',
|
'versioning-strategy': 'lockfile-only',
|
||||||
schedule: { interval: 'weekly', day: 'tuesday' },
|
schedule: { interval: 'weekly', day: 'tuesday' },
|
||||||
});
|
});
|
||||||
Generated
+829
-499
File diff suppressed because it is too large
Load Diff
Generated
+11
-11
@@ -17,7 +17,7 @@
|
|||||||
"test:watch": "npx projen test:watch",
|
"test:watch": "npx projen test:watch",
|
||||||
"unbump": "npx projen unbump",
|
"unbump": "npx projen unbump",
|
||||||
"watch": "npx projen watch",
|
"watch": "npx projen watch",
|
||||||
"projen": "node .projenrc.cjs"
|
"projen": "npx projen"
|
||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Amazon.com, Inc. or its affiliates",
|
"name": "Amazon.com, Inc. or its affiliates",
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@aws-sdk/credential-provider-env": "^3.186.0",
|
"@aws-sdk/credential-provider-env": "^3.186.0",
|
||||||
|
"@aws-sdk/credential-providers": "^3.188.0",
|
||||||
"@jest/globals": "^29.1.2",
|
"@jest/globals": "^29.1.2",
|
||||||
"@types/jest": "^29.1.2",
|
"@types/jest": "^29.1.2",
|
||||||
"@types/node": "^14",
|
"@types/node": "^14",
|
||||||
@@ -70,6 +71,14 @@
|
|||||||
"url": "https://github.com/aws-actions/configure-aws-credentials/issues"
|
"url": "https://github.com/aws-actions/configure-aws-credentials/issues"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.m?[tj]sx?$": [
|
||||||
|
"ts-jest",
|
||||||
|
{
|
||||||
|
"tsconfig": "tsconfig.dev.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"testMatch": [
|
"testMatch": [
|
||||||
"<rootDir>/src/**/__tests__/**/*.ts?(x)",
|
"<rootDir>/src/**/__tests__/**/*.ts?(x)",
|
||||||
"<rootDir>/(test|src)/**/*(*.)@(spec|test).ts?(x)",
|
"<rootDir>/(test|src)/**/*(*.)@(spec|test).ts?(x)",
|
||||||
@@ -103,16 +112,7 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"preset": "ts-jest",
|
"preset": "ts-jest/presets/default-legacy"
|
||||||
"transform": {
|
|
||||||
"^.+\\.[tj]sx?$": [
|
|
||||||
"ts-jest",
|
|
||||||
{
|
|
||||||
"useESM": true,
|
|
||||||
"tsconfig": "tsconfig.dev.json"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"types": "build/index.d.ts",
|
"types": "build/index.d.ts",
|
||||||
"overrides": {
|
"overrides": {
|
||||||
|
|||||||
+9
-1
@@ -38,9 +38,17 @@ export function isDefined<T>(i: T | undefined | null): i is T {
|
|||||||
return i !== undefined && i !== null;
|
return i !== undefined && i !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sleep(ms: number) {
|
function defaultSleep(ms: number) {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
let sleep = defaultSleep;
|
||||||
|
|
||||||
|
export function withsleep(s: typeof sleep) {
|
||||||
|
sleep = s;
|
||||||
|
}
|
||||||
|
export function reset() {
|
||||||
|
sleep = defaultSleep;
|
||||||
|
}
|
||||||
|
|
||||||
// retryAndBackoff retries with exponential backoff the promise if the error isRetryable upto maxRetries time.
|
// retryAndBackoff retries with exponential backoff the promise if the error isRetryable upto maxRetries time.
|
||||||
export async function retryAndBackoff<T>(
|
export async function retryAndBackoff<T>(
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
import { cleanup } from '../src/cleanup';
|
||||||
|
|
||||||
|
const FAKE_ACCESS_KEY_ID = 'MY-AWS-ACCESS-KEY-ID';
|
||||||
|
const FAKE_SECRET_ACCESS_KEY = 'MY-AWS-SECRET-ACCESS-KEY';
|
||||||
|
const FAKE_SESSION_TOKEN = 'MY-AWS-SESSION-TOKEN';
|
||||||
|
const FAKE_REGION = 'fake-region-1';
|
||||||
|
const ACTION_ENVIRONMENT_VARIABLES = {
|
||||||
|
AWS_ACCESS_KEY_ID: FAKE_ACCESS_KEY_ID,
|
||||||
|
AWS_SECRET_ACCESS_KEY: FAKE_SECRET_ACCESS_KEY,
|
||||||
|
AWS_SESSION_TOKEN: FAKE_SESSION_TOKEN,
|
||||||
|
AWS_DEFAULT_REGION: FAKE_REGION,
|
||||||
|
AWS_REGION: FAKE_REGION,
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Configure AWS Credentials', () => {
|
||||||
|
const OLD_ENV = process.env;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
jest.spyOn(core, 'exportVariable');
|
||||||
|
jest.spyOn(core, 'setSecret');
|
||||||
|
jest.spyOn(core, 'setOutput');
|
||||||
|
jest.spyOn(core, 'setFailed');
|
||||||
|
process.env = { ...OLD_ENV, ...ACTION_ENVIRONMENT_VARIABLES };
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
process.env = OLD_ENV;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('replaces AWS credential and region env vars with empty strings', async () => {
|
||||||
|
await cleanup();
|
||||||
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledTimes(5);
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', '');
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', '');
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SESSION_TOKEN', '');
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_REGION', '');
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_REGION', '');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('error is caught and fails the action', async () => {
|
||||||
|
jest.spyOn(core, 'exportVariable').mockImplementation(() => {
|
||||||
|
throw new Error();
|
||||||
|
});
|
||||||
|
|
||||||
|
await cleanup();
|
||||||
|
|
||||||
|
expect(core.setFailed).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
Generated
+2
-2
@@ -9,7 +9,7 @@
|
|||||||
"lib": [
|
"lib": [
|
||||||
"es2019"
|
"es2019"
|
||||||
],
|
],
|
||||||
"module": "CommonJS",
|
"module": "commonjs",
|
||||||
"noEmitOnError": true,
|
"noEmitOnError": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"strictPropertyInitialization": true,
|
"strictPropertyInitialization": true,
|
||||||
"stripInternal": true,
|
"stripInternal": true,
|
||||||
"target": "ES2022",
|
"target": "es2022",
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"outDir": "build"
|
"outDir": "build"
|
||||||
},
|
},
|
||||||
|
|||||||
Generated
+2
-2
@@ -11,7 +11,7 @@
|
|||||||
"lib": [
|
"lib": [
|
||||||
"es2019"
|
"es2019"
|
||||||
],
|
],
|
||||||
"module": "CommonJS",
|
"module": "commonjs",
|
||||||
"noEmitOnError": true,
|
"noEmitOnError": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"strictPropertyInitialization": true,
|
"strictPropertyInitialization": true,
|
||||||
"stripInternal": true,
|
"stripInternal": true,
|
||||||
"target": "ES2022",
|
"target": "es2022",
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"allowUnreachableCode": false,
|
"allowUnreachableCode": false,
|
||||||
"allowUnusedLabels": false,
|
"allowUnusedLabels": false,
|
||||||
|
|||||||
Reference in New Issue
Block a user