Keycloak
81 строка · 3.0 Кб
1import { expect, test } from "@playwright/test";
2import { login } from "../login";
3
4test.describe("Sign out test", () => {
5test("Sign out one device", async ({ browser }) => {
6const context1 = await browser.newContext({
7userAgent:
8"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)",
9});
10const context2 = await browser.newContext();
11try {
12const page1 = await context1.newPage();
13const page2 = await context2.newPage();
14await login(page1, "jdoe", "jdoe", "groups");
15await page1.getByTestId("accountSecurity").click();
16await expect(
17page1.getByTestId("account-security/device-activity"),
18).toBeVisible();
19await page1.getByTestId("account-security/device-activity").click();
20await expect(page1.getByTestId("row-0")).toContainText("Current session");
21
22await login(page2, "jdoe", "jdoe", "groups");
23await page2.getByTestId("accountSecurity").click();
24await expect(
25page2.getByTestId("account-security/device-activity"),
26).toBeVisible();
27await page2.getByTestId("account-security/device-activity").click();
28
29await page2
30.getByRole("button", { name: "Sign out", exact: true })
31.click();
32await page2.getByRole("button", { name: "Confirm" }).click();
33
34// reload pages in browsers, one should stay logged in, the other should be logged out
35await page1.reload();
36await page2.reload();
37await expect(
38page1.getByRole("heading", { name: "Sign in to your account" }),
39).toBeVisible();
40await expect(page2.getByTestId("accountSecurity")).toBeVisible();
41} finally {
42await context1.close();
43await context2.close();
44}
45});
46
47test("Sign out all devices", async ({ browser }) => {
48const context1 = await browser.newContext({
49userAgent:
50"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)",
51});
52const context2 = await browser.newContext();
53try {
54const page1 = await context1.newPage();
55const page2 = await context2.newPage();
56await login(page1, "jdoe", "jdoe", "groups");
57await login(page2, "jdoe", "jdoe", "groups");
58
59await page2.getByTestId("accountSecurity").click();
60await page2.getByTestId("account-security/device-activity").click();
61
62await page2
63.getByRole("button", { name: "Sign out all devices", exact: true })
64.click();
65await page2.getByRole("button", { name: "Confirm" }).click();
66
67// reload pages in browsers, one should stay logged in, the other should be logged out
68await page1.reload();
69// Reload in page2 should not be needed, as it should be logged out after clicking the button
70await expect(
71page1.getByRole("heading", { name: "Sign in to your account" }),
72).toBeVisible();
73await expect(
74page2.getByRole("heading", { name: "Sign in to your account" }),
75).toBeVisible();
76} finally {
77await context1.close();
78await context2.close();
79}
80});
81});
82