Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkim-det committed Oct 24, 2024
1 parent 6f9634b commit 8cbd13f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 20 deletions.
3 changes: 0 additions & 3 deletions .circleci/devcluster/react-rbac.devcluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ stages:
initial_user_password: $INITIAL_USER_PASSWORD
authz:
rbac_ui_enabled: true
workspace_creator_assign_role:
enabled: true
role_id: 1
port: 8082
db:
host: localhost
Expand Down
3 changes: 2 additions & 1 deletion webui/react/src/e2e/fixtures/auth.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Page } from '@playwright/test';
import { expect } from 'e2e/fixtures/global-fixtures';
import { SignIn } from 'e2e/models/pages/SignIn';
import { password, username } from 'e2e/utils/envVars';
import { defaultURL } from 'e2e/utils/pages';

export class AuthFixture {
readonly #page: Page;
Expand All @@ -18,7 +19,7 @@ export class AuthFixture {
}

async login({
expectedURL = /dashboard/,
expectedURL = defaultURL,
username = this.#USERNAME,
password = this.#PASSWORD,
}: {
Expand Down
27 changes: 16 additions & 11 deletions webui/react/src/e2e/fixtures/user.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from 'e2e/fixtures/global-fixtures';
import { UserManagement } from 'e2e/models/pages/Admin/UserManagement';
import { safeName } from 'e2e/utils/naming';
import { repeatWithFallback } from 'e2e/utils/polling';
import { isRbacEnabled } from 'e2e/utils/rbac';
import { TestUser } from 'e2e/utils/users';

interface CreateUserFields {
Expand Down Expand Up @@ -43,16 +44,18 @@ export class UserFixture {
);
}

const checkedAttribute =
await this.userManagementPage.createUserModal.adminToggle.pwLocator.getAttribute(
'aria-checked',
);
if (checkedAttribute === null) {
throw new Error('Expected attribute aria-checked to be present.');
}
const adminState = JSON.parse(checkedAttribute);
if (!!formValues.admin !== adminState) {
await this.userManagementPage.createUserModal.adminToggle.pwLocator.click();
if (!isRbacEnabled()) {
const checkedAttribute =
await this.userManagementPage.createUserModal.adminToggle.pwLocator.getAttribute(
'aria-checked',
);
if (checkedAttribute === null) {
throw new Error('Expected attribute aria-checked to be present.');
}
const adminState = JSON.parse(checkedAttribute);
if (!!formValues.admin !== adminState) {
await this.userManagementPage.createUserModal.adminToggle.pwLocator.click();
}
}

// password and username are required to create a user; if these are filled, submit should be enabled
Expand Down Expand Up @@ -180,7 +183,9 @@ export class UserFixture {
} else {
await row.user.alias.pwLocator.waitFor({ state: 'hidden' });
}
await expect(row.role.pwLocator).toContainText(user.admin ? 'Admin' : 'Member');
if (!isRbacEnabled()) {
await expect(row.role.pwLocator).toContainText(user.admin ? 'Admin' : 'Member');
}
await expect(row.status.pwLocator).toContainText(user.active ? 'Active' : 'Inactive');
}

Expand Down
5 changes: 3 additions & 2 deletions webui/react/src/e2e/tests/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from 'e2e/fixtures/global-fixtures';
import { Cluster } from 'e2e/models/pages/Cluster';
import { SignIn } from 'e2e/models/pages/SignIn';
import { defaultTitle, defaultURL } from 'e2e/utils/pages';

test.describe('Authentication', () => {
test.afterEach(async ({ page, auth }) => {
Expand All @@ -13,8 +14,8 @@ test.describe('Authentication', () => {
test('Login and Logout', async ({ page, auth }) => {
await test.step('Login', async () => {
await auth.login();
await expect(page).toHaveDeterminedTitle('Home');
await expect(page).toHaveURL(/dashboard/);
await expect(page).toHaveDeterminedTitle(defaultTitle);
await expect(page).toHaveURL(defaultURL);
});

await test.step('Logout', async () => {
Expand Down
5 changes: 2 additions & 3 deletions webui/react/src/e2e/tests/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ test.describe('Navigation', () => {
// we need any page to access the sidebar, and i haven't modeled the homepage yet
const userManagementPage = new UserManagement(authedPage);

await test.step('Login steps', async () => {
await expect(authedPage).toHaveDeterminedTitle('Home');
await expect(authedPage).toHaveURL(/dashboard/);
await test.step('Load page', async () => {
await userManagementPage.goto();
});

await test.step('Uncategorized', async () => {
Expand Down
5 changes: 5 additions & 0 deletions webui/react/src/e2e/utils/pages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { isRbacEnabled } from 'e2e/utils/rbac';

export const defaultURL = isRbacEnabled() ? /workspaces/ : /dashboard/;

export const defaultTitle = isRbacEnabled() ? 'Workspaces' : 'Home';
18 changes: 18 additions & 0 deletions webui/react/src/e2e/utils/rbac.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { detExecSync } from 'e2e/utils/detCLI';

let rbacEnabled: boolean;

const getRbacEnabled = (): boolean => {
const masterInfo = detExecSync('master info');
const regexp = /rbacEnabled:\s*(?<enabled>true|false)/;

const { groups } = regexp.exec(masterInfo) || {};

return groups?.enabled === 'true';
};

export const isRbacEnabled = (): boolean => {
if (rbacEnabled === undefined) rbacEnabled = getRbacEnabled();

return rbacEnabled;
};

0 comments on commit 8cbd13f

Please sign in to comment.