mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-18 04:27:02 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
/**
|
|
* Helper functions to run common commands in the consoleComponent during tests.
|
|
* Please note that a user must be logged in during the test context for the commands to run
|
|
*
|
|
* Example:
|
|
*
|
|
* import { v4 as uuidv4 } from 'uuid';
|
|
* import { create } from 'ember-cli-page-object';
|
|
* import consoleClass from 'vault/tests/pages/components/console/ui-panel';
|
|
* import { runCmd, mountEngineCmd } from 'vault/tests/helpers/commands';
|
|
*
|
|
* const consoleComponent = create(consoleClass);
|
|
*
|
|
* async function mountEngineExitOnError() {
|
|
* const backend = `pki-${uuidv4()}`;
|
|
* await runCmd(consoleComponent, mountEngineCmd('pki', backend));
|
|
* return backend;
|
|
* }
|
|
*
|
|
* async function mountEngineSquashErrors() {
|
|
* const backend = `pki-${uuidv4()}`;
|
|
* await consoleComponent.runCommands(mountEngineCmd('pki', backend));
|
|
* return backend;
|
|
* }
|
|
*/
|
|
|
|
export function mountEngineCmd(type, customName = '') {
|
|
const name = customName || type;
|
|
return [`write sys/mounts/${name} type=${type}`];
|
|
}
|
|
|
|
export function deleteEngineCmd(name) {
|
|
return [`delete sys/mounts/${name}`];
|
|
}
|
|
|
|
export function createPolicyCmd(name, contents) {
|
|
const policyContent = window.btoa(contents);
|
|
return [`write sys/policies/acl/${name} policy=${policyContent}`];
|
|
}
|
|
|
|
export function tokenWithPolicyCmd(policyName = 'default') {
|
|
return [`write -field=client_token auth/token/create policies=${policyName} ttl=1h`];
|
|
}
|
|
|
|
/**
|
|
* runCmd is used to run commands and throw an error if the output includes "Error"
|
|
* @param {Component} console instance
|
|
* @param {Array<string>} commands array of commands that should be run
|
|
* @returns the last log output. Throws an error if it includes an error
|
|
*/
|
|
export async function runCmd(component, commands) {
|
|
if (!component || !commands) {
|
|
throw new Error('runCmd requires consoleComponent and commands passed in');
|
|
}
|
|
await component.runCommands(commands);
|
|
const lastOutput = component.lastLogOutput;
|
|
if (lastOutput.includes('Error')) {
|
|
throw new Error(`Error occurred while running commands: "${commands.join('; ')}" - ${lastOutput}`);
|
|
}
|
|
return lastOutput;
|
|
}
|