diff --git a/.circleci/devcluster/react-rbac.devcluster.yaml b/.circleci/devcluster/react-rbac.devcluster.yaml index 6a2631a6fcc6..af6fb92f9c17 100644 --- a/.circleci/devcluster/react-rbac.devcluster.yaml +++ b/.circleci/devcluster/react-rbac.devcluster.yaml @@ -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 diff --git a/webui/react/src/e2e/fixtures/auth.fixture.ts b/webui/react/src/e2e/fixtures/auth.fixture.ts index b85007f3c5c9..b4b1dad28b93 100644 --- a/webui/react/src/e2e/fixtures/auth.fixture.ts +++ b/webui/react/src/e2e/fixtures/auth.fixture.ts @@ -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; @@ -18,7 +19,7 @@ export class AuthFixture { } async login({ - expectedURL = /dashboard/, + expectedURL = defaultURL, username = this.#USERNAME, password = this.#PASSWORD, }: { diff --git a/webui/react/src/e2e/fixtures/user.fixture.ts b/webui/react/src/e2e/fixtures/user.fixture.ts index a941c5013aae..4f5982a334d4 100644 --- a/webui/react/src/e2e/fixtures/user.fixture.ts +++ b/webui/react/src/e2e/fixtures/user.fixture.ts @@ -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 { @@ -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 @@ -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'); } diff --git a/webui/react/src/e2e/tests/auth.spec.ts b/webui/react/src/e2e/tests/auth.spec.ts index 01cbe9012661..add105013afb 100644 --- a/webui/react/src/e2e/tests/auth.spec.ts +++ b/webui/react/src/e2e/tests/auth.spec.ts @@ -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 }) => { @@ -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 () => { diff --git a/webui/react/src/e2e/tests/navigation.spec.ts b/webui/react/src/e2e/tests/navigation.spec.ts index 23b8b3ebaad2..7217b902e292 100644 --- a/webui/react/src/e2e/tests/navigation.spec.ts +++ b/webui/react/src/e2e/tests/navigation.spec.ts @@ -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 () => { diff --git a/webui/react/src/e2e/utils/pages.ts b/webui/react/src/e2e/utils/pages.ts new file mode 100644 index 000000000000..85f8c483fcf1 --- /dev/null +++ b/webui/react/src/e2e/utils/pages.ts @@ -0,0 +1,5 @@ +import { isRbacEnabled } from 'e2e/utils/rbac'; + +export const defaultURL = isRbacEnabled() ? /workspaces/ : /dashboard/; + +export const defaultTitle = isRbacEnabled() ? 'Workspaces' : 'Home'; diff --git a/webui/react/src/e2e/utils/rbac.ts b/webui/react/src/e2e/utils/rbac.ts new file mode 100644 index 000000000000..2af45c09ca00 --- /dev/null +++ b/webui/react/src/e2e/utils/rbac.ts @@ -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*(?true|false)/; + + const { groups } = regexp.exec(masterInfo) || {}; + + return groups?.enabled === 'true'; +}; + +export const isRbacEnabled = (): boolean => { + if (rbacEnabled === undefined) rbacEnabled = getRbacEnabled(); + + return rbacEnabled; +};