|
| 1 | +import { test, expect } from "@red-hat-developer-hub/e2e-test-utils/test"; |
| 2 | + |
| 3 | +test.describe("app-defaults plugins (app-next + OIDC + GitHub integration)", () => { |
| 4 | + test.beforeAll(async ({ rhdh }) => { |
| 5 | + await rhdh.configure({ auth: "keycloak" }); |
| 6 | + await rhdh.deploy(); |
| 7 | + }); |
| 8 | + |
| 9 | + test.beforeEach(async ({ loginHelper }) => { |
| 10 | + await loginHelper.loginAsKeycloakUser(); |
| 11 | + }); |
| 12 | + |
| 13 | + test("loads Catalog after OIDC login", async ({ uiHelper }) => { |
| 14 | + await uiHelper.dismissQuickstartIfVisible(); |
| 15 | + await uiHelper.openSidebar("Catalog"); |
| 16 | + await uiHelper.verifyHeading(/catalog/i); |
| 17 | + }); |
| 18 | + |
| 19 | + test("catalog API responds for authenticated session", async ({ page }) => { |
| 20 | + // Assert on the Catalog SPA's own GET to /api/catalog/* (same cookies/identity as the UI). |
| 21 | + // Ad-hoc fetch()/page.request often 401 here: backend identity middleware matches app-issued requests. |
| 22 | + const catalogApiOk = page.waitForResponse( |
| 23 | + (response) => { |
| 24 | + if (response.request().method() !== "GET") return false; |
| 25 | + if (!response.url().includes("/api/catalog/")) return false; |
| 26 | + const status = response.status(); |
| 27 | + return status >= 200 && status < 400; |
| 28 | + }, |
| 29 | + { timeout: 60_000 }, |
| 30 | + ); |
| 31 | + await page.goto("/catalog"); |
| 32 | + const response = await catalogApiOk; |
| 33 | + expect(response.ok()).toBeTruthy(); |
| 34 | + }); |
| 35 | + |
| 36 | + /** |
| 37 | + * After OIDC app login, connect a GitHub session for SCM (session auth API): |
| 38 | + * Settings → Authentication Providers → GitHub row → **Sign in** → **Login Required** dialog → **Log in** → GitHub OAuth popup. |
| 39 | + */ |
| 40 | + test("GitHub session sign-in from Authentication Providers", async ({ |
| 41 | + page, |
| 42 | + uiHelper, |
| 43 | + }) => { |
| 44 | + await uiHelper.dismissQuickstartIfVisible(); |
| 45 | + await page.goto("/settings/auth-providers"); |
| 46 | + const authProvidersTab = page.getByRole("tab", { |
| 47 | + name: /authentication providers/i, |
| 48 | + }); |
| 49 | + await expect(authProvidersTab).toBeVisible(); |
| 50 | + await expect(authProvidersTab).toHaveAttribute("aria-selected", "true"); |
| 51 | + |
| 52 | + // Row inner text includes title + description (not only "GitHub"), so /^GitHub$/ matches nothing. |
| 53 | + const githubRow = page |
| 54 | + .getByRole("listitem") |
| 55 | + .filter({ hasText: /\bGitHub\b/ }) |
| 56 | + .first(); |
| 57 | + const signInButton = githubRow.getByRole("button", { |
| 58 | + name: /^sign in$/i, |
| 59 | + }); |
| 60 | + await expect(signInButton).toBeVisible(); |
| 61 | + |
| 62 | + await signInButton.click(); |
| 63 | + |
| 64 | + const loginRequiredDialog = page.getByRole("dialog", { |
| 65 | + name: /login required/i, |
| 66 | + }); |
| 67 | + await expect(loginRequiredDialog).toBeVisible(); |
| 68 | + |
| 69 | + const dialogLogInButton = loginRequiredDialog.getByRole("button", { |
| 70 | + name: /^log in$/i, |
| 71 | + }); |
| 72 | + await expect(dialogLogInButton).toBeVisible(); |
| 73 | + |
| 74 | + const [popup] = await Promise.all([ |
| 75 | + page.waitForEvent("popup", { timeout: 60_000 }), |
| 76 | + dialogLogInButton.click(), |
| 77 | + ]); |
| 78 | + await expect(popup).toHaveURL(/github\.com/, { timeout: 60_000 }); |
| 79 | + await popup.close(); |
| 80 | + }); |
| 81 | +}); |
0 commit comments