5
0
Fork 0
mirror of https://github.com/hashicorp/vault-action.git synced 2025-11-08 15:46:56 +00:00

chore(test): fix integration tests

This commit is contained in:
Richard Simpson 2020-01-14 20:41:52 -06:00
parent 3d4cea598b
commit 42a9c06aa7
4 changed files with 64 additions and 61 deletions

View file

@ -57,7 +57,8 @@ async function exportSecrets() {
const requestOptions = {
headers: {
'X-Vault-Token': vaultToken
}};
},
};
if (vaultNamespace != null) {
requestOptions.headers["X-Vault-Namespace"] = vaultNamespace;

7
dist/index.js vendored
View file

@ -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);

View file

@ -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,
});
});

View file

@ -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;
}
});