mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-07 07:06:56 +00:00
fix(tests): fix unit tests and improve e2e
This commit is contained in:
parent
3dfe7ff808
commit
5357098084
3 changed files with 19 additions and 6 deletions
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
|
|
@ -112,6 +112,7 @@ jobs:
|
||||||
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
||||||
- name: use vault action (default K/V version 2)
|
- name: use vault action (default K/V version 2)
|
||||||
uses: ./
|
uses: ./
|
||||||
|
id: kv-secrets
|
||||||
with:
|
with:
|
||||||
url: http://localhost:${{ job.services.vault.ports[8200] }}
|
url: http://localhost:${{ job.services.vault.ports[8200] }}
|
||||||
token: testtoken
|
token: testtoken
|
||||||
|
|
@ -140,6 +141,8 @@ jobs:
|
||||||
/cubbyhole/test zip | NAMED_CUBBYSECRET ;
|
/cubbyhole/test zip | NAMED_CUBBYSECRET ;
|
||||||
- name: verify
|
- name: verify
|
||||||
run: npm run test:e2e
|
run: npm run test:e2e
|
||||||
|
env:
|
||||||
|
OTHER_SECRET_OUTPUT: ${{ job.kv-secrets.outputs.otherSecret }}
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
if: github.event_name == 'push' && contains(github.ref, 'master')
|
if: github.event_name == 'push' && contains(github.ref, 'master')
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ describe('parseSecretsInput', () => {
|
||||||
expect(output).toContainEqual({
|
expect(output).toContainEqual({
|
||||||
secretPath: 'test',
|
secretPath: 'test',
|
||||||
secretSelector: 'key',
|
secretSelector: 'key',
|
||||||
outputName: 'KEY',
|
outputVarName: 'key',
|
||||||
|
envVarName: 'KEY',
|
||||||
isJSONPath: false
|
isJSONPath: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -27,7 +28,8 @@ describe('parseSecretsInput', () => {
|
||||||
const output = parseSecretsInput('test key|testName');
|
const output = parseSecretsInput('test key|testName');
|
||||||
expect(output).toHaveLength(1);
|
expect(output).toHaveLength(1);
|
||||||
expect(output[0]).toMatchObject({
|
expect(output[0]).toMatchObject({
|
||||||
outputName: 'testName',
|
outputVarName: 'testName',
|
||||||
|
envVarName: 'testName',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -58,10 +60,12 @@ describe('parseSecretsInput', () => {
|
||||||
|
|
||||||
expect(output).toHaveLength(2);
|
expect(output).toHaveLength(2);
|
||||||
expect(output[0]).toMatchObject({
|
expect(output[0]).toMatchObject({
|
||||||
outputName: 'A',
|
outputVarName: 'a',
|
||||||
|
envVarName: 'A',
|
||||||
});
|
});
|
||||||
expect(output[1]).toMatchObject({
|
expect(output[1]).toMatchObject({
|
||||||
outputName: 'secondName',
|
outputVarName: 'secondName',
|
||||||
|
envVarName: 'secondName'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -76,10 +80,12 @@ describe('parseSecretsInput', () => {
|
||||||
secretPath: 'first',
|
secretPath: 'first',
|
||||||
});
|
});
|
||||||
expect(output[1]).toMatchObject({
|
expect(output[1]).toMatchObject({
|
||||||
outputName: 'B',
|
outputVarName: 'b',
|
||||||
|
envVarName: 'B'
|
||||||
});
|
});
|
||||||
expect(output[2]).toMatchObject({
|
expect(output[2]).toMatchObject({
|
||||||
outputName: 'SOME_C',
|
outputVarName: 'SOME_C',
|
||||||
|
envVarName: 'SOME_C',
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
@ -172,6 +178,7 @@ describe('exportSecrets', () => {
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
expect(core.exportVariable).toBeCalledWith('KEY', '1');
|
expect(core.exportVariable).toBeCalledWith('KEY', '1');
|
||||||
|
expect(core.setOutput).toBeCalledWith('key', '1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('mapped secret retrieval', async () => {
|
it('mapped secret retrieval', async () => {
|
||||||
|
|
@ -183,6 +190,7 @@ describe('exportSecrets', () => {
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
expect(core.exportVariable).toBeCalledWith('TEST_NAME', '1');
|
expect(core.exportVariable).toBeCalledWith('TEST_NAME', '1');
|
||||||
|
expect(core.setOutput).toBeCalledWith('TEST_NAME', '1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('simple secret retrieval from K/V v1', async () => {
|
it('simple secret retrieval from K/V v1', async () => {
|
||||||
|
|
@ -197,5 +205,6 @@ describe('exportSecrets', () => {
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
expect(core.exportVariable).toBeCalledWith('KEY', '1');
|
expect(core.exportVariable).toBeCalledWith('KEY', '1');
|
||||||
|
expect(core.setOutput).toBeCalledWith('key', '1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ describe('e2e', () => {
|
||||||
expect(process.env.SECRET).toBe("SUPERSECRET");
|
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||||
expect(process.env.NAMED_SECRET).toBe("SUPERSECRET");
|
expect(process.env.NAMED_SECRET).toBe("SUPERSECRET");
|
||||||
expect(process.env.OTHERSECRET).toBe("OTHERSUPERSECRET");
|
expect(process.env.OTHERSECRET).toBe("OTHERSUPERSECRET");
|
||||||
|
expect(process.env.OTHER_SECRET_OUTPUT).toBe("OTHERSUPERSECRET");
|
||||||
expect(process.env.ALTSECRET).toBe("CUSTOMSECRET");
|
expect(process.env.ALTSECRET).toBe("CUSTOMSECRET");
|
||||||
expect(process.env.NAMED_ALTSECRET).toBe("CUSTOMSECRET");
|
expect(process.env.NAMED_ALTSECRET).toBe("CUSTOMSECRET");
|
||||||
expect(process.env.OTHERALTSECRET).toBe("OTHERCUSTOMSECRET");
|
expect(process.env.OTHERALTSECRET).toBe("OTHERCUSTOMSECRET");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue