test: 💍 Refactor target functions and fix failing test (#2999)

* test: 💍 Fixed broken test 

* test: 💍 Refactoring to consolidate target function names

* test: 💍 fixed failing tests with capitalization issue
This commit is contained in:
dillanb-hashi authored and GitHub committed 2025-09-30 09:35:26 -07:00
1 parent 72639bd6a3
commit ea591df0bb
15 files changed
+120 -393

No files matched your search

+20 -315
View File
@@ -9,73 +9,15 @@ import { nanoid } from 'nanoid';
import { BaseResourcePage } from './base-resource.js';
export class TargetsPage extends BaseResourcePage {
/**
* Creates a new target. Assumes you have selected the desired project.
* @param {string} port Port of the target
* @returns Name of the target
*/
async createTarget(port) {
const targetName = 'Target ' + nanoid();
await this.page
.getByRole('navigation', { name: 'Application local navigation' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page.getByLabel('Default Port').fill(port);
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Creates a new target with address. Assumes you have selected the desired project.
* @param {string} address Address of the target
* @param {string} port Port of the target
* @returns Name of the target
*/
async createTargetWithAddress(address, port) {
const targetName = 'Target ' + nanoid();
await this.page
.getByRole('navigation', { name: 'Application local navigation' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page.getByLabel('Target Address').fill(address);
await this.page.getByLabel('Default Port').fill(port);
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Creates a new target with address and alias. Assumes you have selected the desired project.
* @param {string} targetType Type of target (ssh, rdp, tcp)
* @param {string} address Address of the target
* @param {string} port Port of the target
* @param {string} alias alias used for the target
* @returns Name of the target
*/
async createTargetWithAddressAndAlias(
address,
port,
alias,
targetType = 'tcp',
) {
async createTarget({ targetType, port, address, alias }) {
const targetName = 'Target ' + nanoid();
let targetTypeLabel;
@@ -92,9 +34,6 @@ export class TargetsPage extends BaseResourcePage {
targetTypeLabel = 'Generic TCP';
break;
}
default: {
throw new Error(`Unexpected target type passed ${targetType}`);
}
}
await this.page
@@ -104,258 +43,24 @@ export class TargetsPage extends BaseResourcePage {
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page.getByLabel(targetTypeLabel).click();
await this.page.getByLabel('Target Address').fill(address);
await this.page.getByLabel('Default Port').fill(port);
await this.page
.getByRole('group', { name: 'Aliases' })
.getByLabel('value')
.last()
.fill(alias);
await this.page.getByRole('button', { name: 'Add' }).click();
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Creates a new TCP target with address in boundary-enterprise
* Assumes you have selected the desired project.
* @param {string} address Address of the target
* @param {string} port Port of the target
* @returns Name of the target
*/
async createTcpTargetWithAddressEnt(address, port) {
const targetName = 'Target ' + nanoid();
await this.page
.getByRole('navigation', { name: 'Application local navigation' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page
.getByRole('group', { name: 'Type' })
.getByLabel('TCP')
.click();
await this.page.getByLabel('Target Address').fill(address);
await this.page.getByLabel('Default Port').fill(port);
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Creates a new SSH target. Assumes you have selected the desired project.
* @param {string} port Port of the target
* @returns Name of the target
*/
async createSshTargetEnt(port) {
const targetName = 'Target ' + nanoid();
await this.page
.getByRole('navigation', { name: 'Application local navigation' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page
.getByRole('group', { name: 'Type' })
.getByLabel('SSH')
.click();
await this.page.getByLabel('Default Port').fill(port);
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Creates a new SSH target with address in boundary-enterprise
* Assumes you have selected the desired project.
* @param {string} address Address of the target
* @param {string} port Port of the target
* @returns Name of the target
*/
async createSshTargetWithAddressEnt(address, port) {
const targetName = 'Target ' + nanoid();
await this.page
.getByRole('navigation', { name: 'Application local navigation' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page
.getByRole('group', { name: 'Type' })
.getByLabel('SSH')
.click();
await this.page.getByLabel('Target Address').fill(address);
await this.page.getByLabel('Default Port').fill(port);
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Creates a new SSH target with address and alias.
* Assumes you have selected the desired project.
* @param {string} address Address of the target
* @param {string} port Port of the target
* @param {string} alias alias used for the target
* @returns Name of the target
*/
async createSshTargetWithAddressAndAlias(address, port, alias) {
const targetName = 'Target ' + nanoid();
await this.page
.getByRole('navigation', { name: 'Application local navigation' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page
.getByRole('group', { name: 'Type' })
.getByLabel('SSH')
.click();
await this.page.getByLabel('Target Address').fill(address);
await this.page.getByLabel('Default Port').fill(port);
await this.page
.getByRole('group', { name: 'Aliases' })
.getByLabel('value')
.last()
.fill(alias);
await this.page.getByRole('button', { name: 'Add' }).click();
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Creates a new RDP target.
* Assumes you have selected the desired project.
* @param {string} port Port of the target
* @returns Name of the target
*/
async createRdpTargetEnt(port) {
const targetName = 'Target ' + nanoid();
await this.page
.getByRole('navigation', { name: 'Application local navigation' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page
.getByRole('group', { name: 'Type' })
.getByLabel('RDP')
.click();
await this.page.getByLabel('Default Port').fill(port);
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Creates a new RDP target with address in boundary-enterprise
* Assumes you have selected the desired project.
* @param {string} address Address of the target
* @param {string} port Port of the target
* @returns Name of the target
*/
async createRDPTargetWithAddressEnt(address, port) {
const targetName = 'Target ' + nanoid();
await this.page
.getByRole('navigation', { name: 'Application local navigation' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page
.getByRole('group', { name: 'Type' })
.getByLabel('RDP')
.click();
await this.page.getByLabel('Target Address').fill(address);
await this.page.getByLabel('Default Port').fill(port);
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Creates a new RDP target with address and alias.
* Assumes you have selected the desired project.
* @param {string} address Address of the target
* @param {string} port Port of the target
* @param {string} alias alias used for the target
* @returns Name of the target
*/
async createRdpTargetWithAddressAndAlias(address, port, alias) {
const targetName = 'Target ' + nanoid();
await this.page
.getByRole('navigation', { name: 'Application local navigation' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page
.getByRole('group', { name: 'Type' })
.getByLabel('RDP')
.click();
await this.page.getByLabel('Target Address').fill(address);
await this.page.getByLabel('Default Port').fill(port);
await this.page
.getByRole('group', { name: 'Aliases' })
.getByLabel('value')
.last()
.fill(alias);
await this.page.getByRole('button', { name: 'Add' }).click();
if (targetType) {
if (targetTypeLabel)
await this.page
.getByRole('group', { name: 'Type' })
.getByLabel(targetTypeLabel)
.click();
else throw new Error(`Unsupported target type: ${targetType}`);
}
if (address) await this.page.getByLabel('Target Address').fill(address);
if (port) await this.page.getByLabel('Default Port').fill(port);
if (alias) {
await this.page
.getByRole('group', { name: 'Aliases' })
.getByLabel('value')
.last()
.fill(alias);
await this.page.getByRole('button', { name: 'Add' }).click();
}
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
+15 -13
View File
@@ -46,10 +46,11 @@ test.describe('Aliases (Enterprise)', () => {
await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
});
const credentialStoresPage = new CredentialStoresPage(page);
await credentialStoresPage.createStaticCredentialStore();
const credentialName =
@@ -165,12 +166,12 @@ test.describe('Aliases (Enterprise)', () => {
await projectsPage.createProject();
alias = 'example.alias.' + nanoid();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTargetWithAddressAndAlias(
targetAddress,
targetPort,
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
alias,
'ssh',
);
});
const credentialStoresPage = new CredentialStoresPage(page);
await credentialStoresPage.createStaticCredentialStore();
const credentialName =
@@ -236,10 +237,11 @@ test.describe('Aliases (Enterprise)', () => {
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
});
const credentialStoresPage = new CredentialStoresPage(page);
await credentialStoresPage.createStaticCredentialStore();
const credentialName =
+12 -12
View File
@@ -44,10 +44,10 @@ test.describe('Aliases', () => {
const projectsPage = new ProjectsPage(page);
await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTargetWithAddress(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
port: targetPort,
address: targetAddress,
});
// Create alias for target
const aliasName = 'Alias ' + nanoid();
@@ -148,11 +148,11 @@ test.describe('Aliases', () => {
await projectsPage.createProject();
alias = 'example.alias.' + nanoid();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTargetWithAddressAndAlias(
targetAddress,
targetPort,
const targetName = await targetsPage.createTarget({
port: targetPort,
address: targetAddress,
alias,
);
});
// Connect to target using alias
connect = await boundaryCli.connectToAlias(alias, sshUser, sshKeyPath);
@@ -206,10 +206,10 @@ test.describe('Aliases', () => {
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTargetWithAddress(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
port: targetPort,
address: targetAddress,
});
// Create new alias from scope page
await boundaryCli.authenticateBoundary(
@@ -41,10 +41,11 @@ test(
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
});
const credentialStoresPage = new CredentialStoresPage(page);
await credentialStoresPage.createStaticCredentialStore();
const credentialName =
@@ -31,10 +31,10 @@ test.beforeEach(async ({ page, targetAddress, targetPort }) => {
const projectsPage = new ProjectsPage(page);
projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
targetName = await targetsPage.createTargetWithAddress(
targetAddress,
targetPort,
);
targetName = await targetsPage.createTarget({
port: targetPort,
address: targetAddress,
});
const credentialStoresPage = new CredentialStoresPage(page);
await credentialStoresPage.createStaticCredentialStore();
});
@@ -68,10 +68,11 @@ test(
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
});
const credentialStoresPage = new CredentialStoresPage(page);
await credentialStoresPage.createVaultCredentialStoreWithWorkerFilter(
vaultAddrPrivate,
@@ -85,10 +85,10 @@ test(
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTargetWithAddress(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
port: targetPort,
address: targetAddress,
});
const credentialStoresPage = new CredentialStoresPage(page);
await credentialStoresPage.createVaultCredentialStore(
vaultAddr,
@@ -156,7 +156,10 @@ test.describe('AWS', () => {
// Create a target and add DHC host set as a host source
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetEnt(targetPort);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
});
await targetsPage.addHostSourceToTarget(hostSetName);
// Add another host source
@@ -156,7 +156,9 @@ test.describe('AWS', () => {
// Create a target and add DHC host set as a host source
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTarget(targetPort);
const targetName = await targetsPage.createTarget({
port: targetPort,
});
await targetsPage.addHostSourceToTarget(hostSetName);
// Add another host source
@@ -93,10 +93,11 @@ test(
await page.getByRole('link', { name: orgName }).click();
await page.getByRole('link', { name: projectName }).click();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
});
await targetsPage.addEgressWorkerFilterToTarget(
`"${workerTagEgress}" in "/tags/type"`,
);
@@ -97,10 +97,11 @@ test(
await page.getByRole('link', { name: orgName }).click();
await page.getByRole('link', { name: projectName }).click();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
});
await targetsPage.addIngressWorkerFilterToTarget(
`"${workerTagEgress}" in "/tags/type"`,
);
@@ -99,10 +99,11 @@ test(
// Create target
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
});
// Create credentials
const credentialStoresPage = new CredentialStoresPage(page);
@@ -89,10 +89,11 @@ test(
// Create target
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
});
// Create credentials
const credentialStoresPage = new CredentialStoresPage(page);
+19 -13
View File
@@ -41,10 +41,11 @@ test(
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTcpTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'tcp',
port: targetPort,
address: targetAddress,
});
await boundaryCli.authenticateBoundary(
controllerAddr,
@@ -108,10 +109,11 @@ test(
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetWithAddressEnt(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
address: targetAddress,
});
const credentialStoresPage = new CredentialStoresPage(page);
await credentialStoresPage.createStaticCredentialStore();
const credentialName =
@@ -194,7 +196,10 @@ test(
// Create target
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createSshTargetEnt(targetPort);
const targetName = await targetsPage.createTarget({
targetType: 'ssh',
port: targetPort,
});
await targetsPage.addHostSourceToTarget(hostSetName);
// Add/Remove another host source
@@ -285,10 +290,11 @@ test(
);
const targetsPage = new TargetsPage(page);
const rdpTarget = await targetsPage.createRDPTargetWithAddressEnt(
targetAddress,
targetPort,
);
const rdpTarget = await targetsPage.createTarget({
targetType: 'rdp',
port: targetPort,
address: targetAddress,
});
await targetsPage.addBrokeredCredentialsToTarget(
rdpTarget,
credentialName,
+9 -6
View File
@@ -57,7 +57,7 @@ test(
// Create target
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTarget(targetPort);
const targetName = await targetsPage.createTarget({ port: targetPort });
await targetsPage.addHostSourceToTarget(hostSetName);
// Add/Remove another host source
@@ -127,10 +127,10 @@ test(
const projectsPage = new ProjectsPage(page);
const projectName = await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
const targetName = await targetsPage.createTargetWithAddress(
targetAddress,
targetPort,
);
const targetName = await targetsPage.createTarget({
port: targetPort,
address: targetAddress,
});
await boundaryCli.authenticateBoundary(
controllerAddr,
@@ -191,7 +191,10 @@ test(
const projectsPage = new ProjectsPage(page);
await projectsPage.createProject();
const targetsPage = new TargetsPage(page);
await targetsPage.createTargetWithAddress(targetAddress, targetPort);
await targetsPage.createTarget({
port: targetPort,
address: targetAddress,
});
// Update target
await page.getByRole('button', { name: 'Edit Form' }).click();