mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-06 23:06:54 +00:00
Revert convert to esm (#544)
* Revert "update got dependency and convert to esm module (#533)"
This reverts commit 77efb36ae3.
* keep new local test file changes
* keep changes to PR template
* update changelog
This commit is contained in:
parent
ee41aa2fcf
commit
66531b2752
39 changed files with 14341 additions and 12232 deletions
|
|
@ -1,11 +1,5 @@
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
Improvements:
|
|
||||||
|
|
||||||
* chore(deps): bump jsonata from 2.0.3 to 2.0.4 [GH-531](https://github.com/hashicorp/vault-action/pull/531)
|
|
||||||
* chore(deps): bump got from 11.8.6 to 14.2.1 [GH-533](https://github.com/hashicorp/vault-action/pull/533)
|
|
||||||
* convert project from common js to an esm module [GH-533](https://github.com/hashicorp/vault-action/pull/533)
|
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
|
||||||
* `secretId` is no longer required for approle to support advanced use cases like machine login when `bind_secret_id` is false. [GH-522](https://github.com/hashicorp/vault-action/pull/522)
|
* `secretId` is no longer required for approle to support advanced use cases like machine login when `bind_secret_id` is false. [GH-522](https://github.com/hashicorp/vault-action/pull/522)
|
||||||
|
|
|
||||||
2
Makefile
2
Makefile
|
|
@ -1,3 +1,3 @@
|
||||||
.PHONY: local-test
|
.PHONY: local-test
|
||||||
local-test:
|
local-test:
|
||||||
docker compose down; docker-compose up -d vault && act workflow_dispatch -j local-test
|
docker compose down; docker-compose up -d vault && act workflow_dispatch -j local-test -W .github/workflows/local-test.yaml
|
||||||
|
|
|
||||||
22776
dist/index.js
vendored
22776
dist/index.js
vendored
File diff suppressed because one or more lines are too long
3
dist/package.json
vendored
3
dist/package.json
vendored
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"type": "module"
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
import { vi, describe, test, expect } from 'vitest';
|
jest.mock('@actions/core');
|
||||||
|
jest.mock('@actions/core/lib/command');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
vi.mock('@actions/core');
|
const got = require('got');
|
||||||
import core from '@actions/core';
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
import got from 'got';
|
const { exportSecrets } = require('../../src/action');
|
||||||
import { when } from 'jest-when'
|
|
||||||
|
|
||||||
import { exportSecrets } from '../../src/action.js';
|
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
|
|
@ -103,7 +102,7 @@ describe('authenticate with approle', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method', expect.anything())
|
.calledWith('method', expect.anything())
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
import { vi, describe, test, expect } from 'vitest';
|
jest.mock('@actions/core');
|
||||||
|
jest.mock('@actions/core/lib/command');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
vi.mock('@actions/core');
|
const got = require('got');
|
||||||
import core from '@actions/core';
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
import got from 'got';
|
const { exportSecrets } = require('../../src/action');
|
||||||
import { when } from 'jest-when'
|
|
||||||
|
|
||||||
import { exportSecrets } from '../../src/action.js';
|
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
|
|
@ -108,7 +107,7 @@ describe('integration', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
|
||||||
3
integrationTests/basic/jest.config.js
Normal file
3
integrationTests/basic/jest.config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
verbose: true
|
||||||
|
};
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
import { vi, describe, test, expect } from 'vitest';
|
jest.mock('@actions/core');
|
||||||
|
jest.mock('@actions/core/lib/command');
|
||||||
vi.mock('@actions/core');
|
const core = require('@actions/core');
|
||||||
import core from '@actions/core';
|
const rsasign = require('jsrsasign');
|
||||||
import rsasign from 'jsrsasign';
|
const {
|
||||||
import {
|
|
||||||
privateRsaKey,
|
privateRsaKey,
|
||||||
privateRsaKeyBase64,
|
privateRsaKeyBase64,
|
||||||
publicRsaKey
|
publicRsaKey
|
||||||
} from './rsa_keys.js';
|
} = require('./rsa_keys');
|
||||||
|
|
||||||
import got from 'got';
|
const got = require('got');
|
||||||
import { when } from 'jest-when'
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
import { exportSecrets } from '../../src/action.js';
|
const { exportSecrets } = require('../../src/action');
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
|
|
@ -140,7 +139,7 @@ describe('jwt auth', () => {
|
||||||
|
|
||||||
describe('authenticate with private key', () => {
|
describe('authenticate with private key', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
@ -190,7 +189,7 @@ describe('jwt auth', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ LrJEY9tZaRF8xraMZiOcBcyAt6S/TS29HttJ6+zlhcWx34fItEZ8jA5gzhTmspOY
|
||||||
-----END PUBLIC KEY-----
|
-----END PUBLIC KEY-----
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export {
|
module.exports = {
|
||||||
privateRsaKey,
|
privateRsaKey,
|
||||||
privateRsaKeyBase64,
|
privateRsaKeyBase64,
|
||||||
publicRsaKey
|
publicRsaKey
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
import { vi, describe, test, expect } from 'vitest';
|
jest.mock('@actions/core');
|
||||||
|
jest.mock('@actions/core/lib/command');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
vi.mock('@actions/core');
|
const got = require('got');
|
||||||
import core from '@actions/core';
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
import got from 'got';
|
const { exportSecrets } = require('../../src/action');
|
||||||
import { when } from 'jest-when'
|
|
||||||
|
|
||||||
import { exportSecrets } from '../../src/action.js';
|
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
|
|
@ -85,7 +84,7 @@ describe('authenticate with userpass', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method', expect.anything())
|
.calledWith('method', expect.anything())
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
import { defineConfig, configDefaults } from 'vitest/config'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
test: {
|
|
||||||
// required to make jest-when work with vitest
|
|
||||||
globals: true,
|
|
||||||
include: [
|
|
||||||
'**/integrationTests/basic/**.{test,spec}.?(c|m)[jt]s?(x)',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import { describe, test, expect } from 'vitest';
|
|
||||||
|
|
||||||
describe('e2e-tls', () => {
|
describe('e2e-tls', () => {
|
||||||
it('verify', () => {
|
it('verify', () => {
|
||||||
expect(process.env.SECRET).toBe("SUPERSECRET");
|
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||||
|
|
|
||||||
3
integrationTests/e2e-tls/jest.config.js
Normal file
3
integrationTests/e2e-tls/jest.config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
verbose: true
|
||||||
|
};
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import got from 'got';
|
const got = require('got');
|
||||||
import core from '@actions/core';
|
const core = require('@actions/core');
|
||||||
|
|
||||||
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
||||||
const caCertificateRaw = `${process.env.VAULTCA}`;
|
const caCertificateRaw = `${process.env.VAULTCA}`;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
import { defineConfig, configDefaults } from 'vitest/config'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
test: {
|
|
||||||
// required to make jest-when work with vitest
|
|
||||||
globals: true,
|
|
||||||
include: [
|
|
||||||
'**/integrationTests/e2e-tls/**.{test,spec}.?(c|m)[jt]s?(x)',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import { describe, test, expect } from 'vitest';
|
|
||||||
|
|
||||||
describe('e2e', () => {
|
describe('e2e', () => {
|
||||||
it('verify', () => {
|
it('verify', () => {
|
||||||
expect(process.env.SECRET).toBe("SUPERSECRET");
|
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||||
|
|
|
||||||
3
integrationTests/e2e/jest.config.js
Normal file
3
integrationTests/e2e/jest.config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
verbose: true
|
||||||
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import got from 'got';
|
const got = require('got');
|
||||||
|
|
||||||
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN}` === undefined ? `${process.env.VAULT_TOKEN}` : "testtoken";
|
const vaultToken = `${process.env.VAULT_TOKEN}` === undefined ? `${process.env.VAULT_TOKEN}` : "testtoken";
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
import { defineConfig, configDefaults } from 'vitest/config'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
test: {
|
|
||||||
// required to make jest-when work with vitest
|
|
||||||
globals: true,
|
|
||||||
include: [
|
|
||||||
'**/integrationTests/e2e/**.{test,spec}.?(c|m)[jt]s?(x)',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
import { vi, describe, test, expect } from 'vitest';
|
jest.mock('@actions/core');
|
||||||
|
jest.mock('@actions/core/lib/command');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
vi.mock('@actions/core');
|
const got = require('got');
|
||||||
import core from '@actions/core';
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
import got from 'got';
|
const { exportSecrets } = require('../../src/action');
|
||||||
import { when } from 'jest-when'
|
|
||||||
|
|
||||||
import { exportSecrets } from '../../src/action.js';
|
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
|
|
@ -42,7 +41,7 @@ describe('integration', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
@ -239,7 +238,7 @@ describe('authenticate with approle', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method', expect.anything())
|
.calledWith('method', expect.anything())
|
||||||
|
|
|
||||||
3
integrationTests/enterprise/jest.config.js
Normal file
3
integrationTests/enterprise/jest.config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
verbose: true
|
||||||
|
};
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
import { defineConfig, configDefaults } from 'vitest/config'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
test: {
|
|
||||||
// required to make jest-when work with vitest
|
|
||||||
globals: true,
|
|
||||||
include: [
|
|
||||||
'**/integrationTests/enterprise/**.{test,spec}.?(c|m)[jt]s?(x)',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
3
jest.config.js
Normal file
3
jest.config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integrationTests/'],
|
||||||
|
};
|
||||||
|
|
@ -7,4 +7,4 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2018"
|
"target": "es2018"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
3432
package-lock.json
generated
3432
package-lock.json
generated
File diff suppressed because it is too large
Load diff
24
package.json
24
package.json
|
|
@ -2,15 +2,14 @@
|
||||||
"name": "vault-action",
|
"name": "vault-action",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "A Github Action that allows you to consume vault secrets as secure environment variables.",
|
"description": "A Github Action that allows you to consume vault secrets as secure environment variables.",
|
||||||
"type": "module",
|
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build src/entry.js -o dist",
|
"build": "ncc build src/entry.js -o dist",
|
||||||
"test": "vitest run",
|
"test": "jest",
|
||||||
"test:integration:basic": "vitest run -c integrationTests/basic/vitest.config.js",
|
"test:integration:basic": "jest -c integrationTests/basic/jest.config.js",
|
||||||
"test:integration:enterprise": "vitest run -c integrationTests/enterprise/vitest.config.js",
|
"test:integration:enterprise": "jest -c integrationTests/enterprise/jest.config.js",
|
||||||
"test:integration:e2e": "vitest run -c integrationTests/e2e/vitest.config.js",
|
"test:integration:e2e": "jest -c integrationTests/e2e/jest.config.js",
|
||||||
"test:integration:e2e-tls": "vitest run -c integrationTests/e2e-tls/vitest.config.js"
|
"test:integration:e2e-tls": "jest -c integrationTests/e2e-tls/jest.config.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/**/*",
|
"src/**/*",
|
||||||
|
|
@ -35,15 +34,18 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/hashicorp/vault-action#readme",
|
"homepage": "https://github.com/hashicorp/vault-action#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"got": "^11.8.6",
|
||||||
"got": "^14.2.1",
|
"jsonata": "^2.0.3",
|
||||||
"jsonata": "^2.0.4",
|
|
||||||
"jsrsasign": "^11.0.0"
|
"jsrsasign": "^11.0.0"
|
||||||
},
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@actions/core": ">=1 <2"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@actions/core": "^1.10.1",
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@vercel/ncc": "^0.38.1",
|
||||||
|
"jest": "^29.7.0",
|
||||||
"jest-when": "^3.6.0",
|
"jest-when": "^3.6.0",
|
||||||
"mock-http-server": "^1.4.5",
|
"mock-http-server": "^1.4.5"
|
||||||
"vitest": "^1.3.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
import core from '@actions/core';
|
// @ts-check
|
||||||
import got from 'got';
|
const core = require('@actions/core');
|
||||||
|
const command = require('@actions/core/lib/command');
|
||||||
import { normalizeOutputKey } from './utils.js';
|
const got = require('got').default;
|
||||||
import { WILDCARD } from './constants.js';
|
|
||||||
import { retrieveToken } from './auth.js';
|
|
||||||
import { getSecrets } from './secrets.js';
|
|
||||||
|
|
||||||
// ncc doesn't compile jsonata imports properly, so we must use our own custom require
|
|
||||||
import require from "./cjs-require.js";
|
|
||||||
const jsonata = require('jsonata');
|
const jsonata = require('jsonata');
|
||||||
|
const { normalizeOutputKey } = require('./utils');
|
||||||
|
const { WILDCARD } = require('./constants');
|
||||||
|
|
||||||
|
const { auth: { retrieveToken }, secrets: { getSecrets } } = require('./index');
|
||||||
|
|
||||||
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes', 'ldap', 'userpass'];
|
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes', 'ldap', 'userpass'];
|
||||||
const ENCODING_TYPES = ['base64', 'hex', 'utf8'];
|
const ENCODING_TYPES = ['base64', 'hex', 'utf8'];
|
||||||
|
|
@ -221,8 +219,9 @@ function parseHeadersInput(inputKey, inputOptions) {
|
||||||
}, new Map());
|
}, new Map());
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
module.exports = {
|
||||||
exportSecrets,
|
exportSecrets,
|
||||||
parseSecretsInput,
|
parseSecretsInput,
|
||||||
parseHeadersInput,
|
parseHeadersInput,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
import { vi, describe, test, expect } from 'vitest';
|
jest.mock('got');
|
||||||
|
jest.mock('@actions/core');
|
||||||
|
jest.mock('@actions/core/lib/command');
|
||||||
|
|
||||||
vi.mock('got');
|
const command = require('@actions/core/lib/command');
|
||||||
vi.mock('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
const got = require('got');
|
||||||
import core from '@actions/core';
|
const {
|
||||||
import got from 'got';
|
|
||||||
import {
|
|
||||||
exportSecrets,
|
exportSecrets,
|
||||||
parseSecretsInput,
|
parseSecretsInput,
|
||||||
parseHeadersInput
|
parseHeadersInput
|
||||||
} from './action.js';
|
} = require('./action');
|
||||||
|
|
||||||
import { when } from 'jest-when'
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
describe('parseSecretsInput', () => {
|
describe('parseSecretsInput', () => {
|
||||||
it('parses simple secret', () => {
|
it('parses simple secret', () => {
|
||||||
|
|
@ -132,7 +132,7 @@ describe('parseHeaders', () => {
|
||||||
|
|
||||||
describe('exportSecrets', () => {
|
describe('exportSecrets', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
|
||||||
10
src/auth.js
10
src/auth.js
|
|
@ -1,8 +1,8 @@
|
||||||
// @ts-check
|
// @ts-check
|
||||||
import core from '@actions/core';
|
const core = require('@actions/core');
|
||||||
import * as fs from 'fs';
|
const rsasign = require('jsrsasign');
|
||||||
import got from 'got';
|
const fs = require('fs');
|
||||||
import rsasign from 'jsrsasign';
|
const { default: got } = require('got');
|
||||||
|
|
||||||
const defaultKubernetesTokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token'
|
const defaultKubernetesTokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token'
|
||||||
/***
|
/***
|
||||||
|
|
@ -154,6 +154,6 @@ async function getClientToken(client, method, path, payload) {
|
||||||
* }} auth
|
* }} auth
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export {
|
module.exports = {
|
||||||
retrieveToken,
|
retrieveToken,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,22 @@
|
||||||
import { vi, describe, test, expect } from 'vitest';
|
jest.mock('got');
|
||||||
|
jest.mock('@actions/core');
|
||||||
vi.mock('got');
|
jest.mock('@actions/core/lib/command');
|
||||||
vi.mock('@actions/core');
|
jest.mock('fs', () => ({
|
||||||
vi.mock('fs', () => ({
|
stat: jest.fn().mockResolvedValue(null),
|
||||||
stat: vi.fn().mockResolvedValue(null),
|
|
||||||
promises: {
|
promises: {
|
||||||
access: vi.fn().mockResolvedValue(null),
|
access: jest.fn().mockResolvedValue(null),
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import core from '@actions/core';
|
const core = require('@actions/core');
|
||||||
import got from 'got'
|
const got = require('got');
|
||||||
import * as fs from 'fs';
|
const fs = require("fs")
|
||||||
import { when } from 'jest-when'
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
import { retrieveToken } from './auth.js';
|
|
||||||
|
const {
|
||||||
|
retrieveToken
|
||||||
|
} = require('./auth');
|
||||||
|
|
||||||
|
|
||||||
function mockInput(name, key) {
|
function mockInput(name, key) {
|
||||||
|
|
@ -25,7 +27,7 @@ function mockInput(name, key) {
|
||||||
|
|
||||||
function mockApiResponse() {
|
function mockApiResponse() {
|
||||||
const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } }
|
const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } }
|
||||||
got.post = vi.fn()
|
got.post = jest.fn()
|
||||||
got.post.mockReturnValue(response)
|
got.post.mockReturnValue(response)
|
||||||
}
|
}
|
||||||
const testToken = "testoken";
|
const testToken = "testoken";
|
||||||
|
|
@ -33,7 +35,7 @@ const testToken = "testoken";
|
||||||
describe("test retrival for token", () => {
|
describe("test retrival for token", () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test retrival with approle", async () => {
|
it("test retrival with approle", async () => {
|
||||||
|
|
@ -74,7 +76,7 @@ describe("test retrival for token", () => {
|
||||||
mockInput("kubernetesTokenPath", testTokenPath)
|
mockInput("kubernetesTokenPath", testTokenPath)
|
||||||
mockInput("role", testRole)
|
mockInput("role", testRole)
|
||||||
mockInput("path", testPath)
|
mockInput("path", testPath)
|
||||||
fs.readFileSync = vi.fn()
|
fs.readFileSync = jest.fn()
|
||||||
fs.readFileSync.mockReturnValueOnce(jwtToken)
|
fs.readFileSync.mockReturnValueOnce(jwtToken)
|
||||||
const token = await retrieveToken(method, got)
|
const token = await retrieveToken(method, got)
|
||||||
expect(token).toEqual(testToken)
|
expect(token).toEqual(testToken)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
// This allows us to use `require` in our ECMAScript module
|
|
||||||
// See: https://github.com/vercel/ncc/issues/791
|
|
||||||
// https://nodejs.org/api/module.html#modulecreaterequirefilename
|
|
||||||
import { createRequire } from "module";
|
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
|
|
||||||
export default require;
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const WILDCARD = '*';
|
const WILDCARD = '*';
|
||||||
|
|
||||||
export {
|
module.exports = {
|
||||||
WILDCARD
|
WILDCARD
|
||||||
};
|
};
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import core from '@actions/core';
|
const core = require('@actions/core');
|
||||||
import { exportSecrets } from './action.js';
|
const { exportSecrets } = require('./action');
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import auth from './auth.js';
|
const auth = require('./auth');
|
||||||
import secrets from './secrets.js';
|
const secrets = require('./secrets');
|
||||||
|
|
||||||
export default {
|
module.exports = {
|
||||||
auth,
|
auth,
|
||||||
secrets
|
secrets
|
||||||
};
|
};
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
import { vi, describe, test, expect } from 'vitest';
|
jest.mock('@actions/core');
|
||||||
|
|
||||||
vi.mock('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
const ServerMock = require("mock-http-server");
|
||||||
import core from '@actions/core';
|
const { exportSecrets } = require("./action");
|
||||||
import ServerMock from 'mock-http-server';
|
const { when } = require('jest-when');
|
||||||
import { exportSecrets } from './action.js';
|
|
||||||
import { when } from 'jest-when';
|
|
||||||
|
|
||||||
describe('exportSecrets retries', () => {
|
describe('exportSecrets retries', () => {
|
||||||
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
||||||
var calls = 0;
|
var calls = 0;
|
||||||
|
|
||||||
beforeEach(() => new Promise(done => {
|
beforeEach((done) => {
|
||||||
calls = 0;
|
calls = 0;
|
||||||
vi.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('token', expect.anything())
|
.calledWith('token', expect.anything())
|
||||||
|
|
@ -30,11 +28,11 @@ describe('exportSecrets retries', () => {
|
||||||
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
afterEach(() => new Promise(done => {
|
afterEach((done) => {
|
||||||
server.stop(done);
|
server.stop(done);
|
||||||
}));
|
});
|
||||||
|
|
||||||
function mockStatusCodes(statusCodes) {
|
function mockStatusCodes(statusCodes) {
|
||||||
server.on({
|
server.on({
|
||||||
|
|
@ -53,19 +51,19 @@ describe('exportSecrets retries', () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('retries on 412 status code', () => new Promise(done => {
|
it('retries on 412 status code', (done) => {
|
||||||
mockStatusCodes([412, 200])
|
mockStatusCodes([412, 200])
|
||||||
exportSecrets().then(() => {
|
exportSecrets().then(() => {
|
||||||
expect(calls).toEqual(2);
|
expect(calls).toEqual(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('retries on 500 status code', () => new Promise(done => {
|
it('retries on 500 status code', (done) => {
|
||||||
mockStatusCodes([500, 200])
|
mockStatusCodes([500, 200])
|
||||||
exportSecrets().then(() => {
|
exportSecrets().then(() => {
|
||||||
expect(calls).toEqual(2);
|
expect(calls).toEqual(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
import core from '@actions/core';
|
const jsonata = require("jsonata");
|
||||||
import { WILDCARD } from './constants.js';
|
const { WILDCARD } = require("./constants");
|
||||||
import { normalizeOutputKey } from './utils.js';
|
const { normalizeOutputKey } = require("./utils");
|
||||||
|
const core = require('@actions/core');
|
||||||
// ncc doesn't compile jsonata imports properly, so we must use our own custom require
|
|
||||||
import require from "./cjs-require.js";
|
|
||||||
const jsonata = require('jsonata');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} SecretRequest
|
* @typedef {Object} SecretRequest
|
||||||
|
|
@ -48,7 +44,7 @@ async function getSecrets(secretRequests, client, ignoreNotFound) {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const {response} = error;
|
const {response} = error;
|
||||||
if (response?.statusCode === 404) {
|
if (response?.statusCode === 404) {
|
||||||
let notFoundMsg = `Unable to retrieve result for "${path}" because it was not found: ${response.body.trim()}`;
|
notFoundMsg = `Unable to retrieve result for "${path}" because it was not found: ${response.body.trim()}`;
|
||||||
const ignoreNotFound = (core.getInput('ignoreNotFound', { required: false }) || 'false').toLowerCase() != 'false';
|
const ignoreNotFound = (core.getInput('ignoreNotFound', { required: false }) || 'false').toLowerCase() != 'false';
|
||||||
if (ignoreNotFound) {
|
if (ignoreNotFound) {
|
||||||
core.error(`✘ ${notFoundMsg}`);
|
core.error(`✘ ${notFoundMsg}`);
|
||||||
|
|
@ -169,7 +165,7 @@ const selectAndAppendResults = async (
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
module.exports = {
|
||||||
getSecrets,
|
getSecrets,
|
||||||
selectData
|
selectData
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,6 @@ function normalizeOutputKey(dataKey, isEnvVar = false) {
|
||||||
return outputKey;
|
return outputKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
module.exports = {
|
||||||
normalizeOutputKey
|
normalizeOutputKey
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,4 @@
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
import { defineConfig, configDefaults } from 'vitest/config'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
test: {
|
|
||||||
// required to make jest-when work with vitest
|
|
||||||
globals: true,
|
|
||||||
exclude:[
|
|
||||||
...configDefaults.exclude,
|
|
||||||
'**/integrationTests/**'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
})
|
|
||||||
Loading…
Reference in a new issue