Skip to content

HMS-5999: QE: migrate iqe test_rbac_for_repos #515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
73 changes: 73 additions & 0 deletions _playwright-tests/UI/TwoUserRBAC.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { test, expect } from '@playwright/test';
import { navigateToRepositories } from './helpers/navHelpers';
import { deleteAllRepos } from './helpers/deleteRepositories';

Check failure on line 3 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'deleteAllRepos' is defined but never used

Check failure on line 3 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'deleteAllRepos' is defined but never used
import { closePopupsIfExist, getRowByNameOrUrl } from './helpers/helpers';
import { logInWithUsernameAndPassword, logout, logInWithUser1 } from "../helpers/loginHelpers";

Check warning on line 5 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"../helpers/loginHelpers"` with `'../helpers/loginHelpers'`

Check failure on line 5 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'logInWithUser1' is defined but never used

Check failure on line 5 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'logInWithUser1' is defined but never used

Check failure on line 5 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'logInWithUsernameAndPassword' is defined but never used

Check failure on line 5 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'logInWithUsernameAndPassword' is defined but never used

Check failure on line 5 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Imports from outside the '_playwright-tests' directory are not allowed.
import { randomUrl } from './helpers/repoHelpers';

export const url = randomUrl();

export const repoNamePrefix = 'Repo-RBAC';
export const randomName = () => (Math.random() + 1).toString(36).substring(2, 6);
export const repoName = `${repoNamePrefix}-${randomName()}`;

test.describe('User Permissions Test', () => {
test('Default user configures repo', async ({ browser }) => {
const context = await browser.newContext({ storageState: '.auth/default_user.json' });
const page = await context.newPage();
// await deleteAllRepos(page, `&search=${repoNamePrefix}`);
await navigateToRepositories(page);
await closePopupsIfExist(page);

await test.step('Create a repository', async () => {
// Click on the 'Add repositories' button

Check warning on line 23 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
// HMS-5268 There are two buttons on the ZeroState page

Check warning on line 24 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
await page.getByRole('button', { name: 'Add repositories' }).first().click();

Check warning on line 25 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········` with `······`
await expect(page.getByRole('dialog', { name: 'Add custom repositories' })).toBeVisible();

Check warning on line 26 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check warning on line 27 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
// Fill in the repository details

Check warning on line 28 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
await page.getByLabel('Name').fill(repoName);

Check warning on line 29 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········` with `······`
await page.getByLabel('Introspect only').click();

Check warning on line 30 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
await page.getByLabel('URL').fill(url);

Check warning on line 31 in _playwright-tests/UI/TwoUserRBAC.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········` with `······`
await page.getByRole('button', { name: 'Save', exact: true }).click();
});
await test.step('Read the repo', async () => {
// Search for the created repo
await page.getByRole('textbox', { name: 'Filter by name/url' }).fill(repoName);
const row = await getRowByNameOrUrl(page, repoName);
await expect(row.getByText('Valid')).toBeVisible();
await row.getByLabel('Kebab toggle').click();
// Click on the Edit button to see the repo
await row.getByRole('menuitem', { name: 'Edit' }).click();
await expect(page.getByRole('dialog', { name: 'Edit custom repository' })).toBeVisible();
// Assert we can read some values
await expect(page.getByPlaceholder('Enter name', { exact: true })).toHaveValue(repoName);
await expect(page.getByPlaceholder('https://', { exact: true })).toHaveValue(url);
});
await test.step('Update the repository', async () => {
await page.getByPlaceholder('Enter name', { exact: true }).fill(`${repoName}-Edited`);
await page.getByRole('button', { name: 'Save changes', exact: true }).click();
});
await page.context().clearCookies();
await logout(page);
await page.context().close();
});

