From df495748e9db46e9411b0f9d60b1bf4ab382c590 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Tue, 6 May 2025 13:03:13 +0100 Subject: [PATCH] playwright: check admin access for on-prem Add a check to the playwright tests to ensure that the user sees the 'Access is limited.' error message if the logged in user doesn't have the required privileges. --- playwright/helpers/login.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/playwright/helpers/login.ts b/playwright/helpers/login.ts index 7b460862..b283bba3 100644 --- a/playwright/helpers/login.ts +++ b/playwright/helpers/login.ts @@ -1,6 +1,7 @@ import { type Page, expect } from '@playwright/test'; import { closePopupsIfExist, isHosted, togglePreview } from './helpers'; +import { ibFrame } from './navHelpers'; /** * Logs in to either Cockpit or Console, will distinguish between them based on the environment @@ -25,9 +26,16 @@ const loginCockpit = async (page: Page, user: string, password: string) => { await page.getByRole('textbox', { name: 'User name' }).fill(user); await page.getByRole('textbox', { name: 'Password' }).fill(password); - - // cockpit-image-builder needs superuser await page.getByRole('button', { name: 'Log in' }).click(); + + // image-builder lives inside an iframe + const frame = ibFrame(page); + + // cockpit-image-builder needs superuser, expect an error message + // when the user does not have admin priviliges + await expect( + frame.getByRole('heading', { name: 'Access is limited' }) + ).toBeVisible(); await page.getByRole('button', { name: 'Limited access' }).click(); // different popup opens based on type of account (can be passwordless) @@ -49,6 +57,9 @@ const loginCockpit = async (page: Page, user: string, password: string) => { await expect( page.getByRole('button', { name: 'Administrative access' }) ).toBeVisible(); + await expect( + frame.getByRole('heading', { name: 'All images' }) + ).toBeVisible(); }; const loginConsole = async (page: Page, user: string, password: string) => {