mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-07 15:16:56 +00:00
Fix tests from jest-when version bump (#311)
* Fix tests from jest-when version bump * Delete unused test helpers * Add workflow_dispatch for tests
This commit is contained in:
parent
25737aea2b
commit
8e9712e63b
6 changed files with 40 additions and 51 deletions
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
|
|
@ -4,12 +4,13 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request_target:
|
pull_request_target:
|
||||||
types: [opened, reopened, synchronize]
|
types: [opened, reopened, synchronize]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
|
|
@ -109,17 +109,17 @@ describe('integration', () => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url')
|
.calledWith('url', expect.anything())
|
||||||
.mockReturnValueOnce(`${vaultUrl}`);
|
.mockReturnValueOnce(`${vaultUrl}`);
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('token')
|
.calledWith('token', expect.anything())
|
||||||
.mockReturnValueOnce('testtoken');
|
.mockReturnValueOnce('testtoken');
|
||||||
});
|
});
|
||||||
|
|
||||||
function mockInput(secrets) {
|
function mockInput(secrets) {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('secrets')
|
.calledWith('secrets', expect.anything())
|
||||||
.mockReturnValueOnce(secrets);
|
.mockReturnValueOnce(secrets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,23 +141,23 @@ describe('jwt auth', () => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url')
|
.calledWith('url', expect.anything())
|
||||||
.mockReturnValueOnce(`${vaultUrl}`);
|
.mockReturnValueOnce(`${vaultUrl}`);
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method')
|
.calledWith('method', expect.anything())
|
||||||
.mockReturnValueOnce('jwt');
|
.mockReturnValueOnce('jwt');
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('jwtPrivateKey')
|
.calledWith('jwtPrivateKey', expect.anything())
|
||||||
.mockReturnValueOnce(privateRsaKeyBase64);
|
.mockReturnValueOnce(privateRsaKeyBase64);
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('role')
|
.calledWith('role', expect.anything())
|
||||||
.mockReturnValueOnce('default');
|
.mockReturnValueOnce('default');
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('secrets')
|
.calledWith('secrets', expect.anything())
|
||||||
.mockReturnValueOnce('secret/data/test secret');
|
.mockReturnValueOnce('secret/data/test secret');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -191,29 +191,29 @@ describe('jwt auth', () => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url')
|
.calledWith('url', expect.anything())
|
||||||
.mockReturnValueOnce(`${vaultUrl}`);
|
.mockReturnValueOnce(`${vaultUrl}`);
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method')
|
.calledWith('method', expect.anything())
|
||||||
.mockReturnValueOnce('jwt');
|
.mockReturnValueOnce('jwt');
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('jwtPrivateKey')
|
.calledWith('jwtPrivateKey', expect.anything())
|
||||||
.mockReturnValueOnce('');
|
.mockReturnValueOnce('');
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('secrets')
|
.calledWith('secrets', expect.anything())
|
||||||
.mockReturnValueOnce('secret/data/test secret');
|
.mockReturnValueOnce('secret/data/test secret');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('successfully authenticates', async () => {
|
it('successfully authenticates', async () => {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('role')
|
.calledWith('role', expect.anything())
|
||||||
.mockReturnValueOnce('default');
|
.mockReturnValueOnce('default');
|
||||||
|
|
||||||
when(core.getIDToken)
|
when(core.getIDToken)
|
||||||
.calledWith()
|
.calledWith(undefined)
|
||||||
.mockReturnValueOnce(defaultGithubJwt);
|
.mockReturnValueOnce(defaultGithubJwt);
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
@ -222,15 +222,15 @@ describe('jwt auth', () => {
|
||||||
|
|
||||||
it('successfully authenticates with `jwtGithubAudience` set to `sigstore`', async () => {
|
it('successfully authenticates with `jwtGithubAudience` set to `sigstore`', async () => {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('role')
|
.calledWith('role', expect.anything())
|
||||||
.mockReturnValueOnce('default-sigstore');
|
.mockReturnValueOnce('default-sigstore');
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('jwtGithubAudience')
|
.calledWith('jwtGithubAudience', expect.anything())
|
||||||
.mockReturnValueOnce('sigstore');
|
.mockReturnValueOnce('sigstore');
|
||||||
|
|
||||||
when(core.getIDToken)
|
when(core.getIDToken)
|
||||||
.calledWith()
|
.calledWith(expect.anything())
|
||||||
.mockReturnValueOnce(mockGithubOIDCResponse('sigstore'));
|
.mockReturnValueOnce(mockGithubOIDCResponse('sigstore'));
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
@ -239,11 +239,11 @@ describe('jwt auth', () => {
|
||||||
|
|
||||||
it('successfully authenticates as default role without specifying it', async () => {
|
it('successfully authenticates as default role without specifying it', async () => {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('role')
|
.calledWith('role', expect.anything())
|
||||||
.mockReturnValueOnce(null);
|
.mockReturnValueOnce(null);
|
||||||
|
|
||||||
when(core.getIDToken)
|
when(core.getIDToken)
|
||||||
.calledWith()
|
.calledWith(undefined)
|
||||||
.mockReturnValueOnce(defaultGithubJwt);
|
.mockReturnValueOnce(defaultGithubJwt);
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
|
||||||
|
|
@ -43,15 +43,15 @@ describe('integration', () => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url')
|
.calledWith('url', expect.anything())
|
||||||
.mockReturnValueOnce(`${vaultUrl}`);
|
.mockReturnValueOnce(`${vaultUrl}`);
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('token')
|
.calledWith('token', expect.anything())
|
||||||
.mockReturnValueOnce('testtoken');
|
.mockReturnValueOnce('testtoken');
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('namespace')
|
.calledWith('namespace', expect.anything())
|
||||||
.mockReturnValueOnce('ns1');
|
.mockReturnValueOnce('ns1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -211,16 +211,16 @@ describe('authenticate with approle', () => {
|
||||||
.calledWith('method', expect.anything())
|
.calledWith('method', expect.anything())
|
||||||
.mockReturnValueOnce('approle');
|
.mockReturnValueOnce('approle');
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('roleId')
|
.calledWith('roleId', expect.anything())
|
||||||
.mockReturnValueOnce(roleId);
|
.mockReturnValueOnce(roleId);
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('secretId')
|
.calledWith('secretId', expect.anything())
|
||||||
.mockReturnValueOnce(secretId);
|
.mockReturnValueOnce(secretId);
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url')
|
.calledWith('url', expect.anything())
|
||||||
.mockReturnValueOnce(`${vaultUrl}`);
|
.mockReturnValueOnce(`${vaultUrl}`);
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('namespace')
|
.calledWith('namespace', expect.anything())
|
||||||
.mockReturnValueOnce('ns2');
|
.mockReturnValueOnce('ns2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -286,18 +286,6 @@ async function writeSecret(engine, path, namespace, version, data) {
|
||||||
|
|
||||||
function mockInput(secrets) {
|
function mockInput(secrets) {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('secrets')
|
.calledWith('secrets', expect.anything())
|
||||||
.mockReturnValueOnce(secrets);
|
.mockReturnValueOnce(secrets);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mockEngineName(name) {
|
|
||||||
when(core.getInput)
|
|
||||||
.calledWith('path')
|
|
||||||
.mockReturnValueOnce(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function mockVersion(version) {
|
|
||||||
when(core.getInput)
|
|
||||||
.calledWith('kv-version')
|
|
||||||
.mockReturnValueOnce(version);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ describe('parseSecretsInput', () => {
|
||||||
describe('parseHeaders', () => {
|
describe('parseHeaders', () => {
|
||||||
it('parses simple header', () => {
|
it('parses simple header', () => {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('extraHeaders')
|
.calledWith('extraHeaders', undefined)
|
||||||
.mockReturnValueOnce('TEST: 1');
|
.mockReturnValueOnce('TEST: 1');
|
||||||
const result = parseHeadersInput('extraHeaders');
|
const result = parseHeadersInput('extraHeaders');
|
||||||
expect(Array.from(result)).toContainEqual(['test', '1']);
|
expect(Array.from(result)).toContainEqual(['test', '1']);
|
||||||
|
|
@ -102,7 +102,7 @@ describe('parseHeaders', () => {
|
||||||
|
|
||||||
it('parses simple header with whitespace', () => {
|
it('parses simple header with whitespace', () => {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('extraHeaders')
|
.calledWith('extraHeaders', undefined)
|
||||||
.mockReturnValueOnce(`
|
.mockReturnValueOnce(`
|
||||||
TEST: 1
|
TEST: 1
|
||||||
`);
|
`);
|
||||||
|
|
@ -112,7 +112,7 @@ describe('parseHeaders', () => {
|
||||||
|
|
||||||
it('parses multiple headers', () => {
|
it('parses multiple headers', () => {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('extraHeaders')
|
.calledWith('extraHeaders', undefined)
|
||||||
.mockReturnValueOnce(`
|
.mockReturnValueOnce(`
|
||||||
TEST: 1
|
TEST: 1
|
||||||
FOO: bAr
|
FOO: bAr
|
||||||
|
|
@ -124,7 +124,7 @@ describe('parseHeaders', () => {
|
||||||
|
|
||||||
it('parses null response', () => {
|
it('parses null response', () => {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('extraHeaders')
|
.calledWith('extraHeaders', undefined)
|
||||||
.mockReturnValueOnce(null);
|
.mockReturnValueOnce(null);
|
||||||
const result = parseHeadersInput('extraHeaders');
|
const result = parseHeadersInput('extraHeaders');
|
||||||
expect(Array.from(result)).toHaveLength(0);
|
expect(Array.from(result)).toHaveLength(0);
|
||||||
|
|
@ -136,29 +136,29 @@ describe('exportSecrets', () => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url')
|
.calledWith('url', expect.anything())
|
||||||
.mockReturnValueOnce('http://vault:8200');
|
.mockReturnValueOnce('http://vault:8200');
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('token')
|
.calledWith('token', expect.anything())
|
||||||
.mockReturnValueOnce('EXAMPLE');
|
.mockReturnValueOnce('EXAMPLE');
|
||||||
});
|
});
|
||||||
|
|
||||||
function mockInput(key) {
|
function mockInput(key) {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('secrets')
|
.calledWith('secrets', expect.anything())
|
||||||
.mockReturnValueOnce(key);
|
.mockReturnValueOnce(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mockVersion(version) {
|
function mockVersion(version) {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('kv-version')
|
.calledWith('kv-version', expect.anything())
|
||||||
.mockReturnValueOnce(version);
|
.mockReturnValueOnce(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mockExtraHeaders(headerString) {
|
function mockExtraHeaders(headerString) {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('extraHeaders')
|
.calledWith('extraHeaders', expect.anything())
|
||||||
.mockReturnValueOnce(headerString);
|
.mockReturnValueOnce(headerString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,7 +181,7 @@ describe('exportSecrets', () => {
|
||||||
|
|
||||||
function mockExportToken(doExport) {
|
function mockExportToken(doExport) {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('exportToken')
|
.calledWith('exportToken', expect.anything())
|
||||||
.mockReturnValueOnce(doExport);
|
.mockReturnValueOnce(doExport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ const {
|
||||||
|
|
||||||
function mockInput(name, key) {
|
function mockInput(name, key) {
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith(name)
|
.calledWith(name, expect.anything())
|
||||||
.mockReturnValueOnce(key);
|
.mockReturnValueOnce(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue