mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-04-08 21:20:07 +00:00
feat: support for KV version 1 and custom-named engines (#12)
* feat: kv v1 and engine path * doc: add custom version and engine path usage docs Co-authored-by: Richard Simpson <richardsimpson@outlook.com>
This commit is contained in:
parent
3b9239de79
commit
f229481670
9 changed files with 465 additions and 139 deletions
|
|
@ -39,6 +39,46 @@ describe('integration', () => {
|
|||
data: {
|
||||
otherSecret: 'OTHERSUPERSECRET',
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
// Enable custom secret engine
|
||||
try {
|
||||
await got(`${vaultUrl}/v1/sys/mounts/my-secret`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
json: {
|
||||
type: 'kv'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
const {response} = error;
|
||||
if (response.statusCode === 400 && response.body.includes("path is already in use")) {
|
||||
// Engine might already be enabled from previous test runs
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
await got(`${vaultUrl}/v1/my-secret/test`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
json: {
|
||||
secret: 'CUSTOMSECRET',
|
||||
}
|
||||
});
|
||||
|
||||
await got(`${vaultUrl}/v1/my-secret/nested/test`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
json: {
|
||||
otherSecret: 'OTHERCUSTOMSECRET',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -48,17 +88,29 @@ describe('integration', () => {
|
|||
|
||||
when(core.getInput)
|
||||
.calledWith('url')
|
||||
.mockReturnValue(`${vaultUrl}`);
|
||||
.mockReturnValueOnce(`${vaultUrl}`);
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('token')
|
||||
.mockReturnValue('testtoken');
|
||||
.mockReturnValueOnce('testtoken');
|
||||
});
|
||||
|
||||
function mockInput(secrets) {
|
||||
when(core.getInput)
|
||||
.calledWith('secrets')
|
||||
.mockReturnValue(secrets);
|
||||
.mockReturnValueOnce(secrets);
|
||||
}
|
||||
|
||||
function mockEngineName(name) {
|
||||
when(core.getInput)
|
||||
.calledWith('path')
|
||||
.mockReturnValueOnce(name);
|
||||
}
|
||||
|
||||
function mockVersion(version) {
|
||||
when(core.getInput)
|
||||
.calledWith('kv-version')
|
||||
.mockReturnValueOnce(version);
|
||||
}
|
||||
|
||||
it('get simple secret', async () => {
|
||||
|
|
@ -99,4 +151,24 @@ describe('integration', () => {
|
|||
expect(core.exportVariable).toBeCalledWith('NAMED_SECRET', 'SUPERSECRET');
|
||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET');
|
||||
});
|
||||
|
||||
it('get secret from K/V v1', async () => {
|
||||
mockInput('test secret');
|
||||
mockEngineName('my-secret');
|
||||
mockVersion('1');
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportVariable).toBeCalledWith('SECRET', 'CUSTOMSECRET');
|
||||
});
|
||||
|
||||
it('get nested secret from K/V v1', async () => {
|
||||
mockInput('nested/test otherSecret');
|
||||
mockEngineName('my-secret');
|
||||
mockVersion('1');
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERCUSTOMSECRET');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue