Skip to content

Commit

Permalink
Merge branch 'main' into VAULT-27243/update/vault-plugin-database-ela…
Browse files Browse the repository at this point in the history
…sticsearch/v0.16.0
  • Loading branch information
Zlaticanin authored Sep 4, 2024
2 parents 54c5924 + 1238a18 commit eb81560
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 318 deletions.
2 changes: 1 addition & 1 deletion ui/app/models/kmip/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import apiPath from 'vault/utils/api-path';
import lazyCapabilities from 'vault/macros/lazy-capabilities';
import { removeManyFromArray } from 'vault/helpers/remove-from-array';

export const COMPUTEDS = {
const COMPUTEDS = {
operationFields: computed('newFields', function () {
return this.newFields.filter((key) => key.startsWith('operation'));
}),
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"start:chroot": "ember server --proxy=http://127.0.0.1:8300 --port=4300",
"test": "concurrently --kill-others-on-fail -P -c \"auto\" -n lint:js,lint:hbs,vault \"yarn:lint:js:quiet\" \"yarn:lint:hbs:quiet\" \"node scripts/start-vault.js {@}\" --",
"test:enos": "concurrently --kill-others-on-fail -P -c \"auto\" -n lint:js,lint:hbs,enos \"yarn:lint:js:quiet\" \"yarn:lint:hbs:quiet\" \"node scripts/enos-test-ember.js {@}\" --",
"test:oss": "yarn run test -f='!enterprise' --split=8 --preserve-test-name --parallel",
"test:oss": "yarn run test -f='!enterprise'",
"test:ent": "node scripts/start-vault.js -f='enterprise'",
"test:quick": "node scripts/start-vault.js --split=8 --preserve-test-name --parallel",
"test:quick-oss": "node scripts/start-vault.js -f='!enterprise' --split=8 --preserve-test-name --parallel",
Expand Down
91 changes: 89 additions & 2 deletions ui/tests/acceptance/enterprise-kmip-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
* SPDX-License-Identifier: BUSL-1.1
*/

import { currentURL, currentRouteName, settled, fillIn, waitUntil, find, click } from '@ember/test-helpers';
import {
currentURL,
currentRouteName,
settled,
fillIn,
visit,
waitUntil,
find,
click,
} from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';

Expand All @@ -14,7 +23,7 @@ import credentialsPage from 'vault/tests/pages/secrets/backend/kmip/credentials'
import mountSecrets from 'vault/tests/pages/settings/mount-secret-backend';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
import { allEngines } from 'vault/helpers/mountable-secret-engines';
import { runCmd } from 'vault/tests/helpers/commands';
import { mountEngineCmd, runCmd } from 'vault/tests/helpers/commands';
import { v4 as uuidv4 } from 'uuid';

// port has a lower limit of 1024
Expand Down Expand Up @@ -76,6 +85,7 @@ const generateCreds = async (backend) => {
}
return { backend, scope, role, serial };
};

module('Acceptance | Enterprise | KMIP secrets', function (hooks) {
setupApplicationTest(hooks);

Expand Down Expand Up @@ -347,4 +357,81 @@ module('Acceptance | Enterprise | KMIP secrets', function (hooks) {
assert.strictEqual(credentialsPage.listItemLinks.length, 0, 'renders no credentials');
assert.ok(credentialsPage.isEmpty, 'renders empty');
});

// the kmip/role model relies on openApi so testing the form via an acceptance test
module('kmip role edit form', function (hooks) {
hooks.beforeEach(async function () {
this.store = this.owner.lookup('service:store');
this.scope = 'my-scope';
this.name = 'my-role';
await authPage.login();
await runCmd(mountEngineCmd('kmip', this.backend), false);
await runCmd([`write ${this.backend}/scope/${this.scope} -force`]);
await rolesPage.visit({ backend: this.backend, scope: this.scope });
this.setModel = async () => {
await click('[data-test-edit-form-submit]');
await visit(`/vault/secrets/${this.backend}/kmip/scopes/${this.scope}/roles/${this.name}`);
this.model = this.store.peekRecord('kmip/role', this.name);
};
});

// "operationNone" is the attr name for the 'Allow this role to perform KMIP operations' toggle
// operationNone = false => the toggle is ON and KMIP operations are allowed
// operationNone = true => the toggle is OFF and KMIP operations are not allowed
test('it submits when operationNone is toggled on', async function (assert) {
assert.expect(3);

await click('[data-test-role-create]');
await fillIn(GENERAL.inputByAttr('name'), this.name);
assert.dom(GENERAL.inputByAttr('operationAll')).isChecked('operationAll is checked by default');
await this.setModel();
assert.true(this.model.operationAll, 'operationAll is true');
assert.strictEqual(this.model.operationNone, undefined, 'operationNone is unset');
});

test('it submits when operationNone is toggled off', async function (assert) {
assert.expect(4);

await click('[data-test-role-create]');
await fillIn(GENERAL.inputByAttr('name'), this.name);
await click(GENERAL.inputByAttr('operationNone'));
assert
.dom(GENERAL.inputByAttr('operationNone'))
.isNotChecked('Allow this role to perform KMIP operations is toggled off');
assert
.dom(GENERAL.inputByAttr('operationAll'))
.doesNotExist('clicking the toggle hides KMIP operation checkboxes');
await this.setModel();
assert.strictEqual(this.model.operationAll, undefined, 'operationAll is unset');
assert.true(this.model.operationNone, 'operationNone is true');
});

test('it submits when operationAll is unchecked', async function (assert) {
assert.expect(2);

await click('[data-test-role-create]');
await fillIn(GENERAL.inputByAttr('name'), this.name);
await click(GENERAL.inputByAttr('operationAll'));
await this.setModel();
assert.strictEqual(this.model.operationAll, undefined, 'operationAll is unset');
assert.true(this.model.operationNone, 'operationNone is true');
});

test('it submits individually selected operations', async function (assert) {
assert.expect(6);

await click('[data-test-role-create]');
await fillIn(GENERAL.inputByAttr('name'), this.name);
await click(GENERAL.inputByAttr('operationAll'));
await click(GENERAL.inputByAttr('operationGet'));
await click(GENERAL.inputByAttr('operationGetAttributes'));
assert.dom(GENERAL.inputByAttr('operationAll')).isNotChecked();
assert.dom(GENERAL.inputByAttr('operationCreate')).isNotChecked(); // unchecking operationAll deselects the other checkboxes
await this.setModel();
assert.strictEqual(this.model.operationAll, undefined, 'operationAll is unset');
assert.strictEqual(this.model.operationNone, undefined, 'operationNone is unset');
assert.true(this.model.operationGet, 'operationGet is true');
assert.true(this.model.operationGetAttributes, 'operationGetAttributes is true');
});
});
});
19 changes: 9 additions & 10 deletions ui/tests/acceptance/pki/pki-configuration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { setupMirage } from 'ember-cli-mirage/test-support';
import { click, currentURL, fillIn, visit, settled, find, waitFor, waitUntil } from '@ember/test-helpers';
import { v4 as uuidv4 } from 'uuid';

import authPage from 'vault/tests/pages/auth';
import logout from 'vault/tests/pages/logout';
import { login, logout } from 'vault/tests/helpers/auth/auth-helpers';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { runCmd } from 'vault/tests/helpers/commands';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
Expand All @@ -29,17 +28,17 @@ module('Acceptance | pki configuration test', function (hooks) {

hooks.beforeEach(async function () {
this.pemBundle = issuerPemBundle;
await authPage.login();
await login();
// Setup PKI engine
const mountPath = `pki-workflow-${uuidv4()}`;
await enablePage.enable('pki', mountPath);
this.mountPath = mountPath;
await logout.visit();
await logout();
});

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

test('it shows the delete all issuers modal', async function (assert) {
await authPage.login(this.pkiAdminToken);
await login(this.pkiAdminToken);
await visit(`/vault/secrets/${this.mountPath}/pki/configuration`);
await click(PKI_CONFIGURE_CREATE.configureButton);
assert.strictEqual(currentURL(), `/vault/secrets/${this.mountPath}/pki/configuration/create`);
Expand Down Expand Up @@ -78,7 +77,7 @@ module('Acceptance | pki configuration test', function (hooks) {
});

test('it shows the correct empty state message if certificates exists after delete all issuers', async function (assert) {
await authPage.login(this.pkiAdminToken);
await login(this.pkiAdminToken);
await visit(`/vault/secrets/${this.mountPath}/pki/configuration`);
await click(PKI_CONFIGURE_CREATE.configureButton);
assert.strictEqual(
Expand Down Expand Up @@ -157,7 +156,7 @@ module('Acceptance | pki configuration test', function (hooks) {
});

test('it shows the correct empty state message if roles and certificates exists after delete all issuers', async function (assert) {
await authPage.login(this.pkiAdminToken);
await login(this.pkiAdminToken);
// Configure PKI
await visit(`/vault/secrets/${this.mountPath}/pki/configuration`);
await click(PKI_CONFIGURE_CREATE.configureButton);
Expand Down Expand Up @@ -231,7 +230,7 @@ module('Acceptance | pki configuration test', function (hooks) {
// test coverage for ed25519 certs not displaying because the verify() function errors
test('it generates and displays a root issuer of key type = ed25519', async function (assert) {
assert.expect(4);
await authPage.login(this.pkiAdminToken);
await login(this.pkiAdminToken);
await visit(`/vault/secrets/${this.mountPath}/pki/overview`);
await click(GENERAL.secretTab('Issuers'));
await click(PKI_ISSUER_LIST.generateIssuerDropdown);
Expand Down
6 changes: 3 additions & 3 deletions ui/tests/acceptance/settings/auth/enable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { v4 as uuidv4 } from 'uuid';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
import page from 'vault/tests/pages/settings/auth/enable';
import listPage from 'vault/tests/pages/access/methods';
import authPage from 'vault/tests/pages/auth';
import { login } from 'vault/tests/helpers/auth/auth-helpers';

module('Acceptance | settings/auth/enable', function (hooks) {
setupApplicationTest(hooks);

hooks.beforeEach(function () {
this.uid = uuidv4();
return authPage.login();
return login();
});

test('it mounts and redirects', async function (assert) {
Expand All @@ -29,7 +29,7 @@ module('Acceptance | settings/auth/enable', function (hooks) {
assert.strictEqual(currentRouteName(), 'vault.cluster.settings.auth.enable');
await page.enable(type, path);
await settled();
await assert.strictEqual(
assert.strictEqual(
page.flash.latestMessage,
`Successfully mounted the ${type} auth method at ${path}.`,
'success flash shows'
Expand Down
42 changes: 32 additions & 10 deletions ui/tests/helpers/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
* SPDX-License-Identifier: BUSL-1.1
*/

import consoleClass from 'vault/tests/pages/components/console/ui-panel';
import { create } from 'ember-cli-page-object';
import { click, fillIn, findAll, triggerKeyEvent } from '@ember/test-helpers';

const REPL = {
toggle: '[data-test-console-toggle]',
consoleInput: '[data-test-component="console/command-input"] input',
logOutputItems: '[data-test-component="console/output-log"] > div',
};

/**
* Helper functions to run common commands in the consoleComponent during tests.
Expand All @@ -31,30 +36,47 @@ import { create } from 'ember-cli-page-object';
* }
*/

const cc = create(consoleClass);

/**
* runCmd is used to run commands and throw an error if the output includes "Error"
* @param {string || string[]} commands array of commands that should run
* @param {boolean} throwErrors
* @returns the last log output. Throws an error if it includes an error
*/
export async function runCmd(commands, throwErrors = true) {
export const runCmd = async (commands, throwErrors = true) => {
if (!commands) {
throw new Error('runCmd requires commands array passed in');
}
if (!Array.isArray(commands)) {
commands = [commands];
}
await cc.toggle();
await cc.runCommands(commands, false);
const lastOutput = cc.lastLogOutput;
await cc.toggle();
await click(REPL.toggle);
await enterCommands(commands);
const lastOutput = await lastLogOutput();
await click(REPL.toggle);
if (throwErrors && lastOutput.includes('Error')) {
throw new Error(`Error occurred while running commands: "${commands.join('; ')}" - ${lastOutput}`);
}
return lastOutput;
}
};

export const enterCommands = async (commands) => {
const toExecute = Array.isArray(commands) ? commands : [commands];
for (const command of toExecute) {
await fillIn(REPL.consoleInput, command);
await triggerKeyEvent(REPL.consoleInput, 'keyup', 'Enter');
}
};

export const lastLogOutput = async () => {
const items = findAll(REPL.logOutputItems);
const count = items.length;
if (count === 0) {
// If no logOutput items are found, we can assume the response is empty
return '';
}
const outputItemText = items[count - 1].innerText;
return outputItemText;
};

// Common commands
export function mountEngineCmd(type, customName = '') {
Expand Down
Loading

0 comments on commit eb81560

Please sign in to comment.