forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.spec.js
142 lines (112 loc) Β· 5.16 KB
/
auth.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { test, expect } from "@playwright/test";
import { start, stop, baseUrl } from "./evcc";
test.use({ baseURL: baseUrl() });
const BASIC = "basics.evcc.yaml";
test("set initial password", async ({ page }) => {
await start(BASIC);
await page.goto("/");
const modal = page.getByTestId("password-modal");
await expect(modal).toBeVisible();
await expect(modal.getByRole("heading", { name: "Set Administrator Password" })).toBeVisible();
// empty password
await modal.getByRole("button", { name: "Create Password" }).click();
await expect(modal.getByText("Password should not be empty")).toBeVisible();
// invalid repeat
await modal.getByLabel("New password").fill("foo");
await modal.getByLabel("Repeat password").fill("bar");
await modal.getByRole("button", { name: "Create Password" }).click();
await expect(modal.getByText("Passwords do not match")).toBeVisible();
// success
await modal.getByLabel("New password").fill("secret");
await modal.getByLabel("Repeat password").fill("secret");
await modal.getByRole("button", { name: "Create Password" }).click();
await expect(modal).not.toBeVisible();
await stop();
});
test("login", async ({ page }) => {
await start(BASIC, "password.sql");
await page.goto("/");
// go to config
await page.getByTestId("topnavigation-button").click();
await page.getByRole("link", { name: "Configuration" }).click();
// login modal
const login = page.getByTestId("login-modal");
await expect(login).toBeVisible();
await expect(login.getByRole("heading", { name: "Authentication" })).toBeVisible();
// enter wrong password
await login.getByLabel("Password").fill("wrong");
await login.getByRole("button", { name: "Login" }).click();
await expect(login.getByText("Login failed: Password is invalid.")).toBeVisible();
// enter correct password
await login.getByLabel("Password").fill("secret");
await login.getByRole("button", { name: "Login" }).click();
await expect(login).not.toBeVisible();
await expect(page.getByRole("heading", { name: "Configuration" })).toBeVisible();
await stop();
});
test("http iframe hint", async ({ page }) => {
await start(BASIC, "password.sql");
await page.goto("/");
// go to config
await page.getByTestId("topnavigation-button").click();
await page.getByRole("link", { name: "Configuration" }).click();
// login modal
const login = page.getByTestId("login-modal");
await expect(login).toBeVisible();
await expect(login.getByRole("heading", { name: "Authentication" })).toBeVisible();
// rewrite api call to simulate lost auth cookie
await page.route("**/api/auth/status", (route) => {
route.fulfill({ status: 200, body: "false" });
});
// enter correct password
await login.getByLabel("Password").fill("secret");
await login.getByRole("button", { name: "Login" }).click();
// iframe hint visible (login-iframe-hint)
await expect(login.getByTestId("login-iframe-hint")).toBeVisible();
await stop();
});
test("update password", async ({ page }) => {
const instance = await start(BASIC, "password.sql");
await page.goto("/");
const oldPassword = "secret";
const newPassword = "newsecret";
// login modal
page.goto("/#/config");
const loginOld = page.getByTestId("login-modal");
await loginOld.getByLabel("Password").fill(oldPassword);
await loginOld.getByRole("button", { name: "Login" }).click();
await expect(loginOld).not.toBeVisible();
// update password
await page.getByTestId("generalconfig-password").getByRole("button", { name: "edit" }).click();
const modal = page.getByTestId("password-modal");
await expect(modal.getByRole("heading", { name: "Update Administrator Password" })).toBeVisible();
await modal.getByLabel("Current password").fill(oldPassword);
await modal.getByLabel("New password").fill(newPassword);
await modal.getByLabel("Repeat password").fill(newPassword);
await modal.getByRole("button", { name: "Update Password" }).click();
await expect(
modal.getByRole("heading", { name: "Update Administrator Password" })
).not.toBeVisible();
// logout
await page.getByTestId("topnavigation-button").click();
await page.getByRole("button", { name: "Logout" }).click();
// login modal
await page.getByTestId("topnavigation-button").click();
await expect(page.getByRole("button", { name: "Logout" })).not.toBeVisible();
await page.getByRole("link", { name: "Configuration" }).click();
const loginNew = page.getByTestId("login-modal");
await loginNew.getByLabel("Password").fill(newPassword);
await loginNew.getByRole("button", { name: "Login" }).click();
await expect(page.getByRole("heading", { name: "Configuration" })).toBeVisible();
await expect(loginNew).not.toBeVisible();
// revert to old password
await page.getByTestId("generalconfig-password").getByRole("button", { name: "edit" }).click();
await modal.getByLabel("Current password").fill(newPassword);
await modal.getByLabel("New password").fill(oldPassword);
await modal.getByLabel("Repeat password").fill(oldPassword);
await modal.getByRole("button", { name: "Update Password" }).click();
await expect(
modal.getByRole("heading", { name: "Update Administrator Password" })
).not.toBeVisible();
await stop();
});