Files
threshold-ui/ui/admin/tests/e2e/tests/target.spec.js
T
Michael Li 45c16252a7 refact(e2e): Update Admin UI tests to use Page Objects (#2426)
* refact(e2e): Use page object methods

* refact(e2e): Create base page class
2024-08-06 13:15:00 -04:00

227 lines
7.4 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
/* eslint-disable no-undef */
const { test, expect } = require('@playwright/test');
const { execSync } = require('child_process');
const { checkEnv, authenticatedState } = require('../helpers/general');
const {
authenticateBoundaryCli,
checkBoundaryCli,
connectToTarget,
deleteOrgCli,
} = require('../helpers/boundary-cli');
const HostCatalogsPage = require('../pages/host-catalogs');
const OrgsPage = require('../pages/orgs');
const ProjectsPage = require('../pages/projects');
const SessionsPage = require('../pages/sessions');
const TargetsPage = require('../pages/targets');
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 to target with host, then cancel the session @ce @aws @docker', async ({
page,
}) => {
await page.goto('/');
let org;
let connect;
try {
const orgsPage = new OrgsPage(page);
const orgName = await orgsPage.createOrg();
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
// Create host set
const hostCatalogsPage = new HostCatalogsPage(page);
const hostCatalogName = await hostCatalogsPage.createHostCatalog();
const hostSetName = await hostCatalogsPage.createHostSet();
await hostCatalogsPage.createHostInHostSet(process.env.E2E_TARGET_ADDRESS);
// Create another host set
await page
.getByRole('navigation', { name: 'Resources' })
.getByRole('link', { name: 'Host Catalogs' })
.click();
await page.getByRole('link', { name: hostCatalogName }).click();
const hostSetName2 = await hostCatalogsPage.createHostSet();
// Create target
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTarget(
process.env.E2E_TARGET_PORT,
);
await targetsPage.addHostSourceToTarget(hostSetName);
// Add/Remove another host source
await targetsPage.addHostSourceToTarget(hostSetName2);
await page
.getByRole('link', { name: hostSetName2 })
.locator('..')
.locator('..')
.getByRole('button', { name: 'Manage' })
.click();
await page.getByRole('button', { name: 'Remove' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
await expect(
page.getByRole('alert').getByText('Success', { exact: true }),
).toBeVisible();
await page.getByRole('button', { name: 'Dismiss' }).click();
// Connect to target
await authenticateBoundaryCli(
process.env.BOUNDARY_ADDR,
process.env.E2E_PASSWORD_AUTH_METHOD_ID,
process.env.E2E_PASSWORD_ADMIN_LOGIN_NAME,
process.env.E2E_PASSWORD_ADMIN_PASSWORD,
);
const orgs = JSON.parse(execSync('boundary scopes list -format json'));
org = orgs.items.filter((obj) => obj.name == orgName)[0];
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 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,
process.env.E2E_SSH_USER,
process.env.E2E_SSH_KEY_PATH,
);
const sessionsPage = new SessionsPage(page);
await sessionsPage.waitForSessionToBeVisible(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 to target with address, then cancel the session @ce @aws @docker', async ({
page,
}) => {
await page.goto('/');
let org;
let connect;
try {
const orgsPage = new OrgsPage(page);
const orgName = await orgsPage.createOrg();
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTargetWithAddress(
process.env.E2E_TARGET_ADDRESS,
process.env.E2E_TARGET_PORT,
);
await authenticateBoundaryCli(
process.env.BOUNDARY_ADDR,
process.env.E2E_PASSWORD_AUTH_METHOD_ID,
process.env.E2E_PASSWORD_ADMIN_LOGIN_NAME,
process.env.E2E_PASSWORD_ADMIN_PASSWORD,
);
const orgs = JSON.parse(execSync('boundary scopes list -format json'));
org = orgs.items.filter((obj) => obj.name == orgName)[0];
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 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,
process.env.E2E_SSH_USER,
process.env.E2E_SSH_KEY_PATH,
);
const sessionsPage = new SessionsPage(page);
await sessionsPage.waitForSessionToBeVisible(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 TCP target is updated @ce @aws @docker', async ({ page }) => {
await page.goto('/');
let orgName;
try {
const orgsPage = new OrgsPage(page);
orgName = await orgsPage.createOrg();
const projectsPage = new ProjectsPage(page);
await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
await targetsPage.createTargetWithAddress(
process.env.E2E_TARGET_ADDRESS,
process.env.E2E_TARGET_PORT,
);
// Update target
await page.getByRole('button', { name: 'Edit Form' }).click();
await page.getByLabel('Name').fill('New target name');
await page.getByLabel('Description').fill('New description');
await page.getByLabel('Target Address').fill('127.0.0.1');
await page.getByLabel('Default Port').fill('10');
await page.getByLabel('Default Client Port').fill('10');
await page.getByLabel('Maximum Duration').fill('1000');
await page.getByLabel('Maximum Connections').fill('10');
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 targetsPage.addEgressWorkerFilterToTarget('"dev" in "/tags/type"');
} finally {
await authenticateBoundaryCli(
process.env.BOUNDARY_ADDR,
process.env.E2E_PASSWORD_AUTH_METHOD_ID,
process.env.E2E_PASSWORD_ADMIN_LOGIN_NAME,
process.env.E2E_PASSWORD_ADMIN_PASSWORD,
);
const orgs = JSON.parse(execSync('boundary scopes list -format json'));
const org = orgs.items.filter((obj) => obj.name === orgName)[0];
if (org) {
await deleteOrgCli(org.id);
}
}
});