Skip to content

Commit

Permalink
Replace PKI test suites custom runCommands with vault tools runCmd (#…
Browse files Browse the repository at this point in the history
…25226)

* replace runCommand custom for PKI to vault tools runCmd

* remove duplicate policy command
  • Loading branch information
Monkeychip committed Feb 6, 2024
1 parent edf4caa commit 2f05a36
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 72 deletions.
4 changes: 2 additions & 2 deletions ui/tests/acceptance/pki/pki-action-forms-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { v4 as uuidv4 } from 'uuid';
import authPage from 'vault/tests/pages/auth';
import logout from 'vault/tests/pages/logout';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { runCommands } from 'vault/tests/helpers/pki/pki-run-commands';
import { runCmd } from 'vault/tests/helpers/commands';
import { SELECTORS as S } from 'vault/tests/helpers/pki/workflow';
import { issuerPemBundle } from 'vault/tests/helpers/pki/values';

Expand All @@ -32,7 +32,7 @@ module('Acceptance | pki action forms test', function (hooks) {
await logout.visit();
await authPage.login();
// Cleanup engine
await runCommands([`delete sys/mounts/${this.mountPath}`]);
await runCmd([`delete sys/mounts/${this.mountPath}`]);
});

module('import', function (hooks) {
Expand Down
8 changes: 4 additions & 4 deletions ui/tests/acceptance/pki/pki-configuration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { v4 as uuidv4 } from 'uuid';
import authPage from 'vault/tests/pages/auth';
import logout from 'vault/tests/pages/logout';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { runCommands } from 'vault/tests/helpers/pki/pki-run-commands';
import { runCmd } from 'vault/tests/helpers/commands';
import { SELECTORS } from 'vault/tests/helpers/pki/workflow';
import { issuerPemBundle } from 'vault/tests/helpers/pki/values';

Expand All @@ -33,7 +33,7 @@ module('Acceptance | pki configuration test', function (hooks) {
await logout.visit();
await authPage.login();
// Cleanup engine
await runCommands([`delete sys/mounts/${this.mountPath}`]);
await runCmd([`delete sys/mounts/${this.mountPath}`]);
});

module('delete all issuers modal and empty states', function (hooks) {
Expand Down Expand Up @@ -157,14 +157,14 @@ module('Acceptance | pki configuration test', function (hooks) {
await fillIn(SELECTORS.configuration.generateRootIssuerNameField, 'issuer-0');
await click(SELECTORS.configuration.generateRootSave);
await click(SELECTORS.configuration.doneButton);
await runCommands([
await runCmd([
`write ${this.mountPath}/roles/some-role \
issuer_ref="default" \
allowed_domains="example.com" \
allow_subdomains=true \
max_ttl="720h"`,
]);
await runCommands([`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test"`]);
await runCmd([`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test"`]);
assert.strictEqual(currentURL(), `/vault/secrets/${this.mountPath}/pki/overview`);
await click(SELECTORS.configTab);
assert.strictEqual(currentURL(), `/vault/secrets/${this.mountPath}/pki/configuration`);
Expand Down
10 changes: 5 additions & 5 deletions ui/tests/acceptance/pki/pki-cross-sign-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { v4 as uuidv4 } from 'uuid';

import authPage from 'vault/tests/pages/auth';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { runCommands } from 'vault/tests/helpers/pki/pki-run-commands';
import { runCmd } from 'vault/tests/helpers/commands';
import { SELECTORS } from 'vault/tests/helpers/pki/pki-issuer-cross-sign';
import { verifyCertificates } from 'vault/utils/parse-pki-cert';
module('Acceptance | pki/pki cross sign', function (hooks) {
Expand All @@ -27,7 +27,7 @@ module('Acceptance | pki/pki cross sign', function (hooks) {
await enablePage.enable('pki', this.parentMountPath);
await enablePage.enable('pki', this.intMountPath);

await runCommands([
await runCmd([
`write "${this.parentMountPath}/root/generate/internal" common_name="Long-Lived Root X1" ttl=8960h issuer_name="${this.oldParentIssuerName}"`,
`write "${this.parentMountPath}/root/generate/internal" common_name="Long-Lived Root X2" ttl=8960h issuer_name="${this.parentIssuerName}"`,
`write "${this.parentMountPath}/config/issuers" default="${this.parentIssuerName}"`,
Expand All @@ -36,8 +36,8 @@ module('Acceptance | pki/pki cross sign', function (hooks) {

hooks.afterEach(async function () {
// Cleanup engine
await runCommands([`delete sys/mounts/${this.intMountPath}`]);
await runCommands([`delete sys/mounts/${this.parentMountPath}`]);
await runCmd([`delete sys/mounts/${this.intMountPath}`]);
await runCmd([`delete sys/mounts/${this.parentMountPath}`]);
});

test('it cross-signs an issuer', async function (assert) {
Expand Down Expand Up @@ -88,7 +88,7 @@ module('Acceptance | pki/pki cross sign', function (hooks) {

// verify cross-sign was accurate by creating a role to issue a leaf certificate
const myRole = 'some-role';
await runCommands([
await runCmd([
`write ${this.intMountPath}/roles/${myRole} \
issuer_ref=${this.newlySignedIssuer}\
allow_any_name=true \
Expand Down
4 changes: 2 additions & 2 deletions ui/tests/acceptance/pki/pki-engine-route-cleanup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import authPage from 'vault/tests/pages/auth';
import logout from 'vault/tests/pages/logout';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { click, currentURL, fillIn, visit } from '@ember/test-helpers';
import { runCommands } from 'vault/tests/helpers/pki/pki-run-commands';
import { runCmd } from 'vault/tests/helpers/commands';
import { SELECTORS } from 'vault/tests/helpers/pki/workflow';

/**
Expand All @@ -34,7 +34,7 @@ module('Acceptance | pki engine route cleanup test', function (hooks) {
await logout.visit();
await authPage.login();
// Cleanup engine
await runCommands([`delete sys/mounts/${this.mountPath}`]);
await runCmd([`delete sys/mounts/${this.mountPath}`]);
});

module('configuration', function () {
Expand Down
31 changes: 15 additions & 16 deletions ui/tests/acceptance/pki/pki-engine-workflow-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { click, currentURL, fillIn, find, isSettled, visit } from '@ember/test-helpers';
import { SELECTORS } from 'vault/tests/helpers/pki/workflow';
import { adminPolicy, readerPolicy, updatePolicy } from 'vault/tests/helpers/policy-generator/pki';
import { tokenWithPolicy, runCommands, clearRecords } from 'vault/tests/helpers/pki/pki-run-commands';
import { clearRecords } from 'vault/tests/helpers/pki/pki-run-commands';
import { runCmd, tokenWithPolicyCmd } from 'vault/tests/helpers/commands';
import { unsupportedPem } from 'vault/tests/helpers/pki/values';
import { create } from 'ember-cli-page-object';
Expand Down Expand Up @@ -42,14 +42,14 @@ module('Acceptance | pki workflow', function (hooks) {
await logout.visit();
await authPage.login();
// Cleanup engine
await runCommands([`delete sys/mounts/${this.mountPath}`]);
await runCmd([`delete sys/mounts/${this.mountPath}`]);
});

module('not configured', function (hooks) {
hooks.beforeEach(async function () {
await authPage.login();
const pki_admin_policy = adminPolicy(this.mountPath, 'roles');
this.pkiAdminToken = await tokenWithPolicy(`pki-admin-${this.mountPath}`, pki_admin_policy);
this.pkiAdminToken = await runCmd(tokenWithPolicyCmd(`pki-admin-${this.mountPath}`, pki_admin_policy));
await logout.visit();
clearRecords(this.store);
});
Expand Down Expand Up @@ -95,14 +95,14 @@ module('Acceptance | pki workflow', function (hooks) {
hooks.beforeEach(async function () {
await authPage.login();
// Setup role-specific items
await runCommands([
await runCmd([
`write ${this.mountPath}/roles/some-role \
issuer_ref="default" \
allowed_domains="example.com" \
allow_subdomains=true \
max_ttl="720h"`,
]);
await runCommands([`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test"`]);
await runCmd([`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test"`]);
const pki_admin_policy = adminPolicy(this.mountPath, 'roles');
const pki_reader_policy = readerPolicy(this.mountPath, 'roles');
const pki_editor_policy = updatePolicy(this.mountPath, 'roles');
Expand Down Expand Up @@ -242,13 +242,13 @@ module('Acceptance | pki workflow', function (hooks) {
hooks.beforeEach(async function () {
await authPage.login();
// base config pki so empty state doesn't show
await runCommands([`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test"`]);
await runCmd([`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test"`]);
const pki_admin_policy = adminPolicy(this.mountPath);
const pki_reader_policy = readerPolicy(this.mountPath, 'keys', true);
const pki_editor_policy = updatePolicy(this.mountPath, 'keys');
this.pkiKeyReader = await tokenWithPolicy(`pki-reader-${this.mountPath}`, pki_reader_policy);
this.pkiKeyEditor = await tokenWithPolicy(`pki-editor-${this.mountPath}`, pki_editor_policy);
this.pkiAdminToken = await tokenWithPolicy(`pki-admin-${this.mountPath}`, pki_admin_policy);
this.pkiKeyReader = await runCmd(tokenWithPolicyCmd(`pki-reader-${this.mountPath}`, pki_reader_policy));
this.pkiKeyEditor = await runCmd(tokenWithPolicyCmd(`pki-editor-${this.mountPath}`, pki_editor_policy));
this.pkiAdminToken = await runCmd(tokenWithPolicyCmd(`pki-admin-${this.mountPath}`, pki_admin_policy));
await logout.visit();
clearRecords(this.store);
});
Expand Down Expand Up @@ -365,9 +365,9 @@ module('Acceptance | pki workflow', function (hooks) {
hooks.beforeEach(async function () {
await authPage.login();
const pki_admin_policy = adminPolicy(this.mountPath);
this.pkiAdminToken = await tokenWithPolicy(`pki-admin-${this.mountPath}`, pki_admin_policy);
this.pkiAdminToken = await runCmd(tokenWithPolicyCmd(`pki-admin-${this.mountPath}`, pki_admin_policy));
// Configure engine with a default issuer
await runCommands([
await runCmd([
`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test" name="Hashicorp Test"`,
]);
await logout.visit();
Expand Down Expand Up @@ -401,9 +401,8 @@ module('Acceptance | pki workflow', function (hooks) {
capabilities = ["deny"]
}
`;
this.token = await tokenWithPolicy(
`pki-issuer-denied-policy-${this.mountPath}`,
pki_issuer_denied_policy
this.token = await runCmd(
tokenWithPolicyCmd(`pki-issuer-denied-policy-${this.mountPath}`, pki_issuer_denied_policy)
);
await logout.visit();
await authPage.login(this.token);
Expand Down Expand Up @@ -479,7 +478,7 @@ module('Acceptance | pki workflow', function (hooks) {
module('rotate', function (hooks) {
hooks.beforeEach(async function () {
await authPage.login();
await runCommands([`write ${this.mountPath}/root/generate/internal issuer_name="existing-issuer"`]);
await runCmd([`write ${this.mountPath}/root/generate/internal issuer_name="existing-issuer"`]);
await logout.visit();
});
test('it renders a warning banner when parent issuer has unsupported OIDs', async function (assert) {
Expand Down Expand Up @@ -513,7 +512,7 @@ module('Acceptance | pki workflow', function (hooks) {
module('config', function (hooks) {
hooks.beforeEach(async function () {
await authPage.login();
await runCommands([`write ${this.mountPath}/root/generate/internal issuer_name="existing-issuer"`]);
await runCmd([`write ${this.mountPath}/root/generate/internal issuer_name="existing-issuer"`]);
const mixed_config_policy = `
${adminPolicy(this.mountPath)}
${readerPolicy(this.mountPath, 'config/cluster')}
Expand Down
17 changes: 9 additions & 8 deletions ui/tests/acceptance/pki/pki-overview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import logout from 'vault/tests/pages/logout';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { click, currentURL, currentRouteName, visit } from '@ember/test-helpers';
import { SELECTORS } from 'vault/tests/helpers/pki/overview';
import { tokenWithPolicy, runCommands, clearRecords } from 'vault/tests/helpers/pki/pki-run-commands';
import { clearRecords } from 'vault/tests/helpers/pki/pki-run-commands';
import { runCmd, tokenWithPolicyCmd } from 'vault/tests/helpers/commands';

module('Acceptance | pki overview', function (hooks) {
setupApplicationTest(hooks);
Expand All @@ -24,7 +25,7 @@ module('Acceptance | pki overview', function (hooks) {
const mountPath = `pki-${uuidv4()}`;
await enablePage.enable('pki', mountPath);
this.mountPath = mountPath;
await runCommands([`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test"`]);
await runCmd([`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test"`]);
const pki_admin_policy = `
path "${this.mountPath}/*" {
capabilities = ["create", "read", "update", "delete", "list"]
Expand All @@ -41,9 +42,9 @@ module('Acceptance | pki overview', function (hooks) {
},
`;

this.pkiRolesList = await tokenWithPolicy('pki-roles-list', pki_roles_list_policy);
this.pkiIssuersList = await tokenWithPolicy('pki-issuers-list', pki_issuers_list_policy);
this.pkiAdminToken = await tokenWithPolicy('pki-admin', pki_admin_policy);
this.pkiRolesList = await runCmd(tokenWithPolicyCmd('pki-roles-list', pki_roles_list_policy));
this.pkiIssuersList = await runCmd(tokenWithPolicyCmd('pki-issuers-list', pki_issuers_list_policy));
this.pkiAdminToken = await runCmd(tokenWithPolicyCmd('pki-admin', pki_admin_policy));
await logout.visit();
clearRecords(this.store);
});
Expand All @@ -52,7 +53,7 @@ module('Acceptance | pki overview', function (hooks) {
await logout.visit();
await authPage.login();
// Cleanup engine
await runCommands([`delete sys/mounts/${this.mountPath}`]);
await runCmd([`delete sys/mounts/${this.mountPath}`]);
});

test('navigates to view issuers when link is clicked on issuer card', async function (assert) {
Expand All @@ -72,7 +73,7 @@ module('Acceptance | pki overview', function (hooks) {
assert.dom(SELECTORS.rolesCardOverviewNum).hasText('0');
await click(SELECTORS.rolesCardLink);
assert.strictEqual(currentURL(), `/vault/secrets/${this.mountPath}/pki/roles`);
await runCommands([
await runCmd([
`write ${this.mountPath}/roles/some-role \
issuer_ref="default" \
allowed_domains="example.com" \
Expand All @@ -92,7 +93,7 @@ module('Acceptance | pki overview', function (hooks) {

test('navigates to generate certificate page for Issue Certificates card', async function (assert) {
await authPage.login(this.pkiAdminToken);
await runCommands([
await runCmd([
`write ${this.mountPath}/roles/some-role \
issuer_ref="default" \
allowed_domains="example.com" \
Expand Down
6 changes: 3 additions & 3 deletions ui/tests/acceptance/pki/pki-tidy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { v4 as uuidv4 } from 'uuid';
import authPage from 'vault/tests/pages/auth';
import logout from 'vault/tests/pages/logout';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { runCommands } from 'vault/tests/helpers/pki/pki-run-commands';
import { runCmd } from 'vault/tests/helpers/commands';
import { SELECTORS } from 'vault/tests/helpers/pki/page/pki-tidy';

module('Acceptance | pki tidy', function (hooks) {
Expand All @@ -26,7 +26,7 @@ module('Acceptance | pki tidy', function (hooks) {
const mountPath = `pki-workflow-${uuidv4()}`;
await enablePage.enable('pki', mountPath);
this.mountPath = mountPath;
await runCommands([
await runCmd([
`write ${this.mountPath}/root/generate/internal common_name="Hashicorp Test" name="Hashicorp Test"`,
]);
await logout.visit();
Expand All @@ -36,7 +36,7 @@ module('Acceptance | pki tidy', function (hooks) {
await logout.visit();
await authPage.login();
// Cleanup engine
await runCommands([`delete sys/mounts/${this.mountPath}`]);
await runCmd([`delete sys/mounts/${this.mountPath}`]);
});

test('it configures a manual tidy operation and shows its details and tidy states', async function (assert) {
Expand Down
32 changes: 0 additions & 32 deletions ui/tests/helpers/pki/pki-run-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,6 @@
* SPDX-License-Identifier: BUSL-1.1
*/

import consoleClass from 'vault/tests/pages/components/console/ui-panel';
import { create } from 'ember-cli-page-object';

const consoleComponent = create(consoleClass);

export const tokenWithPolicy = async function (name, policy) {
await consoleComponent.runCommands([
`write sys/policies/acl/${name} policy=${btoa(policy)}`,
`write -field=client_token auth/token/create policies=${name}`,
]);
return consoleComponent.lastLogOutput;
};

export const runCommands = async function (commands) {
try {
await consoleComponent.runCommands(commands);
const res = consoleComponent.lastLogOutput;
if (res.includes('Error')) {
throw new Error(res);
}
return res;
} catch (error) {
// eslint-disable-next-line no-console
console.error(
`The following occurred when trying to run the command(s):\n ${commands.join('\n')} \n\n ${
consoleComponent.lastLogOutput
}`
);
throw error;
}
};

// Clears pki-related data and capabilities so that admin
// capabilities from setup don't rollover
export function clearRecords(store) {
Expand Down

0 comments on commit 2f05a36

Please sign in to comment.