From d91591b52f8e599f20664e270211533b67f94d5f Mon Sep 17 00:00:00 2001 From: Nil Gallego Date: Thu, 14 Nov 2024 10:23:13 +0100 Subject: [PATCH] sync with main --- .../e2e/plugins/rbac/rbac-plugin.spec.ts | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/e2e-tests/playwright/e2e/plugins/rbac/rbac-plugin.spec.ts b/e2e-tests/playwright/e2e/plugins/rbac/rbac-plugin.spec.ts index b9407be1b..a8163c22d 100644 --- a/e2e-tests/playwright/e2e/plugins/rbac/rbac-plugin.spec.ts +++ b/e2e-tests/playwright/e2e/plugins/rbac/rbac-plugin.spec.ts @@ -15,14 +15,48 @@ test.describe uiHelper = new UIhelper(page); common = new Common(page); await common.loginAsGithubUser(); - await uiHelper.openSidebarButton("Administration"); - await uiHelper.openSidebar("RBAC"); - await uiHelper.verifyHeading("RBAC"); }); - test.beforeEach( - async () => await new Common(page).checkAndClickOnGHloginPopup(), - ); + test.beforeEach(async () => { + await page.goto("/rbac"); + await new Common(page).checkAndClickOnGHloginPopup(); + }); + + test("Should download the user list", async () => { + await page.locator('a:has-text("Download User List")').click(); + const fileContent = await downloadAndReadFile(page); + const lines = fileContent.trim().split("\n"); + + const header = "userEntityRef,displayName,email,lastAuthTime"; + if (lines[0] !== header) { + throw new Error("Header does not match"); + } + + // Check that each subsequent line starts with "user:default" + const allUsersValid = lines + .slice(1) + .every((line) => line.startsWith("user:default")); + if (!allUsersValid) { + throw new Error("Not all users info are valid"); + } + }); + + async function downloadAndReadFile(page: Page): Promise { + const [download] = await Promise.all([ + page.waitForEvent("download"), + page.locator('a:has-text("Download User List")').click(), + ]); + + const filePath = await download.path(); + + if (filePath) { + const fileContent = await fs.readFile(filePath, "utf-8"); + return fileContent; + } else { + console.error("Download failed or path is not available"); + return undefined; + } + } test("Check if permission policies defined in files are loaded and effective", async () => { const testRole: string = "role:default/test2-role";