vault/ui/tests/helpers/kv/kv-run-commands.js
Angel Garbarino 1133777c6f
Improve test stability (#25120)
* improve overview test

* Add custom waiter to maybe-query-record

* add custom waiter to console/ui-panel

* Add flash message check for better visibility into flakiness

* trying to find what's wrong with PKI

* create role happy path uses root token

* make all policy names on pki workflow unique

* some secret test cleanup, not the main offenders

* remove uncessary settled

* Update kv-run-commands.js

* Update kv-run-commands.js

* Update kv-data-fields-test.js

* some missed fixes that were outside the original cherry pick

* remove overview test things

* move testWaiter to logAndOutput command

* nope not working

---------

Co-authored-by: Chelsea Shaw <cshaw@hashicorp.com>
2024-01-30 12:35:44 -07:00

69 lines
2.5 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
/* eslint-disable ember/no-settled-after-test-helper */
import { click, fillIn, visit, settled } from '@ember/test-helpers';
import { FORM } from './kv-selectors';
import { encodePath } from 'vault/utils/path-encoding-helpers';
// CUSTOM ACTIONS RELEVANT TO KV-V2
export const writeSecret = async function (backend, path, key, val, ns = null) {
const url = `vault/secrets/${backend}/kv/create`;
ns ? await visit(url + `?namespace=${ns}`) : await visit(url);
await settled();
await fillIn(FORM.inputByAttr('path'), path);
await fillIn(FORM.keyInput(), key);
await fillIn(FORM.maskedValueInput(), val);
await click(FORM.saveBtn);
await settled();
return;
};
export const writeVersionedSecret = async function (backend, path, key, val, version = 2, ns = null) {
await writeSecret(backend, path, 'key-1', 'val-1', ns);
await settled();
for (let currentVersion = 2; currentVersion <= version; currentVersion++) {
const url = `/vault/secrets/${backend}/kv/${encodeURIComponent(path)}/details/edit`;
ns ? await visit(url + `?namespace=${ns}`) : await visit(url);
await settled();
if (currentVersion === version) {
await fillIn(FORM.keyInput(), key);
await fillIn(FORM.maskedValueInput(), val);
} else {
await fillIn(FORM.keyInput(), `key-${currentVersion}`);
await fillIn(FORM.maskedValueInput(), `val-${currentVersion}`);
}
await click(FORM.saveBtn);
await settled();
}
return;
};
export const deleteVersionCmd = function (backend, secretPath, version = 1) {
return `write ${backend}/delete/${encodePath(secretPath)} versions=${version}`;
};
export const destroyVersionCmd = function (backend, secretPath, version = 1) {
return `write ${backend}/destroy/${encodePath(secretPath)} versions=${version}`;
};
export const deleteLatestCmd = function (backend, secretPath) {
return `delete ${backend}/data/${encodePath(secretPath)}`;
};
export const addSecretMetadataCmd = (backend, secret, options = { max_versions: 10 }) => {
const stringOptions = Object.keys(options).reduce((prev, curr) => {
return `${prev} ${curr}=${options[curr]}`;
}, '');
return `write ${backend}/metadata/${secret} ${stringOptions}`;
};
// Clears kv-related data and capabilities so that admin
// capabilities from setup don't rollover
export function clearRecords(store) {
store.unloadAll('kv/data');
store.unloadAll('kv/metatata');
store.unloadAll('capabilities');
}