diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 612f183..0f4bc88 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,8 +20,7 @@ jobs: env: CI: true - e2e: - + integration: runs-on: ubuntu-latest services: @@ -41,9 +40,38 @@ jobs: node-version: 10.x - name: npm install run: npm ci - - name: npm run test:e2e - run: npm run test:e2e + - name: npm run test:integration + run: npm run test:integration env: VAULT_HOST: localhost VAULT_PORT: ${{ job.services.vault.ports[8200] }} + e2e: + runs-on: ubuntu-latest + + services: + vault: + image: vault:1.2.3 + ports: + - 8200/tcp + env: + VAULT_DEV_ROOT_TOKEN_ID: testtoken + options: --cap-add=IPC_LOCK + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js 10.x + uses: actions/setup-node@v1 + with: + node-version: 10.x + - name: npm install + run: npm ci + - name: setup vault + run: node ./e2e/setup.js + - name: use vault actions + uses: ./ + - name: verify + run: npm run test:e2e + + + diff --git a/action.test.js b/action.test.js index 4c916ba..263302d 100644 --- a/action.test.js +++ b/action.test.js @@ -89,8 +89,9 @@ describe('exportSecrets', () => { function mockVaultData(data) { got.mockResolvedValue({ body: JSON.stringify({ - data, - meta: {} + data: { + data + } }) }); } diff --git a/e2e/e2e.test.js b/e2e/e2e.test.js index c2d5976..d0bd673 100644 --- a/e2e/e2e.test.js +++ b/e2e/e2e.test.js @@ -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"); }); }); \ No newline at end of file diff --git a/e2e/setup.js b/e2e/setup.js new file mode 100644 index 0000000..c6a01cd --- /dev/null +++ b/e2e/setup.js @@ -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); + } +})(); \ No newline at end of file diff --git a/integration/integration.test.js b/integration/integration.test.js new file mode 100644 index 0000000..80a266b --- /dev/null +++ b/integration/integration.test.js @@ -0,0 +1,91 @@ +jest.mock('@actions/core'); +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', + }, + }); + + 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); + }); +}); \ No newline at end of file diff --git a/integration/jest.config.js b/integration/jest.config.js new file mode 100644 index 0000000..03d15be --- /dev/null +++ b/integration/jest.config.js @@ -0,0 +1,3 @@ +module.exports = { + verbose: true +}; diff --git a/jest.config.js b/jest.config.js index 6cd1ce3..2355f35 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,3 @@ module.exports = { - testPathIgnorePatterns: ['/node_modules/', '/e2e/'], + testPathIgnorePatterns: ['/node_modules/', '/integration/', '/e2e/'], }; diff --git a/package.json b/package.json index c83724a..d847aaa 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "index.js", "scripts": { "test": "jest", + "test:integration": "jest -c integration/jest.config.js", "test:e2e": "jest -c e2e/jest.config.js" }, "repository": {