-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(namespace): handle request on vault namespace (#5)
* feat(namespace): handle request on vault namespace
- Loading branch information
1 parent
0104a02
commit 3747195
Showing
9 changed files
with
214 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Start vault server locally | ||
# You can run integration tests against server by running | ||
# `VAULT_HOST=localhost VAULT_PORT=8200 CI=true npm run test:integration-ent` | ||
version: "3.0" | ||
services: | ||
vault: | ||
image: hashicorp/vault-enterprise:1.3.0_ent | ||
environment: | ||
VAULT_DEV_ROOT_TOKEN_ID: testtoken | ||
ports: | ||
- 8200:8200 | ||
privileged: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
jest.mock('@actions/core'); | ||
jest.mock('@actions/core/lib/command'); | ||
const core = require('@actions/core'); | ||
|
||
const got = require('got'); | ||
const { when } = require('jest-when'); | ||
|
||
const { exportSecrets } = require('../action'); | ||
|
||
describe('integration', () => { | ||
|
||
beforeAll(async () => { | ||
// Verify Connection | ||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/config`, { | ||
headers: { | ||
'X-Vault-Token': 'testtoken', | ||
}, | ||
}); | ||
|
||
// Create namespace | ||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/sys/namespaces/ns1`, { | ||
method: 'POST', | ||
headers: { | ||
'X-Vault-Token': 'testtoken', | ||
}, | ||
json: true, | ||
}); | ||
|
||
// Enable secret engine | ||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/sys/mounts/secret`, { | ||
method: 'POST', | ||
headers: { | ||
'X-Vault-Token': 'testtoken', | ||
'X-Vault-Namespace': 'ns1', | ||
}, | ||
body: {"path":"secret","type":"kv","config":{},"options":{"version":2},"generate_signing_key":true}, | ||
json: true, | ||
}); | ||
|
||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/test`, { | ||
method: 'POST', | ||
headers: { | ||
'X-Vault-Token': 'testtoken', | ||
'X-Vault-Namespace': 'ns1', | ||
}, | ||
body: { | ||
data: { | ||
secret: "SUPERSECRET_IN_NAMESPACE", | ||
}, | ||
}, | ||
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', | ||
'X-Vault-Namespace': 'ns1', | ||
}, | ||
body: { | ||
data: { | ||
otherSecret: "OTHERSUPERSECRET_IN_NAMESPACE", | ||
}, | ||
}, | ||
json: true, | ||
}); | ||
|
||
|
||
|
||
}) | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
|
||
when(core.getInput) | ||
.calledWith('url') | ||
.mockReturnValue(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`); | ||
|
||
when(core.getInput) | ||
.calledWith('token') | ||
.mockReturnValue('testtoken'); | ||
|
||
when(core.getInput) | ||
.calledWith('namespace') | ||
.mockReturnValue('ns1'); | ||
}); | ||
|
||
function mockInput(secrets) { | ||
when(core.getInput) | ||
.calledWith('secrets') | ||
.mockReturnValue(secrets); | ||
} | ||
|
||
it('get simple secret', async () => { | ||
mockInput('test secret') | ||
|
||
await exportSecrets(); | ||
|
||
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET_IN_NAMESPACE'); | ||
}); | ||
|
||
it('re-map secret', async () => { | ||
mockInput('test secret | TEST_KEY') | ||
|
||
await exportSecrets(); | ||
|
||
expect(core.exportVariable).toBeCalledWith('TEST_KEY', 'SUPERSECRET_IN_NAMESPACE'); | ||
}); | ||
|
||
it('get nested secret', async () => { | ||
mockInput('nested/test otherSecret') | ||
|
||
await exportSecrets(); | ||
|
||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET_IN_NAMESPACE'); | ||
}); | ||
|
||
it('get multiple secrets', async () => { | ||
mockInput(` | ||
test secret ; | ||
test secret | NAMED_SECRET ; | ||
nested/test otherSecret ;`); | ||
|
||
await exportSecrets(); | ||
|
||
expect(core.exportVariable).toBeCalledTimes(3); | ||
|
||
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET_IN_NAMESPACE'); | ||
expect(core.exportVariable).toBeCalledWith('NAMED_SECRET', 'SUPERSECRET_IN_NAMESPACE'); | ||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET_IN_NAMESPACE'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
verbose: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integration/', '<rootDir>/e2e/'], | ||
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integration/', '<rootDir>/e2e/','<rootDir>/integration-ent'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters