Files
threshold-ui/e2e-tests/admin/tests/delete-resources.spec.js
T
Michael Li 1cbf3b227e test(e2e): Add additional assertions to UI tests (#2634)
* test(e2e): Address deprecation

* test(e2e): Add additional connection assertions on tests

* CR: Fix flake when waiting for sessions

If no sessions are available and the page needs to reload, we should wait to ensure that the page has loaded before checking what the state of the sessions are

* CR: Address flake in connect methods

Noticed an issue where a session recording was not playable. The theory is that the session didn't last long enough before it was cancelled. This adds a 2 second wait after establishing a connection before continuing.

* CR: Use authenticated state by default

* CR: Update dynamic host catalog assertion

* CR: Simplify host set checks

- Use .all() when looping
- Add check to see if we need to reload the page or not

* CR: Be more specific with locator

Ran into a conflict with the Static/Dynamic host catalog type and the Static/Dynamic credential type.

* CR: Update connection methods to be more resilient

Rather than using a hardcoded sleep, we will now run a command on the target and wait for a specific string to return before continuing.

* CR
2025-01-06 11:40:32 -05:00

187 lines
6.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { test } from '../../global-setup.js';
import { execSync } from 'node:child_process';
import * as boundaryCli from '../../helpers/boundary-cli';
import * as vaultCli from '../../helpers/vault-cli';
import { AuthMethodsPage } from '../pages/auth-methods.js';
import { BaseResourcePage } from '../pages/base-resource.js';
import { WorkersPage } from '../pages/workers.js';
const secretPolicyName = 'kv-policy';
const boundaryPolicyName = 'boundary-controller';
// Setting the test timeout to 180s
// This test can often exceed the globally defined timeout due to the number of
// network calls.
test.setTimeout(180000);
test.beforeAll(async () => {
await boundaryCli.checkBoundaryCli();
await vaultCli.checkVaultCli();
});
test.beforeEach(
async ({ baseURL, adminAuthMethodId, adminLoginName, adminPassword }) => {
execSync(`vault policy delete ${secretPolicyName}`);
execSync(`vault policy delete ${boundaryPolicyName}`);
await boundaryCli.authenticateBoundary(
baseURL,
adminAuthMethodId,
adminLoginName,
adminPassword,
);
},
);
test('Verify resources can be deleted @ce @aws', async ({
page,
awsRegion,
vaultAddr,
}) => {
let orgId;
let orgDeleted = false;
try {
// Create boundary resources using CLI
orgId = await boundaryCli.createOrg();
let projectId = await boundaryCli.createProject(orgId);
let workerId = await boundaryCli.createControllerLedWorker();
let authMethodId = await boundaryCli.createPasswordAuthMethod(orgId);
await boundaryCli.makeAuthMethodPrimary(orgId, authMethodId);
let passwordAccountId =
await boundaryCli.createPasswordAccount(authMethodId);
let projectScopeRoleId = await boundaryCli.createRole(projectId);
let orgScopeRoleId = await boundaryCli.createRole(orgId);
let globalScopeRoleId = await boundaryCli.createRole('global');
let groupId = await boundaryCli.createGroup(orgId);
let userId = await boundaryCli.createUser(orgId);
let staticHostCatalogId =
await boundaryCli.createStaticHostCatalog(projectId);
let dynamicAwsHostCatalogId = await boundaryCli.createDynamicAwsHostCatalog(
projectId,
awsRegion,
);
let staticHostId = await boundaryCli.createStaticHost(staticHostCatalogId);
let staticHostSetId = await boundaryCli.createHostSet(staticHostCatalogId);
let staticCredentialStoreId =
await boundaryCli.createStaticCredentialStore(projectId);
const vaultToken = await vaultCli.getVaultToken(
boundaryPolicyName,
secretPolicyName,
);
let vaultCredentialStoreId = await boundaryCli.createVaultCredentialStore(
projectId,
vaultAddr,
vaultToken,
);
let usernamePasswordCredentialId =
await boundaryCli.createUsernamePasswordCredential(
staticCredentialStoreId,
);
let tcpTargetId = await boundaryCli.createTcpTarget(projectId);
const baseResourcePage = new BaseResourcePage(page);
// Delete TCP target
await page.goto(`/scopes/${projectId}/targets/${tcpTargetId}`);
await baseResourcePage.deleteResource(page);
// Delete username-password credentials
await page.goto(
`/scopes/${projectId}/credential-stores/${staticCredentialStoreId}/credentials/${usernamePasswordCredentialId}`,
);
await baseResourcePage.deleteResource(page);
// Delete static credential store
await page.goto(
`/scopes/${projectId}/credential-stores/${staticCredentialStoreId}`,
);
await baseResourcePage.deleteResource(page);
// Delete vault credential store
await page.goto(
`/scopes/${projectId}/credential-stores/${vaultCredentialStoreId}`,
);
await baseResourcePage.deleteResource(page);
// Delete static host set
await page.goto(
`/scopes/${projectId}/host-catalogs/${staticHostCatalogId}/host-sets/${staticHostSetId}`,
);
await baseResourcePage.deleteResource(page);
// Delete static host
await page.goto(
`/scopes/${projectId}/host-catalogs/${staticHostCatalogId}/hosts/${staticHostId}`,
);
await baseResourcePage.deleteResource(page);
// Delete static host catalog
await page.goto(
`/scopes/${projectId}/host-catalogs/${staticHostCatalogId}`,
);
await baseResourcePage.deleteResource(page);
// Delete dynamic aws host catalog
await page.goto(
`/scopes/${projectId}/host-catalogs/${dynamicAwsHostCatalogId}`,
);
await baseResourcePage.deleteResource(page);
// Delete user
await page.goto(`/scopes/${projectId}/users/${userId}`);
await baseResourcePage.deleteResource(page);
// Delete group
await page.goto(`/scopes/${projectId}/groups/${groupId}`);
await baseResourcePage.deleteResource(page);
// Delete role under global scope
await page.goto(`/scopes/global/roles/${globalScopeRoleId}`);
await baseResourcePage.deleteResource(page);
// Delete role under org scope
await page.goto(`/scopes/${projectId}/roles/${orgScopeRoleId}`);
await baseResourcePage.deleteResource(page);
// Delete role under project scope
await page.goto(`/scopes/${projectId}/roles/${projectScopeRoleId}`);
await baseResourcePage.deleteResource(page);
// Delete password account
await page.goto(
`/scopes/${orgId}/auth-methods/${authMethodId}/accounts/${passwordAccountId}`,
);
await baseResourcePage.deleteResource(page);
// Delete auth method
await page.goto(`/scopes/${orgId}/auth-methods/${authMethodId}`);
const authMethodsPage = new AuthMethodsPage(page);
await authMethodsPage.removeAuthMethodAsPrimary();
await baseResourcePage.deleteResource(page);
// Delete worker
await page.goto(`/scopes/global/workers/${workerId}`);
const workersPage = new WorkersPage(page);
await workersPage.deleteResource(page);
// Delete project
await page.goto(`/scopes/${projectId}`);
await baseResourcePage.deleteResource(page);
// Delete org
await page.goto(`/scopes/${orgId}/edit`);
await baseResourcePage.deleteResource(page);
orgDeleted = true;
} finally {
// Delete org in case the test failed before deleting the org using UI
if (orgId && orgDeleted === false) {
await boundaryCli.deleteScope(orgId);
}
}
});