From 42a9c06aa7a4a313406ec8579f28d08ce22b92eb Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Tue, 14 Jan 2020 20:41:52 -0600 Subject: [PATCH] chore(test): fix integration tests --- action.js | 3 +- dist/index.js | 7 +- integrationTests/basic/integration.test.js | 6 +- .../enterprise/enterprise.test.js | 109 +++++++++--------- 4 files changed, 64 insertions(+), 61 deletions(-) diff --git a/action.js b/action.js index 56cc633..4df8ce2 100644 --- a/action.js +++ b/action.js @@ -57,7 +57,8 @@ async function exportSecrets() { const requestOptions = { headers: { 'X-Vault-Token': vaultToken - }}; + }, + }; if (vaultNamespace != null) { requestOptions.headers["X-Vault-Namespace"] = vaultNamespace; diff --git a/dist/index.js b/dist/index.js index 1883a47..ccc7a31 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4120,10 +4120,11 @@ async function exportSecrets() { const requestOptions = { headers: { 'X-Vault-Token': vaultToken - }}; + }, + }; - if (vaultNamespace != null){ - requestOptions.headers["X-Vault-Namespace"] = vaultNamespace + if (vaultNamespace != null) { + requestOptions.headers["X-Vault-Namespace"] = vaultNamespace; } const result = await got(`${vaultUrl}/v1/secret/data/${secretPath}`, requestOptions); diff --git a/integrationTests/basic/integration.test.js b/integrationTests/basic/integration.test.js index d440a2b..70f9ce1 100644 --- a/integrationTests/basic/integration.test.js +++ b/integrationTests/basic/integration.test.js @@ -23,12 +23,11 @@ describe('integration', () => { headers: { 'X-Vault-Token': 'testtoken', }, - body: { + json: { data: { secret: 'SUPERSECRET', }, }, - json: true, }); await got(`${vaultUrl}/v1/secret/data/nested/test`, { @@ -36,12 +35,11 @@ describe('integration', () => { headers: { 'X-Vault-Token': 'testtoken', }, - body: { + json: { data: { otherSecret: 'OTHERSUPERSECRET', }, }, - json: true, }); }); diff --git a/integrationTests/enterprise/enterprise.test.js b/integrationTests/enterprise/enterprise.test.js index cc0ae97..9c69d08 100644 --- a/integrationTests/enterprise/enterprise.test.js +++ b/integrationTests/enterprise/enterprise.test.js @@ -11,57 +11,61 @@ const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env. describe('integration', () => { beforeAll(async () => { - // Verify Connection - await got(`${vaultUrl}/v1/secret/config`, { - headers: { - 'X-Vault-Token': 'testtoken', - }, - }); - - // Create namespace - await got(`${vaultUrl}/v1/sys/namespaces/ns1`, { - method: 'POST', - headers: { - 'X-Vault-Token': 'testtoken', - }, - json: true, - }); - - // Enable secret engine - await got(`${vaultUrl}/v1/sys/mounts/secret`, { - method: 'POST', - headers: { - 'X-Vault-Token': 'testtoken', - 'X-Vault-Namespace': 'ns1', - }, - json: { path: 'secret', type: 'kv', config: {}, options: { version: 2 }, generate_signing_key: true }, - }); - - await got(`${vaultUrl}/v1/secret/data/test`, { - method: 'POST', - headers: { - 'X-Vault-Token': 'testtoken', - 'X-Vault-Namespace': 'ns1', - }, - json: { - data: { - secret: 'SUPERSECRET_IN_NAMESPACE', + try { + // Verify Connection + await got(`${vaultUrl}/v1/secret/config`, { + headers: { + 'X-Vault-Token': 'testtoken', }, - }, - }); + }); - await got(`${vaultUrl}/v1/secret/data/nested/test`, { - method: 'POST', - headers: { - 'X-Vault-Token': 'testtoken', - 'X-Vault-Namespace': 'ns1', - }, - json: { - data: { - otherSecret: 'OTHERSUPERSECRET_IN_NAMESPACE', + // Create namespace + await got(`${vaultUrl}/v1/sys/namespaces/ns1`, { + method: 'POST', + headers: { + 'X-Vault-Token': 'testtoken', + } + }); + + // Enable secret engine + await got(`${vaultUrl}/v1/sys/mounts/secret`, { + method: 'POST', + headers: { + 'X-Vault-Token': 'testtoken', + 'X-Vault-Namespace': 'ns1', }, - }, - }); + json: { path: 'secret', type: 'kv', config: {}, options: { version: 2 }, generate_signing_key: true }, + }); + + await got(`${vaultUrl}/v1/secret/data/test`, { + method: 'POST', + headers: { + 'X-Vault-Token': 'testtoken', + 'X-Vault-Namespace': 'ns1', + }, + json: { + data: { + secret: 'SUPERSECRET_IN_NAMESPACE', + }, + }, + }); + + await got(`${vaultUrl}/v1/secret/data/nested/test`, { + method: 'POST', + headers: { + 'X-Vault-Token': 'testtoken', + 'X-Vault-Namespace': 'ns1', + }, + json: { + data: { + otherSecret: 'OTHERSUPERSECRET_IN_NAMESPACE', + }, + }, + }); + } catch (e) { + console.error('Failed to setup test', e); + throw e; + } }); beforeEach(() => { @@ -144,7 +148,6 @@ describe('authenticate with approle', () => { headers: { 'X-Vault-Token': 'testtoken', }, - json: true, }); // Enable secret engine @@ -214,7 +217,7 @@ describe('authenticate with approle', () => { 'X-Vault-Token': 'testtoken', 'X-Vault-Namespace': 'ns2', }, - json: true, + responseType: 'json', }); roleId = roldIdResponse.body.data.role_id; @@ -225,12 +228,12 @@ describe('authenticate with approle', () => { 'X-Vault-Token': 'testtoken', 'X-Vault-Namespace': 'ns2', }, - json: true, + responseType: 'json', }); secretId = secretIdResponse.body.data.secret_id; } catch(err) { - console.warn('Create approle',err); - throw err + console.warn('Create approle', err); + throw err; } });