test('Read-only user can view but not edit', async ({ browser }) => {
const context = await browser.newContext({ storageState: '.auth/readonly_user.json' });
const page = await context.newPage();
await navigateToRepositories(page);
await closePopupsIfExist(page);

// Assert read-only user can list but not edit previously created repo
const row = await getRowByNameOrUrl(page, repoName);
await expect(row.getByText('Valid')).toBeVisible();
await row.getByLabel('Kebab toggle').click();
// Assert we cannot click on the Edit button to see the repo
await expect(row.locator(".pf-v5-c-menu__list")).toBeVisible({ timeout: 5000 }); // Confirm menu is open
await expect(row.getByRole("menuitem", { name: "Edit" })).not.toBeVisible({ timeout: 1000 });
// You do not have the required permissions to perform this action.
const repoButton = page.getByRole('button', { name: 'Add repositories', exact: true });
await expect(repoButton).toBeDisabled(); // Verify button is disabled
});
});
44 changes: 36 additions & 8 deletions _playwright-tests/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { expect, test as setup } from '@playwright/test';
import { expect, test as setup, type Page } from "@playwright/test";

Check failure on line 1 in _playwright-tests/auth.setup.ts

View workflow job for this annotation

GitHub Actions / lint

'Page' is defined but never used

Check failure on line 1 in _playwright-tests/auth.setup.ts

View workflow job for this annotation

GitHub Actions / lint

'Page' is defined but never used
import {
throwIfMissingEnvVariables,
logInWithUser1,
storeStorageStateAndToken,
} from './helpers/loginHelpers';
import { closePopupsIfExist } from './UI/helpers/helpers';
closePopupsIfExist,
} from './UI/helpers/helpers';
import {
throwIfMissingEnvVariables,
logInWithUsernameAndPassword,
storeStorageStateAndToken,

Check failure on line 8 in _playwright-tests/auth.setup.ts

View workflow job for this annotation

GitHub Actions / lint

'storeStorageStateAndToken' is defined but never used
logout,
} from "./helpers/loginHelpers";

setup.describe('Setup', async () => {
setup.describe.configure({ retries: 3 });
Expand All @@ -17,7 +20,32 @@
setup.setTimeout(60_000);

await closePopupsIfExist(page);
await logInWithUser1(page);
await storeStorageStateAndToken(page);
await logInWithUsernameAndPassword(
page,
process.env.USER1USERNAME,
process.env.USER1PASSWORD,
);
// Save admin user storage state
await page.context().storageState({ path: '.auth/default_user.json' });
await logout(page);
await logInWithUsernameAndPassword(
page,
process.env.RO_USER_USERNAME,
process.env.RO_USER_PASSWORD,
);
// Save read-only user storage state
await page.context().storageState({ path: '.auth/readonly_user.json' });
await logout(page);
// Example of how to add another user
// await logout(page)
// await logInWithUsernameAndPassword(
// page,
// process.env.USER2USERNAME,
// process.env.USER2PASSWORD
// );
// Example of how to switch to said user
// await switchToUser(page, process.env.USER1USERNAME!);
// await ensureNotInPreview(page);
// Other users for other tests can be added below after logging out
});
});
4 changes: 2 additions & 2 deletions _playwright-tests/helpers/loginHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';

export const logout = async (page: Page) => {
const button = await page.locator(
'div.pf-v5-c-toolbar__item.pf-m-hidden.pf-m-visible-on-lg.pf-v5-u-mr-0 > button',
'div.pf-v6-c-toolbar__item.pf-m-hidden.pf-m-visible-on-lg.pf-v6-u-mr-0 > button',
);

await button.click();
Expand Down Expand Up @@ -55,7 +55,7 @@ export const logInWithUser1 = async (page: Page) =>
export const storeStorageStateAndToken = async (page: Page) => {
const { cookies } = await page
.context()
.storageState({ path: path.join(__dirname, '../../.auth/user.json') });
.storageState({ path: path.join(__dirname, '../../.auth/default_user.json') });
process.env.TOKEN = `Bearer ${cookies.find((cookie) => cookie.name === 'cs_jwt')?.value}`;
await page.waitForTimeout(100);
};
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default defineConfig({
name: 'chromium',
use: {
...devices['Desktop Chrome'],
storageState: '.auth/user.json',
storageState: '.auth/default_user.json',
},
dependencies: ['setup'],
},
Expand Down
Loading