diff --git a/ui/admin/tests/e2e/helpers/boundary-cli.js b/ui/admin/tests/e2e/helpers/boundary-cli.js index dcc4c896f..98f0c4509 100644 --- a/ui/admin/tests/e2e/helpers/boundary-cli.js +++ b/ui/admin/tests/e2e/helpers/boundary-cli.js @@ -25,13 +25,13 @@ exports.authenticateBoundaryCli = async () => { 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=' + + 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', ); } catch (e) { console.log(`${e.stderr}`); @@ -48,18 +48,41 @@ exports.connectToTarget = async (targetId) => { try { connect = exec( 'boundary connect' + - ' -target-id=' + - targetId + - ' -exec /usr/bin/ssh --' + - ' -l ' + - process.env.E2E_SSH_USER + - ' -i ' + - process.env.E2E_SSH_KEY_PATH + - ' -o UserKnownHostsFile=/dev/null' + - ' -o StrictHostKeyChecking=no' + - ' -o IdentitiesOnly=yes' + // forces the use of the provided key - ' -p {{boundary.port}}' + - ' {{boundary.ip}}', + ' -target-id=' + + targetId + + ' -exec /usr/bin/ssh --' + + ' -l ' + + process.env.E2E_SSH_USER + + ' -i ' + + process.env.E2E_SSH_KEY_PATH + + ' -o UserKnownHostsFile=/dev/null' + + ' -o StrictHostKeyChecking=no' + + ' -o IdentitiesOnly=yes' + // forces the use of the provided key + ' -p {{boundary.port}}' + + ' {{boundary.ip}}', + ); + } catch (e) { + console.log(`${e.stderr}`); + } + return connect; +}; + +/** + * Uses the boundary CLI to connect ssh to the specified target + * @param {string} targetId ID of the target to be connected to + * @returns ChildProcess representing the result of the command execution + */ +exports.connectSshToTarget = async (targetId) => { + let connect; + try { + connect = exec( + 'boundary connect ssh' + + ' -target-id=' + + targetId + + ' --' + + ' -o UserKnownHostsFile=/dev/null' + + ' -o StrictHostKeyChecking=no' + + ' -o IdentitiesOnly=yes', // forces the use of the provided key ); } catch (e) { console.log(`${e.stderr}`); @@ -69,7 +92,7 @@ exports.connectToTarget = async (targetId) => { /** * Uses the boundary CLI to create a new org. - * @returns {string} new org's id + * @returns {Promise} new org's id */ exports.createNewOrgCli = async () => { const orgName = 'Org ' + nanoid(); @@ -78,9 +101,9 @@ exports.createNewOrgCli = async () => { newOrg = JSON.parse( execSync( `boundary scopes create \ - -name="${orgName}" \ - -scope-id=global \ - -format json`, + -name="${orgName}" \ + -scope-id=global \ + -format json`, ), ).item; } catch (e) { @@ -104,7 +127,7 @@ exports.deleteOrgCli = async (orgId) => { /** * Uses the boundary CLI to create a new project. * @param {string} orgId ID of the organization under which the project will be created. - * @returns {string} new project's ID + * @returns {Promise} new project's ID */ exports.createNewProjectCli = async (orgId) => { const projectName = 'Project ' + nanoid(); @@ -113,9 +136,9 @@ exports.createNewProjectCli = async (orgId) => { newProject = JSON.parse( execSync( `boundary scopes create \ - -name="${projectName}" \ - -scope-id=${orgId} \ - -format json`, + -name="${projectName}" \ + -scope-id=${orgId} \ + -format json`, ), ).item; } catch (e) { @@ -126,7 +149,7 @@ exports.createNewProjectCli = async (orgId) => { /** * Uses the boundary CLI to create a new controller-led worker. - * @returns {string} new worker's ID + * @returns {Promise} new worker's ID */ exports.createNewControllerLedWorkerCli = async () => { const workerName = 'worker-' + nanoid(); @@ -135,8 +158,8 @@ exports.createNewControllerLedWorkerCli = async () => { newWorker = JSON.parse( execSync( `boundary workers create controller-led \ - -name="${workerName.toLowerCase()}" \ - -format json`, + -name="${workerName.toLowerCase()}" \ + -format json`, ), ).item; } catch (e) { @@ -148,7 +171,7 @@ exports.createNewControllerLedWorkerCli = async () => { /** * Uses the boundary CLI to create a new password auth-method. * @param {string} scopeId ID of the scope under which the auth-method will be created. - * @returns {string} new auth-method's ID + * @returns {Promise} new auth-method's ID */ exports.createNewPasswordAuthMethodCli = async (scopeId) => { const authMethodName = 'auth-method-' + nanoid(); @@ -157,9 +180,9 @@ exports.createNewPasswordAuthMethodCli = async (scopeId) => { newAuthMethod = JSON.parse( execSync( `boundary auth-methods create password \ - -name "${authMethodName}" \ - -scope-id ${scopeId} \ - -format json`, + -name "${authMethodName}" \ + -scope-id ${scopeId} \ + -format json`, ), ).item; } catch (e) { @@ -189,7 +212,7 @@ exports.makeAuthMethodPrimaryCli = async (scopeId, authMethodId) => { /** * Uses the boundary CLI to create a new password account. * @param {string} authMethodId ID of the auth-method that the new account will be created for. - * @returns {string} new account's ID + * @returns {Promise} new account's ID */ exports.createNewPasswordAccountCli = async (authMethodId) => { let passwordAccount; @@ -199,10 +222,10 @@ exports.createNewPasswordAccountCli = async (authMethodId) => { passwordAccount = JSON.parse( execSync( `boundary accounts create password \ - -auth-method-id ${authMethodId} \ - -login-name ${login} \ - -password env://ACCOUNT_PASSWORD \ - -format json`, + -auth-method-id ${authMethodId} \ + -login-name ${login} \ + -password env://ACCOUNT_PASSWORD \ + -format json`, ), ).item; } catch (e) { @@ -214,7 +237,7 @@ exports.createNewPasswordAccountCli = async (authMethodId) => { /** * Uses the boundary CLI to create a new role. * @param {string} scopeId ID of the scope under which the role will be created. - * @returns {string} new role's ID + * @returns {Promise} new role's ID */ exports.createNewRoleCli = async (scopeId) => { const roleName = 'role-' + nanoid(); @@ -223,9 +246,9 @@ exports.createNewRoleCli = async (scopeId) => { role = JSON.parse( execSync( `boundary roles create \ - -scope-id ${scopeId} \ - -name ${roleName} \ - -format json`, + -scope-id ${scopeId} \ + -name ${roleName} \ + -format json`, ), ).item; } catch (e) { @@ -237,7 +260,7 @@ exports.createNewRoleCli = async (scopeId) => { /** * Uses the boundary CLI to create a new group. * @param {string} scopeId ID of the scope under which the group will be created. - * @returns {string} new group's ID + * @returns {Promise} new group's ID */ exports.createNewGroupCli = async (scopeId) => { const groupName = 'group-' + nanoid(); @@ -246,9 +269,9 @@ exports.createNewGroupCli = async (scopeId) => { group = JSON.parse( execSync( `boundary groups create \ - -scope-id ${scopeId} \ - -name ${groupName} \ - -format json`, + -scope-id ${scopeId} \ + -name ${groupName} \ + -format json`, ), ).item; } catch (e) { @@ -260,7 +283,7 @@ exports.createNewGroupCli = async (scopeId) => { /** * Uses the boundary CLI to create a new user. * @param {string} scopeId ID of the scope under which the user will be created. - * @returns {string} new user's ID + * @returns {Promise} new user's ID */ exports.createNewUserCli = async (scopeId) => { const userName = 'user-' + nanoid(); @@ -269,9 +292,9 @@ exports.createNewUserCli = async (scopeId) => { user = JSON.parse( execSync( `boundary users create \ - -scope-id ${scopeId} \ - -name ${userName} \ - -format json`, + -scope-id ${scopeId} \ + -name ${userName} \ + -format json`, ), ).item; } catch (e) { @@ -283,7 +306,7 @@ exports.createNewUserCli = async (scopeId) => { /** * Uses the boundary CLI to create a new static host catalog. * @param {string} projectId ID of the project under which the host catalog will be created. - * @returns {string} new host catalog's ID + * @returns {Promise} new host catalog's ID */ exports.createNewStaticHostCatalogCli = async (projectId) => { const hostCatalogName = 'static-host-catalog-' + nanoid(); @@ -292,9 +315,9 @@ exports.createNewStaticHostCatalogCli = async (projectId) => { hostCatalog = JSON.parse( execSync( `boundary host-catalogs create static \ - -scope-id ${projectId} \ - -name ${hostCatalogName} \ - -format json`, + -scope-id ${projectId} \ + -name ${hostCatalogName} \ + -format json`, ), ).item; } catch (e) { @@ -306,7 +329,7 @@ exports.createNewStaticHostCatalogCli = async (projectId) => { /** * Uses the boundary CLI to create a new dynamic AWS host catalog. * @param {string} projectId ID of the project under which the host catalog will be created. - * @returns {string} new host catalog's ID + * @returns {Promise} new host catalog's ID */ exports.createDynamicAwsHostCatalogCli = async (projectId) => { const hostCatalogName = 'dynamic-aws-host-catalog-' + nanoid(); @@ -334,7 +357,7 @@ exports.createDynamicAwsHostCatalogCli = async (projectId) => { /** * Uses the boundary CLI to create a new static host. * @param {string} hostCatalogId ID of the host catalog that the host will be created for. - * @returns {string} new host's ID + * @returns {Promise} new host's ID */ exports.createNewStaticHostCli = async (hostCatalogId) => { const hostName = 'static-host-' + nanoid(); @@ -343,10 +366,10 @@ exports.createNewStaticHostCli = async (hostCatalogId) => { host = JSON.parse( execSync( `boundary hosts create static \ - -host-catalog-id ${hostCatalogId} \ - -name ${hostName} \ - -address localhost \ - -format json`, + -host-catalog-id ${hostCatalogId} \ + -name ${hostName} \ + -address localhost \ + -format json`, ), ).item; } catch (e) { @@ -358,7 +381,7 @@ exports.createNewStaticHostCli = async (hostCatalogId) => { /** * Uses the boundary CLI to create a new static host set. * @param {string} hostCatalogId ID of the host catalog that the host set will be created for. - * @returns {string} new host set's ID + * @returns {Promise} new host set's ID */ exports.createNewHostSetCli = async (hostCatalogId) => { const hostSetName = 'static-host-' + nanoid(); @@ -367,9 +390,9 @@ exports.createNewHostSetCli = async (hostCatalogId) => { hostSet = JSON.parse( execSync( `boundary host-sets create static \ - -host-catalog-id ${hostCatalogId} \ - -name ${hostSetName} \ - -format json`, + -host-catalog-id ${hostCatalogId} \ + -name ${hostSetName} \ + -format json`, ), ).item; } catch (e) { @@ -381,7 +404,7 @@ exports.createNewHostSetCli = async (hostCatalogId) => { /** * Uses the boundary CLI to create a new static credential store. * @param {string} projectId ID of the project under which the credential store will be created. - * @returns {string} new credential store's ID + * @returns {Promise} new credential store's ID */ exports.createNewStaticCredentialStoreCli = async (projectId) => { const credentialStoreName = 'static-credential-store-' + nanoid(); @@ -390,9 +413,9 @@ exports.createNewStaticCredentialStoreCli = async (projectId) => { staticCredentialStore = JSON.parse( execSync( `boundary credential-stores create static \ - -scope-id ${projectId} \ - -name ${credentialStoreName} \ - -format json`, + -scope-id ${projectId} \ + -name ${credentialStoreName} \ + -format json`, ), ).item; } catch (e) { @@ -406,7 +429,7 @@ exports.createNewStaticCredentialStoreCli = async (projectId) => { * @param {string} projectId ID of the project under which the credential store will be created. * @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 {string} new credential store's ID + * @returns {Promise} new credential store's ID */ exports.createNewVaultCredentialStoreCli = async ( projectId, @@ -454,7 +477,7 @@ exports.createNewVaultCredentialStoreCli = async ( /** * Uses the boundary CLI to create a new username-password credential. * @param {string} credentialStoreId ID of the credential store that the credential will be created for. - * @returns {string} new credential's ID + * @returns {Promise} new credential's ID */ exports.createNewUsernamePasswordCredentialCli = async (credentialStoreId) => { let usernamePasswordCredential; @@ -464,11 +487,11 @@ exports.createNewUsernamePasswordCredentialCli = async (credentialStoreId) => { usernamePasswordCredential = JSON.parse( execSync( `boundary credentials create username-password \ - -name ${login} \ - -credential-store-id ${credentialStoreId} \ - -username ${login} \ - -password env://CREDENTIALS_PASSWORD \ - -format json`, + -name ${login} \ + -credential-store-id ${credentialStoreId} \ + -username ${login} \ + -password env://CREDENTIALS_PASSWORD \ + -format json`, ), ).item; } catch (e) { @@ -480,7 +503,7 @@ exports.createNewUsernamePasswordCredentialCli = async (credentialStoreId) => { /** * Uses the boundary CLI to create a new TCP target. * @param {string} projectId ID of the project under which the target will be created. - * @returns {string} new target's ID + * @returns {Promise} new target's ID */ exports.createNewTcpTarget = async (projectId) => { const targetName = 'target-' + nanoid(); @@ -490,10 +513,10 @@ exports.createNewTcpTarget = async (projectId) => { target = JSON.parse( execSync( `boundary targets create tcp \ - -default-port ${defaultPort} \ - -name ${targetName} \ - -scope-id ${projectId} \ - -format json`, + -default-port ${defaultPort} \ + -name ${targetName} \ + -scope-id ${projectId} \ + -format json`, ), ).item; } catch (e) { @@ -505,9 +528,9 @@ exports.createNewTcpTarget = async (projectId) => { /** * Uses the boundary CLI to create a new SSH target. * @param {string} projectId ID of the project under which the target will be created. - * @returns {string} new target's ID + * @returns {Promise} new target's ID */ -exports.createNewSshTarget = async (projectId) => { +exports.createNewSshTargetCli = async (projectId) => { const targetName = 'target-' + nanoid(); const defaultPort = 22; let target; @@ -515,10 +538,10 @@ exports.createNewSshTarget = async (projectId) => { target = JSON.parse( execSync( `boundary targets create ssh \ - -default-port ${defaultPort} \ - -name ${targetName} \ - -scope-id ${projectId} \ - -format json`, + -default-port ${defaultPort} \ + -name ${targetName} \ + -scope-id ${projectId} \ + -format json`, ), ).item; } catch (e) { diff --git a/ui/admin/tests/e2e/helpers/boundary-ui.js b/ui/admin/tests/e2e/helpers/boundary-ui.js index ed455ce49..1395928c1 100644 --- a/ui/admin/tests/e2e/helpers/boundary-ui.js +++ b/ui/admin/tests/e2e/helpers/boundary-ui.js @@ -5,6 +5,7 @@ /* eslint-disable no-undef */ const { expect } = require('@playwright/test'); +const { readFile } = require('fs/promises'); const { nanoid } = require('nanoid'); /** @@ -136,6 +137,71 @@ exports.createNewHostInHostSet = async (page) => { return hostName; }; +/** + * Uses the UI to create a credential store. Assumes you have selected the desired project. + * @param {Page} page Playwright page object + * @returns Name of the credential store + */ +exports.createStaticCredentialStore = async (page) => { + const credentialStoreName = 'Credential Store ' + nanoid(); + await page + .getByRole('navigation', { name: 'Resources' }) + .getByRole('link', { name: 'Credential Stores' }) + .click(); + await page.getByRole('link', { name: 'New', exact: true }).click(); + 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('Static').click(); + await page.getByRole('button', { name: 'Save' }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }), + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); + await expect( + page + .getByRole('navigation', { name: 'breadcrumbs' }) + .getByText(credentialStoreName), + ).toBeVisible(); + + return credentialStoreName; +}; + +/** + * Uses the UI to create a static key pair credential . Assumes you have selected the desired project. + * @param {Page} page Playwright page object + * @returns Name of the credential + */ +exports.createStaticCredentialKeyPair = async (page) => { + const credentialName = 'Credential ' + nanoid(); + await page.getByRole('link', { name: 'Credentials', exact: true }).click(); + await page.getByRole('link', { name: 'New', exact: true }).click(); + await page.getByLabel('Name', { exact: true }).fill(credentialName); + await page.getByLabel('Description').fill('This is an automated test'); + await 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, { + encoding: 'utf-8', + }); + await page.getByLabel('SSH Private Key', { exact: true }).fill(keyData); + await page.getByRole('button', { name: 'Save' }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }), + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); + await expect( + page + .getByRole('navigation', { name: 'breadcrumbs' }) + .getByText(credentialName), + ).toBeVisible(); + + return credentialName; +}; + /** * Uses the UI to create a new target. Assumes you have selected the desired project. * @param {Page} page Playwright page object @@ -191,6 +257,66 @@ exports.createNewTargetWithAddress = async (page) => { return targetName; }; +/** + * 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 + * @returns Name of the target + */ +exports.createTcpTargetWithAddressEnt = async (page) => { + const targetName = 'Target ' + nanoid(); + await page + .getByRole('navigation', { name: 'Resources' }) + .getByRole('link', { name: 'Targets' }) + .click(); + 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.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.getByRole('button', { name: 'Save' }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }), + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); + await expect( + page.getByRole('navigation', { name: 'breadcrumbs' }).getByText(targetName), + ).toBeVisible(); + + return targetName; +}; + +/** + * 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 + * @returns Name of the target + */ +exports.createSshTargetWithAddressEnt = async (page) => { + const targetName = 'Target ' + nanoid(); + await page + .getByRole('navigation', { name: 'Resources' }) + .getByRole('link', { name: 'Targets' }) + .click(); + 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.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.getByRole('button', { name: 'Save' }).click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }), + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); + await expect( + page.getByRole('navigation', { name: 'breadcrumbs' }).getByText(targetName), + ).toBeVisible(); + + return targetName; +}; + /** * Uses the UI to delete a Boundary resource. Assume you have selected the desired resource. * Note: For a resource to be deleted using this method, @@ -312,6 +438,53 @@ exports.addBrokeredCredentialsToTarget = async ( await expect(page.getByRole('link', { name: credentialName })).toBeVisible(); }; +/** + * Uses the UI to navigate to the specified Target and add the Injected Credentials to it. + * @param {Page} page Playwright page object + * @param {string} targetName Name of the target associated with the session + * @param {string} credentialName Name of the credentials to be added to the target + */ +exports.addInjectedCredentialsToTarget = async ( + page, + targetName, + credentialName, +) => { + await page + .getByRole('navigation', { name: 'Resources' }) + .getByRole('link', { name: 'Targets' }) + .click(); + await page.getByRole('link', { name: targetName }).click(); + await page + .getByRole('link', { + name: 'Injected Application Credentials', + exact: true, + }) + .click(); + await page + .getByRole('article') + .getByRole('link', { + name: 'Add Injected Application Credentials', + exact: true, + }) + .click(); + await page + .getByRole('cell', { name: credentialName }) + .locator('..') + .getByRole('checkbox') + .click({ force: true }); + await page + .getByRole('button', { + name: 'Add Injected Application Credentials', + exact: true, + }) + .click(); + await expect( + page.getByRole('alert').getByText('Success', { exact: true }), + ).toBeVisible(); + await page.getByRole('button', { name: 'Dismiss' }).click(); + await expect(page.getByRole('link', { name: credentialName })).toBeVisible(); +}; + /** * Uses the UI to create new Auth Method. Assumes you have selected the desired scope. * @param {Page} page Playwright page object diff --git a/ui/admin/tests/e2e/tests/credential-store-static.spec.js b/ui/admin/tests/e2e/tests/credential-store-static.spec.js index 8f3c1e641..352ea5e66 100644 --- a/ui/admin/tests/e2e/tests/credential-store-static.spec.js +++ b/ui/admin/tests/e2e/tests/credential-store-static.spec.js @@ -20,6 +20,8 @@ const { createNewHostSet, createNewHostInHostSet, createNewTarget, + createStaticCredentialStore, + createStaticCredentialKeyPair, addBrokeredCredentialsToTarget, addHostSourceToTarget, } = require('../helpers/boundary-ui'); @@ -51,58 +53,13 @@ test.beforeEach(async ({ page }) => { await createNewHostInHostSet(page); targetName = await createNewTarget(page); await addHostSourceToTarget(page, hostSetName); - - const credentialStoreName = 'Credential Store ' + nanoid(); - await page - .getByRole('navigation', { name: 'Resources' }) - .getByRole('link', { name: 'Credential Stores' }) - .click(); - await page.getByRole('link', { name: 'New', exact: true }).click(); - 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('Static').click(); - await page.getByRole('button', { name: 'Save' }).click(); - await expect( - page.getByRole('alert').getByText('Success', { exact: true }), - ).toBeVisible(); - await page.getByRole('button', { name: 'Dismiss' }).click(); - await expect( - page - .getByRole('navigation', { name: 'breadcrumbs' }) - .getByText(credentialStoreName), - ).toBeVisible(); + await createStaticCredentialStore(page); }); test('Static Credential Store (User & Key Pair) @ce @aws @docker', async ({ page, }) => { - const credentialName = 'Credential ' + nanoid(); - await page.getByRole('link', { name: 'Credentials', exact: true }).click(); - await page.getByRole('link', { name: 'New', exact: true }).click(); - await page.getByLabel('Name', { exact: true }).fill(credentialName); - await page.getByLabel('Description').fill('This is an automated test'); - await 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, { - encoding: 'utf-8', - }); - await page.getByLabel('SSH Private Key', { exact: true }).fill(keyData); - await page.getByRole('button', { name: 'Save' }).click(); - await expect( - page.getByRole('alert').getByText('Success', { exact: true }), - ).toBeVisible(); - await page.getByRole('button', { name: 'Dismiss' }).click(); - await expect( - page - .getByRole('navigation', { name: 'breadcrumbs' }) - .getByText(credentialName), - ).toBeVisible(); - + const credentialName = await createStaticCredentialKeyPair(page); await addBrokeredCredentialsToTarget(page, targetName, credentialName); await authenticateBoundaryCli(); @@ -118,6 +75,10 @@ test('Static Credential Store (User & Key Pair) @ce @aws @docker', async ({ retrievedUser, ); } + + const keyData = await readFile(process.env.E2E_SSH_KEY_PATH, { + encoding: 'utf-8', + }); if (keyData != retrievedKey) { throw new Error('Stored Key does not match'); } diff --git a/ui/admin/tests/e2e/tests/delete-resources-ent.spec.js b/ui/admin/tests/e2e/tests/delete-resources-ent.spec.js new file mode 100644 index 000000000..327030f1a --- /dev/null +++ b/ui/admin/tests/e2e/tests/delete-resources-ent.spec.js @@ -0,0 +1,167 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +/* eslint-disable no-undef */ +const { test } = require('@playwright/test'); + +const { authenticatedState, checkEnv } = require('../helpers/general'); +const { + authenticateBoundaryCli, + checkBoundaryCli, + createNewOrgCli, + createNewProjectCli, + createNewControllerLedWorkerCli, + createNewPasswordAuthMethodCli, + makeAuthMethodPrimaryCli, + createNewPasswordAccountCli, + createNewRoleCli, + createNewGroupCli, + createNewUserCli, + createNewStaticHostCatalogCli, + createDynamicAwsHostCatalogCli, + createNewStaticHostCli, + createNewHostSetCli, + createNewStaticCredentialStoreCli, + createNewTcpTarget, + createNewSshTargetCli, + createNewVaultCredentialStoreCli, + createNewUsernamePasswordCredentialCli, + deleteOrgCli, +} = require('../helpers/boundary-cli'); + +const { + deleteResource, + removeAuthMethodAsPrimary, +} = require('../helpers/boundary-ui'); +const { checkVaultCli } = require('../helpers/vault-cli'); +const { execSync } = require('child_process'); + +const secretPolicyName = 'kv-policy'; +const boundaryPolicyName = 'boundary-controller'; + +test.use({ storageState: authenticatedState }); + +test.beforeAll(async () => { + await checkEnv([ + 'VAULT_ADDR', + 'VAULT_TOKEN', + 'E2E_VAULT_ADDR', + 'E2E_TARGET_ADDRESS', + 'E2E_SSH_USER', + 'E2E_SSH_KEY_PATH', + 'E2E_AWS_ACCESS_KEY_ID', + 'E2E_AWS_SECRET_ACCESS_KEY', + ]); + await checkBoundaryCli(); + await checkVaultCli(); +}); + +test.beforeEach(async () => { + execSync(`vault policy delete ${secretPolicyName}`); + execSync(`vault policy delete ${boundaryPolicyName}`); + await authenticateBoundaryCli(); +}); + +test('Verify resources can be deleted (enterprise) @ent @aws', async ({ + page, +}) => { + let orgId; + try { + orgId = await createNewOrgCli(); + let projectId = await createNewProjectCli(orgId); + + // Create boundary resources using CLI + let workerId = await createNewControllerLedWorkerCli(); + let authMethodId = await createNewPasswordAuthMethodCli(orgId); + await makeAuthMethodPrimaryCli(orgId, authMethodId); + let passwordAccountId = await createNewPasswordAccountCli(authMethodId); + let projectScopeRoleId = await createNewRoleCli(projectId); + let orgScopeRoleId = await createNewRoleCli(orgId); + let globalScopeRoleId = await createNewRoleCli('global'); + let groupId = await createNewGroupCli(orgId); + let userId = await createNewUserCli(orgId); + let staticHostCatalogId = await createNewStaticHostCatalogCli(projectId); + let dynamicAwsHostCatalogId = + await createDynamicAwsHostCatalogCli(projectId); + let staticHostId = await createNewStaticHostCli(staticHostCatalogId); + let staticHostSetId = await createNewHostSetCli(staticHostCatalogId); + let staticCredentialStoreId = + await createNewStaticCredentialStoreCli(projectId); + let vaultCredentialStoreId = await createNewVaultCredentialStoreCli( + projectId, + secretPolicyName, + boundaryPolicyName, + ); + let usernamePasswordCredentialId = + await createNewUsernamePasswordCredentialCli(staticCredentialStoreId); + let tcpTargetId = await createNewTcpTarget(projectId); + + // Create enterprise boundary resources using CLI + let sshTargetId = await createNewSshTargetCli(projectId); + + // Delete resources + await page.goto(`/scopes/${projectId}/targets/${tcpTargetId}`); + await deleteResource(page); + await page.goto( + `/scopes/${projectId}/credential-stores/${staticCredentialStoreId}/credentials/${usernamePasswordCredentialId}`, + ); + await deleteResource(page); + await page.goto( + `/scopes/${projectId}/credential-stores/${staticCredentialStoreId}`, + ); + await deleteResource(page); + await page.goto( + `/scopes/${projectId}/credential-stores/${vaultCredentialStoreId}`, + ); + await deleteResource(page); + await page.goto( + `/scopes/${projectId}/host-catalogs/${staticHostCatalogId}/host-sets/${staticHostSetId}`, + ); + await deleteResource(page); + await page.goto( + `/scopes/${projectId}/host-catalogs/${staticHostCatalogId}/hosts/${staticHostId}`, + ); + await deleteResource(page); + await page.goto( + `/scopes/${projectId}/host-catalogs/${staticHostCatalogId}`, + ); + await deleteResource(page); + await page.goto( + `/scopes/${projectId}/host-catalogs/${dynamicAwsHostCatalogId}`, + ); + await deleteResource(page); + await page.goto(`/scopes/${projectId}/users/${userId}`); + await deleteResource(page); + await page.goto(`/scopes/${projectId}/groups/${groupId}`); + await deleteResource(page); + await page.goto(`/scopes/global/roles/${globalScopeRoleId}`); + await deleteResource(page); + await page.goto(`/scopes/${projectId}/roles/${orgScopeRoleId}`); + await deleteResource(page); + await page.goto(`/scopes/${projectId}/roles/${projectScopeRoleId}`); + await deleteResource(page); + await page.goto( + `/scopes/${orgId}/auth-methods/${authMethodId}/accounts/${passwordAccountId}`, + ); + await deleteResource(page); + await page.goto(`/scopes/${orgId}/auth-methods/${authMethodId}`); + await removeAuthMethodAsPrimary(page); + await deleteResource(page); + await page.goto(`/scopes/global/workers/${workerId}`); + await deleteResource(page); + + // Delete enterprise resources + await page.goto(`/scopes/${projectId}/targets/${sshTargetId}`); + await deleteResource(page); + + // Delete project and org + await page.goto(`/scopes/${projectId}`); + await deleteResource(page); + await page.goto(`/scopes/${orgId}/edit`); + await deleteResource(page); + } finally { + await deleteOrgCli(orgId); + } +}); diff --git a/ui/admin/tests/e2e/tests/delete-resources.spec.js b/ui/admin/tests/e2e/tests/delete-resources.spec.js index 40036b3c3..5580ed9c9 100644 --- a/ui/admin/tests/e2e/tests/delete-resources.spec.js +++ b/ui/admin/tests/e2e/tests/delete-resources.spec.js @@ -25,7 +25,6 @@ const { createNewHostSetCli, createNewStaticCredentialStoreCli, createNewTcpTarget, - createNewSshTarget, createNewVaultCredentialStoreCli, createNewUsernamePasswordCredentialCli, deleteOrgCli, @@ -64,7 +63,7 @@ test.beforeEach(async () => { await authenticateBoundaryCli(); }); -test('Verify resources can be deleted @ce @aws @docker', async ({ page }) => { +test('Verify resources can be deleted @ce @aws', async ({ page }) => { let orgId; try { // Create boundary resources using CLI @@ -188,22 +187,3 @@ test('Verify resources can be deleted @ce @aws @docker', async ({ page }) => { await deleteOrgCli(orgId); } }); - -test('Verify enterprise resources can be deleted @ent @aws @docker', async ({ - page, -}) => { - let orgId; - try { - orgId = await createNewOrgCli(); - let projectId = await createNewProjectCli(orgId); - - // Create enterprise boundary resources using CLI - let sshTargetId = await createNewSshTarget(projectId); - - // Delete SSH target - await page.goto(`/scopes/${projectId}/targets/${sshTargetId}`); - await deleteResource(page); - } finally { - await deleteOrgCli(orgId); - } -}); diff --git a/ui/admin/tests/e2e/tests/target-ent.spec.js b/ui/admin/tests/e2e/tests/target-ent.spec.js new file mode 100644 index 000000000..ba98afd66 --- /dev/null +++ b/ui/admin/tests/e2e/tests/target-ent.spec.js @@ -0,0 +1,127 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +/* eslint-disable no-undef */ +const { test } = require('@playwright/test'); +const { execSync } = require('child_process'); +const { checkEnv, authenticatedState } = require('../helpers/general'); +const { + authenticateBoundaryCli, + checkBoundaryCli, + connectToTarget, + connectSshToTarget, + deleteOrgCli, +} = require('../helpers/boundary-cli'); +const { + createNewOrg, + createNewProject, + createStaticCredentialStore, + createStaticCredentialKeyPair, + addInjectedCredentialsToTarget, + createTcpTargetWithAddressEnt, + createSshTargetWithAddressEnt, + waitForSessionToBeVisible, +} = require('../helpers/boundary-ui'); + +test.use({ storageState: authenticatedState }); + +test.beforeAll(async () => { + await checkEnv([ + 'E2E_SSH_USER', + 'E2E_SSH_KEY_PATH', + 'E2E_TARGET_ADDRESS', + 'E2E_TARGET_PORT', + ]); + + await checkBoundaryCli(); +}); + +test('Verify session created for TCP target @ent @aws @docker', async ({ + page, +}) => { + await page.goto('/'); + let org; + let connect; + try { + const orgName = await createNewOrg(page); + await authenticateBoundaryCli(); + const orgs = JSON.parse(execSync('boundary scopes list -format json')); + org = orgs.items.filter((obj) => obj.name == orgName)[0]; + + const projectName = await createNewProject(page); + const projects = JSON.parse( + execSync('boundary scopes list -format json -scope-id ' + org.id), + ); + const project = projects.items.filter((obj) => obj.name == projectName)[0]; + + const targetName = await createTcpTargetWithAddressEnt(page); + const targets = JSON.parse( + execSync('boundary targets list -format json -scope-id ' + project.id), + ); + const target = targets.items.filter((obj) => obj.name == targetName)[0]; + + connect = await connectToTarget(target.id); + await waitForSessionToBeVisible(page, targetName); + await page + .getByRole('cell', { name: targetName }) + .locator('..') + .getByRole('button', { name: 'Cancel' }) + .click(); + } finally { + if (org) { + await deleteOrgCli(org.id); + } + // End `boundary connect` process + if (connect) { + connect.kill('SIGTERM'); + } + } +}); + +test('Verify session created for SSH target @ent @aws @docker', async ({ + page, +}) => { + await page.goto('/'); + let org; + let connect; + try { + const orgName = await createNewOrg(page); + await authenticateBoundaryCli(); + const orgs = JSON.parse(execSync('boundary scopes list -format json')); + org = orgs.items.filter((obj) => obj.name == orgName)[0]; + + const projectName = await createNewProject(page); + const projects = JSON.parse( + execSync('boundary scopes list -format json -scope-id ' + org.id), + ); + const project = projects.items.filter((obj) => obj.name == projectName)[0]; + + const targetName = await createSshTargetWithAddressEnt(page); + const targets = JSON.parse( + execSync('boundary targets list -format json -scope-id ' + project.id), + ); + const target = targets.items.filter((obj) => obj.name == targetName)[0]; + + await createStaticCredentialStore(page); + const credentialName = await createStaticCredentialKeyPair(page); + await addInjectedCredentialsToTarget(page, targetName, credentialName); + + connect = await connectSshToTarget(target.id); + await waitForSessionToBeVisible(page, targetName); + await page + .getByRole('cell', { name: targetName }) + .locator('..') + .getByRole('button', { name: 'Cancel' }) + .click(); + } finally { + if (org) { + await deleteOrgCli(org.id); + } + // End `boundary connect` process + if (connect) { + connect.kill('SIGTERM'); + } + } +});