refact(e2e): Move env outside of helper methods (#2186)

* refact(e2e): Move env outside of UI helper methods

* refact(e2e): Move env outside of CLI helpers
This commit is contained in:
Michael Li authored and GitHub committed 2024-03-18 15:53:39 -04:00
1 parent 98170ed01e
commit 879c196887
14 files changed
+273 -92

No files matched your search

+28 -18
View File
@@ -20,18 +20,25 @@ exports.checkBoundaryCli = async () => {
/**
* Uses the boundary CLI to authenticate to the specified Boundary instance
* @param {string} addr Address of the Boundary instance to be authenticated to
* @param {string} authMethodId ID of the auth method to be used for authentication
* @param {string} loginName Login name to be used for authentication
* @param {string} password Password to be used for authentication
*/
exports.authenticateBoundaryCli = async () => {
exports.authenticateBoundaryCli = async (
addr,
authMethodId,
loginName,
password,
) => {
try {
execSync(
'boundary authenticate password' +
' -addr=' +
process.env.BOUNDARY_ADDR +
' -auth-method-id=' +
process.env.E2E_PASSWORD_AUTH_METHOD_ID +
' -login-name=' +
process.env.E2E_PASSWORD_ADMIN_LOGIN_NAME +
' -password=env://E2E_PASSWORD_ADMIN_PASSWORD',
` -addr=${addr}` +
` -auth-method-id=${authMethodId}` +
` -login-name=${loginName}` +
' -password=env://BPASS',
{ env: { ...process.env, BPASS: password } },
);
} catch (e) {
console.log(`${e.stderr}`);
@@ -41,20 +48,19 @@ exports.authenticateBoundaryCli = async () => {
/**
* Uses the boundary CLI to connect to the specified target
* @param {string} targetId ID of the target to be connected to
* @param {string} sshUser User to be used for the ssh connection
* @param {string} sshKeyPath Path to the ssh key to be used for the ssh connection
* @returns ChildProcess representing the result of the command execution
*/
exports.connectToTarget = async (targetId) => {
exports.connectToTarget = async (targetId, sshUser, sshKeyPath) => {
let connect;
try {
connect = exec(
'boundary connect' +
' -target-id=' +
targetId +
` -target-id=${targetId}` +
' -exec /usr/bin/ssh --' +
' -l ' +
process.env.E2E_SSH_USER +
' -i ' +
process.env.E2E_SSH_KEY_PATH +
` -l ${sshUser}` +
` -i ${sshKeyPath}` +
' -o UserKnownHostsFile=/dev/null' +
' -o StrictHostKeyChecking=no' +
' -o IdentitiesOnly=yes' + // forces the use of the provided key
@@ -241,7 +247,6 @@ exports.makeAuthMethodPrimaryCli = async (scopeId, authMethodId) => {
exports.createNewPasswordAccountCli = async (authMethodId) => {
let passwordAccount;
const login = 'test-login';
process.env.ACCOUNT_PASSWORD = 'test-password';
try {
passwordAccount = JSON.parse(
execSync(
@@ -250,6 +255,7 @@ exports.createNewPasswordAccountCli = async (authMethodId) => {
-login-name ${login} \
-password env://ACCOUNT_PASSWORD \
-format json`,
{ env: { ...process.env, ACCOUNT_PASSWORD: 'test-password' } },
),
).item;
} catch (e) {
@@ -451,12 +457,14 @@ exports.createNewStaticCredentialStoreCli = async (projectId) => {
/**
* Uses the boundary CLI to create a new vault credential store.
* @param {string} projectId ID of the project under which the credential store will be created.
* @param {string} vaultAddr Address of the vault that the credential store will be created for.
* @param {string} secretPolicyName Name of the secret policy that's used to create vault token.
* @param {string} boundaryPolicyName Name of the boundary policy that's used to create vault token.
* @returns {Promise<string>} new credential store's ID
*/
exports.createNewVaultCredentialStoreCli = async (
projectId,
vaultAddr,
secretPolicyName,
boundaryPolicyName,
) => {
@@ -487,7 +495,7 @@ exports.createNewVaultCredentialStoreCli = async (
`boundary credential-stores create vault \
-scope-id ${projectId} \
-name ${credentialStoreName} \
-vault-address ${process.env.E2E_VAULT_ADDR} \
-vault-address ${vaultAddr} \
-vault-token ${clientToken} \
-format json`,
),
@@ -506,7 +514,6 @@ exports.createNewVaultCredentialStoreCli = async (
exports.createNewUsernamePasswordCredentialCli = async (credentialStoreId) => {
let usernamePasswordCredential;
const login = 'test-login';
process.env.CREDENTIALS_PASSWORD = 'credentials-password';
try {
usernamePasswordCredential = JSON.parse(
execSync(
@@ -516,6 +523,9 @@ exports.createNewUsernamePasswordCredentialCli = async (credentialStoreId) => {
-username ${login} \
-password env://CREDENTIALS_PASSWORD \
-format json`,
{
env: { ...process.env, CREDENTIALS_PASSWORD: 'credentials-password' },
},
),
).item;
} catch (e) {
+50 -34
View File
@@ -118,15 +118,16 @@ exports.createNewHostSet = async (page) => {
/**
* Uses the UI to create a new host in a host set. Assumes you have just created a new host set.
* @param {Page} page Playwright page object
* @param {string} address Address of the host
* @returns Name of the host
*/
exports.createNewHostInHostSet = async (page) => {
exports.createNewHostInHostSet = async (page, address) => {
const hostName = 'Host ' + nanoid();
await page.getByText('Manage').click();
await page.getByRole('link', { name: 'Create and Add Host' }).click();
await page.getByLabel('Name').fill(hostName);
await page.getByLabel('Description').fill('This is an automated test');
await page.getByLabel('Address').fill(process.env.E2E_TARGET_ADDRESS);
await page.getByLabel('Address').fill(address);
await page.getByRole('button', { name: 'Save' }).click();
await expect(
page.getByRole('alert').getByText('Success', { exact: true }),
@@ -169,10 +170,11 @@ exports.createStaticCredentialStore = async (page) => {
/**
* Uses the UI to create a vault credential store. Assumes you have selected the desired project.
* @param {Page} page Playwright page object
* @param {string} vaultAddr address of the vault server
* @param {string} clientToken vault token to connect to boundary
* @returns Name of the credential store
*/
exports.createVaultCredentialStore = async (page, clientToken) => {
exports.createVaultCredentialStore = async (page, vaultAddr, clientToken) => {
const credentialStoreName = 'Credential Store ' + nanoid();
await page
.getByRole('navigation', { name: 'Resources' })
@@ -182,9 +184,7 @@ exports.createVaultCredentialStore = async (page, clientToken) => {
await page.getByLabel('Name', { exact: true }).fill(credentialStoreName);
await page.getByLabel('Description').fill('This is an automated test');
await page.getByRole('group', { name: 'Type' }).getByLabel('Vault').click();
await page
.getByLabel('Address', { exact: true })
.fill(process.env.E2E_VAULT_ADDR);
await page.getByLabel('Address', { exact: true }).fill(vaultAddr);
await page.getByLabel('Token', { exact: true }).fill(clientToken);
await page.getByRole('button', { name: 'Save' }).click();
await expect(
@@ -203,9 +203,11 @@ exports.createVaultCredentialStore = async (page, clientToken) => {
/**
* Uses the UI to create a static key pair credential . Assumes you have selected the desired project.
* @param {Page} page Playwright page object
* @param {string} username username for the credential
* @param {string} keyPath path to the private key
* @returns Name of the credential
*/
exports.createStaticCredentialKeyPair = async (page) => {
exports.createStaticCredentialKeyPair = async (page, username, keyPath) => {
const credentialName = 'Credential ' + nanoid();
await page.getByRole('link', { name: 'Credentials', exact: true }).click();
await page.getByRole('link', { name: 'New', exact: true }).click();
@@ -215,10 +217,8 @@ exports.createStaticCredentialKeyPair = async (page) => {
.getByRole('group', { name: 'Type' })
.getByLabel('Username & Key Pair')
.click();
await page
.getByLabel('Username', { exact: true })
.fill(process.env.E2E_SSH_USER);
const keyData = await readFile(process.env.E2E_SSH_KEY_PATH, {
await page.getByLabel('Username', { exact: true }).fill(username);
const keyData = await readFile(keyPath, {
encoding: 'utf-8',
});
await page.getByLabel('SSH Private Key', { exact: true }).fill(keyData);
@@ -281,11 +281,13 @@ exports.createVaultGenericCredentialLibrary = async (
* the desired credential store.
* @param {Page} page Playwright page object
* @param {string} vaultPath path to secret in vault
* @param {string} username username for the credential
* @returns Name of the credential library
*/
exports.createVaultSshCertificateCredentialLibrary = async (
page,
vaultPath,
username,
) => {
const credentialLibraryName = 'Credential Library ' + nanoid();
@@ -306,7 +308,7 @@ exports.createVaultSshCertificateCredentialLibrary = async (
.getByLabel('Description (Optional)')
.fill('This is an automated test');
await page.getByLabel('Vault Path').fill(vaultPath);
await page.getByLabel('Username').fill(process.env.E2E_SSH_USER);
await page.getByLabel('Username').fill(username);
await page.getByLabel('Key Type').selectOption('ecdsa');
await page.getByLabel('Key Bits').fill('521');
@@ -331,9 +333,10 @@ exports.createVaultSshCertificateCredentialLibrary = async (
/**
* Uses the UI to create a new target. Assumes you have selected the desired project.
* @param {Page} page Playwright page object
* @param {string} port Port of the target
* @returns Name of the target
*/
exports.createNewTarget = async (page) => {
exports.createNewTarget = async (page, port) => {
const targetName = 'Target ' + nanoid();
await page
.getByRole('navigation', { name: 'Resources' })
@@ -342,7 +345,7 @@ exports.createNewTarget = async (page) => {
await page.getByRole('link', { name: 'New', exact: true }).click();
await page.getByLabel('Name').fill(targetName);
await page.getByLabel('Description').fill('This is an automated test');
await page.getByLabel('Default Port').fill(process.env.E2E_TARGET_PORT);
await page.getByLabel('Default Port').fill(port);
await page.getByRole('button', { name: 'Save' }).click();
await expect(
page.getByRole('alert').getByText('Success', { exact: true }),
@@ -358,9 +361,11 @@ exports.createNewTarget = async (page) => {
/**
* Uses the UI to create a new target with address. Assumes you have selected the desired project.
* @param {Page} page Playwright page object
* @param {string} address Address of the target
* @param {string} port Port of the target
* @returns Name of the target
*/
exports.createNewTargetWithAddress = async (page) => {
exports.createNewTargetWithAddress = async (page, address, port) => {
const targetName = 'Target ' + nanoid();
await page
.getByRole('navigation', { name: 'Resources' })
@@ -369,8 +374,8 @@ exports.createNewTargetWithAddress = async (page) => {
await page.getByRole('link', { name: 'New', exact: true }).click();
await page.getByLabel('Name').fill(targetName);
await page.getByLabel('Description').fill('This is an automated test');
await page.getByLabel('Target Address').fill(process.env.E2E_TARGET_ADDRESS);
await page.getByLabel('Default Port').fill(process.env.E2E_TARGET_PORT);
await page.getByLabel('Target Address').fill(address);
await page.getByLabel('Default Port').fill(port);
await page.getByRole('button', { name: 'Save' }).click();
await expect(
page.getByRole('alert').getByText('Success', { exact: true }),
@@ -387,9 +392,11 @@ exports.createNewTargetWithAddress = async (page) => {
* Uses the UI to create a new TCP target with address in boundary-enterprise
* Assumes you have selected the desired project.
* @param {Page} page Playwright page object
* @param {string} address Address of the target
* @param {string} port Port of the target
* @returns Name of the target
*/
exports.createTcpTargetWithAddressEnt = async (page) => {
exports.createTcpTargetWithAddressEnt = async (page, address, port) => {
const targetName = 'Target ' + nanoid();
await page
.getByRole('navigation', { name: 'Resources' })
@@ -399,8 +406,8 @@ exports.createTcpTargetWithAddressEnt = async (page) => {
await page.getByLabel('Name').fill(targetName);
await page.getByLabel('Description').fill('This is an automated test');
await page.getByRole('group', { name: 'Type' }).getByLabel('TCP').click();
await page.getByLabel('Target Address').fill(process.env.E2E_TARGET_ADDRESS);
await page.getByLabel('Default Port').fill(process.env.E2E_TARGET_PORT);
await page.getByLabel('Target Address').fill(address);
await page.getByLabel('Default Port').fill(port);
await page.getByRole('button', { name: 'Save' }).click();
await expect(
page.getByRole('alert').getByText('Success', { exact: true }),
@@ -417,9 +424,11 @@ exports.createTcpTargetWithAddressEnt = async (page) => {
* Uses the UI to create a new SSH target with address in boundary-enterprise
* Assumes you have selected the desired project.
* @param {Page} page Playwright page object
* @param {string} address Address of the target
* @param {string} port Port of the target
* @returns Name of the target
*/
exports.createSshTargetWithAddressEnt = async (page) => {
exports.createSshTargetWithAddressEnt = async (page, address, port) => {
const targetName = 'Target ' + nanoid();
await page
.getByRole('navigation', { name: 'Resources' })
@@ -429,8 +438,8 @@ exports.createSshTargetWithAddressEnt = async (page) => {
await page.getByLabel('Name').fill(targetName);
await page.getByLabel('Description').fill('This is an automated test');
await page.getByRole('group', { name: 'Type' }).getByLabel('SSH').click();
await page.getByLabel('Target Address').fill(process.env.E2E_TARGET_ADDRESS);
await page.getByLabel('Default Port').fill(process.env.E2E_TARGET_PORT);
await page.getByLabel('Target Address').fill(address);
await page.getByLabel('Default Port').fill(port);
await page.getByRole('button', { name: 'Save' }).click();
await expect(
page.getByRole('alert').getByText('Success', { exact: true }),
@@ -907,25 +916,32 @@ exports.addGrantsToGroup = async (page, grants) => {
/**
* Uses the UI to create a new Storage Bucket. Assumes you have selected the desired scope.
* @param {Page} page Playwright page object
* @param {string} bucketName Name of the Storage Bucket
* @param {string} region Region of the Storage Bucket
* @param {string} accessKeyId Access Key ID for the Storage Bucket
* @param {string} secretAccessKey Secret Access Key for the Storage Bucket
* @param {string} workerFilter Worker filter for the Storage Bucket
* @returns Name of the Storage Bucket
*/
exports.createStorageBucket = async (page) => {
exports.createStorageBucket = async (
page,
bucketName,
region,
accessKeyId,
secretAccessKey,
workerFilter,
) => {
const storageBucketName = 'Bucket ' + nanoid();
await page
.getByRole('link', { name: 'Storage Buckets', exact: true })
.click();
await page.getByRole('link', { name: 'New Storage Bucket' }).click();
await page.getByLabel(new RegExp('Name*')).fill(storageBucketName);
await page.getByLabel('Bucket name').fill(process.env.E2E_AWS_BUCKET_NAME);
await page.getByLabel('Region').fill(process.env.E2E_AWS_REGION);
await page
.getByLabel('Access key ID')
.fill(process.env.E2E_AWS_ACCESS_KEY_ID);
await page
.getByLabel('Secret access key')
.fill(process.env.E2E_AWS_SECRET_ACCESS_KEY);
const workerTag = `"${process.env.E2E_WORKER_TAG_EGRESS}" in "/tags/type"`;
await page.getByLabel('Worker filter').fill(workerTag);
await page.getByLabel('Bucket name').fill(bucketName);
await page.getByLabel('Region').fill(region);
await page.getByLabel('Access key ID').fill(accessKeyId);
await page.getByLabel('Secret access key').fill(secretAccessKey);
await page.getByLabel('Worker filter').fill(workerFilter);
await page.getByLabel('Disable credential rotation').click();
await page.getByRole('button', { name: 'Save' }).click();
await expect(