|
| 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 | + // Use in-page fetch with credentials so session cookies match browser auth (page.request can 401 on some RHDH setups). |
| 21 | + await page.goto("/catalog"); |
| 22 | + const catalogOrigin = new URL(page.url()).origin; |
| 23 | + const result = await page.evaluate(async (origin: string) => { |
| 24 | + const res = await fetch( |
| 25 | + `${origin}/api/catalog/entities?limit=5&filter=kind=component`, |
| 26 | + { credentials: "include" }, |
| 27 | + ); |
| 28 | + const text = await res.text(); |
| 29 | + return { ok: res.ok, status: res.status, text }; |
| 30 | + }, catalogOrigin); |
| 31 | + expect( |
| 32 | + result.ok, |
| 33 | + `HTTP ${result.status}: ${result.text.slice(0, 500)}`, |
| 34 | + ).toBeTruthy(); |
| 35 | + }); |
| 36 | + |
| 37 | + /** |
| 38 | + * After OIDC app login, connect a GitHub session for SCM (session auth API): |
| 39 | + * Settings → Authentication Providers → GitHub row → **Sign in**. Backstage opens GitHub OAuth in a popup. |
| 40 | + */ |
| 41 | + test("GitHub session sign-in from Authentication Providers", async ({ |
| 42 | + page, |
| 43 | + uiHelper, |
| 44 | + }) => { |
| 45 | + await uiHelper.dismissQuickstartIfVisible(); |
| 46 | + await page.goto("/settings/auth-providers"); |
| 47 | + const authProvidersTab = page.getByRole("tab", { |
| 48 | + name: /authentication providers/i, |
| 49 | + }); |
| 50 | + await expect(authProvidersTab).toBeVisible(); |
| 51 | + await expect(authProvidersTab).toHaveAttribute("aria-selected", "true"); |
| 52 | + |
| 53 | + const githubRow = page |
| 54 | + .getByRole("listitem") |
| 55 | + .filter({ hasText: /^GitHub$/ }); |
| 56 | + const signInButton = githubRow.getByRole("button", { |
| 57 | + name: /^sign in$/i, |
| 58 | + }); |
| 59 | + await expect(signInButton).toBeVisible(); |
| 60 | + |
| 61 | + const [popup] = await Promise.all([ |
| 62 | + page.waitForEvent("popup"), |
| 63 | + signInButton.click(), |
| 64 | + ]); |
| 65 | + await expect(popup).toHaveURL(/github\.com/, { timeout: 60_000 }); |
| 66 | + await popup.close(); |
| 67 | + }); |
| 68 | +}); |
0 commit comments