2024-03-22 13:02:50 +00:00
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
import { login } from "./login";
|
2024-04-16 15:24:22 +00:00
|
|
|
import { getAdminUrl } from "./utils";
|
|
|
|
import { ADMIN_PASSWORD, ADMIN_USER, DEFAULT_REALM } from "../src/constants";
|
|
|
|
|
|
|
|
// NOTE: This test suite will only pass when running a production build, as the referrer is extracted on the server side.
|
|
|
|
// This will change once https://github.com/keycloak/keycloak/pull/27311 has been merged.
|
2024-03-22 13:02:50 +00:00
|
|
|
|
|
|
|
test.describe("Signing in with referrer link", () => {
|
2024-04-16 15:24:22 +00:00
|
|
|
test("shows a referrer link when a matching client exists", async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
const referrer = "security-admin-console";
|
|
|
|
const referrerUrl = getAdminUrl();
|
|
|
|
const referrerName = "security admin console";
|
|
|
|
|
2024-03-22 13:02:50 +00:00
|
|
|
const queryParams = {
|
2024-04-16 15:24:22 +00:00
|
|
|
referrer,
|
|
|
|
referrer_uri: referrerUrl,
|
2024-03-22 13:02:50 +00:00
|
|
|
};
|
|
|
|
|
2024-04-16 15:24:22 +00:00
|
|
|
await login(page, ADMIN_USER, ADMIN_PASSWORD, DEFAULT_REALM, queryParams);
|
|
|
|
await expect(page.getByTestId("referrer-link")).toContainText(referrerName);
|
2024-03-22 13:02:50 +00:00
|
|
|
|
2024-04-16 15:24:22 +00:00
|
|
|
// Navigate around to ensure the referrer is still shown.
|
2024-03-22 13:02:50 +00:00
|
|
|
await page.getByTestId("accountSecurity").click();
|
|
|
|
await expect(page.getByTestId("account-security/signing-in")).toBeVisible();
|
2024-04-16 15:24:22 +00:00
|
|
|
await expect(page.getByTestId("referrer-link")).toContainText(referrerName);
|
2024-03-22 13:02:50 +00:00
|
|
|
});
|
|
|
|
|
2024-04-16 15:24:22 +00:00
|
|
|
test("shows no referrer link when an invalid URL is passed", async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
const referrer = "security-admin-console";
|
|
|
|
const referrerUrl = "http://i-am-not-an-allowed-url.com";
|
|
|
|
|
2024-03-22 13:02:50 +00:00
|
|
|
const queryParams = {
|
2024-04-16 15:24:22 +00:00
|
|
|
referrer,
|
|
|
|
referrer_uri: referrerUrl,
|
2024-03-22 13:02:50 +00:00
|
|
|
};
|
|
|
|
|
2024-04-16 15:24:22 +00:00
|
|
|
await login(page, ADMIN_USER, ADMIN_PASSWORD, DEFAULT_REALM, queryParams);
|
|
|
|
await expect(page.getByText("Manage your basic information")).toBeVisible();
|
2024-03-22 13:02:50 +00:00
|
|
|
await expect(page.getByTestId("referrer-link")).toBeHidden();
|
|
|
|
});
|
|
|
|
});
|