mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-04-09 05:30:05 +00:00
feat: fix unit and add e2e test
This commit is contained in:
parent
0b17727b1c
commit
33ba690ebb
8 changed files with 180 additions and 97 deletions
|
|
@ -1,93 +1,7 @@
|
|||
jest.mock('@actions/core');
|
||||
const core = require('@actions/core');
|
||||
|
||||
const got = require('got');
|
||||
const { when } = require('jest-when');
|
||||
|
||||
const { exportSecrets } = require('../action');
|
||||
|
||||
describe('e2e', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
console.debug(`Testing against: http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret`)
|
||||
|
||||
// Verify Connection
|
||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/config`, {
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
});
|
||||
|
||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/test`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
body: {
|
||||
data: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
},
|
||||
},
|
||||
json: true,
|
||||
});
|
||||
|
||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/nested/test`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
body: {
|
||||
data: {
|
||||
e: 4,
|
||||
f: 5,
|
||||
g: 6,
|
||||
},
|
||||
},
|
||||
json: true,
|
||||
});
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('vaultUrl')
|
||||
.mockReturnValue(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`);
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('vaultToken')
|
||||
.mockReturnValue('testtoken');
|
||||
});
|
||||
|
||||
function mockInput(key) {
|
||||
when(core.getInput)
|
||||
.calledWith('keys')
|
||||
.mockReturnValue(key);
|
||||
}
|
||||
|
||||
it('get simple secret', async () => {
|
||||
mockInput('test a')
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportSecret).toBeCalledWith('A', 1);
|
||||
});
|
||||
|
||||
it('re-map secret', async () => {
|
||||
mockInput('test a | TEST_KEY')
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportSecret).toBeCalledWith('TEST_KEY', 1);
|
||||
});
|
||||
|
||||
it('get nested secret', async () => {
|
||||
mockInput('nested/test e')
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportSecret).toBeCalledWith('E', 4);
|
||||
it('verify', () => {
|
||||
expect(process.env.A).toBe("1");
|
||||
expect(process.env.NAMED_TOKEN).toBe("1");
|
||||
expect(process.env.E).toBe("4");
|
||||
});
|
||||
});
|
||||
45
e2e/setup.js
Normal file
45
e2e/setup.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
const got = require('got');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
// Verify Connection
|
||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/config`, {
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
});
|
||||
|
||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/test`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
body: {
|
||||
data: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
},
|
||||
},
|
||||
json: true,
|
||||
});
|
||||
|
||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/nested/test`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
body: {
|
||||
data: {
|
||||
e: 4,
|
||||
f: 5,
|
||||
g: 6,
|
||||
},
|
||||
},
|
||||
json: true,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue