From 44e1f881f29afefb0c506f8f427f3e18c14f1e23 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Wed, 5 Feb 2020 15:00:31 -0600 Subject: [PATCH] add tests for custom engines --- .github/workflows/build.yml | 8 +++++ action.js | 1 + integrationTests/basic/integration.test.js | 36 ++++++++++++++++++++++ integrationTests/e2e/e2e.test.js | 2 ++ integrationTests/e2e/setup.js | 11 +++++++ 5 files changed, 58 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 163fee9..9938ba8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -130,6 +130,14 @@ jobs: test altSecret ; test altSecret | NAMED_ALTSECRET ; nested/test otherAltSecret ; + - name: use vault action (using cubbyhole engine) + uses: ./ + with: + url: http://localhost:${{ job.services.vault.ports[8200] }} + token: testtoken + secrets: | + /cubbyhole/test foo ; + /cubbyhole/test zip | NAMED_CUBBYSECRET ; - name: verify run: npm run test:e2e diff --git a/action.js b/action.js index a87b325..cc36793 100644 --- a/action.js +++ b/action.js @@ -88,6 +88,7 @@ async function exportSecrets() { let body; if (responseCache.has(requestPath)) { body = responseCache.get(requestPath); + core.debug('ℹ using cached response'); } else { const result = await got(requestPath, requestOptions); body = result.body; diff --git a/integrationTests/basic/integration.test.js b/integrationTests/basic/integration.test.js index 22b52d6..00c601a 100644 --- a/integrationTests/basic/integration.test.js +++ b/integrationTests/basic/integration.test.js @@ -171,4 +171,40 @@ describe('integration', () => { expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERCUSTOMSECRET'); }); + + describe('generic engines', () => { + beforeAll(async () => { + await got(`${vaultUrl}/v1/cubbyhole/test`, { + method: 'POST', + headers: { + 'X-Vault-Token': 'testtoken', + }, + json: { + foo: "bar", + zip: "zap" + }, + }); + }); + + it('supports cubbyhole', async () => { + mockInput('/cubbyhole/test foo'); + + await exportSecrets(); + + expect(core.exportVariable).toBeCalledWith('FOO', 'bar'); + }); + + it('caches responses', async () => { + mockInput(` + /cubbyhole/test foo ; + /cubbyhole/test zip`); + + await exportSecrets(); + + expect(core.debug).toBeCalledWith('ℹ using cached response'); + + expect(core.exportVariable).toBeCalledWith('FOO', 'bar'); + expect(core.exportVariable).toBeCalledWith('ZIP', 'zap'); + }); + }) }); diff --git a/integrationTests/e2e/e2e.test.js b/integrationTests/e2e/e2e.test.js index bfa4987..56421ba 100644 --- a/integrationTests/e2e/e2e.test.js +++ b/integrationTests/e2e/e2e.test.js @@ -6,5 +6,7 @@ describe('e2e', () => { expect(process.env.ALTSECRET).toBe("CUSTOMSECRET"); expect(process.env.NAMED_ALTSECRET).toBe("CUSTOMSECRET"); expect(process.env.OTHERALTSECRET).toBe("OTHERCUSTOMSECRET"); + expect(process.env.FOO).toBe("bar"); + expect(process.env.NAMED_CUBBYSECRET).toBe("zap"); }); }); diff --git a/integrationTests/e2e/setup.js b/integrationTests/e2e/setup.js index 1cc73e2..13625dc 100644 --- a/integrationTests/e2e/setup.js +++ b/integrationTests/e2e/setup.js @@ -64,6 +64,17 @@ const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`; otherAltSecret: 'OTHERCUSTOMSECRET', }, }); + + await got(`http://${vaultUrl}/v1/cubbyhole/test`, { + method: 'POST', + headers: { + 'X-Vault-Token': 'testtoken', + }, + json: { + foo: 'bar', + zip: 'zap', + }, + }); } catch (error) { console.log(error); process.exit(1);