mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-19 23:44:04 +02:00
test: Ensure inactive users can't log in
This commit is contained in:
parent
28dc77f9e3
commit
e08f90ed1a
2 changed files with 16 additions and 2 deletions
|
@ -44,6 +44,10 @@ test.describe("Multiple Users", () => {
|
|||
await page.reload();
|
||||
await expect(page.getByText("Log in")).toBeVisible();
|
||||
|
||||
// Try to log in as the admin user
|
||||
await login(page, "admin", true); // Expect failure
|
||||
await screenshot(testInfo, page);
|
||||
|
||||
// Login as the new user
|
||||
await page.goto("./dashboard"); // Assuming the new user has ID 2
|
||||
await login(page, "newuser");
|
||||
|
@ -60,6 +64,8 @@ test.describe("Multiple Users", () => {
|
|||
await page.reload();
|
||||
await expect(page.getByText("Log in")).toBeVisible();
|
||||
|
||||
// Try to log in as the new user
|
||||
await login(page, "newuser", true); // Expect failure
|
||||
await screenshot(testInfo, page);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { expect } from "@playwright/test";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const serverUrl = require("../../config/playwright.config.js").url;
|
||||
|
@ -20,9 +22,10 @@ export async function screenshot(testInfo, page) {
|
|||
/**
|
||||
* @param {Page} page Page
|
||||
* @param {string} user Username to log in with
|
||||
* @param {boolean} expectFail Whether to expect a failure (true) or success (false)
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function login(page, user = "admin") {
|
||||
export async function login(page, user = "admin", expectFail = false) {
|
||||
// Login
|
||||
await page.getByPlaceholder("Username").click();
|
||||
await page.getByPlaceholder("Username").fill(user);
|
||||
|
@ -30,7 +33,12 @@ export async function login(page, user = "admin") {
|
|||
await page.getByPlaceholder("Password").fill(user + "123");
|
||||
await page.getByLabel("Remember me").check();
|
||||
await page.getByRole("button", { name: "Log in" }).click();
|
||||
await page.isVisible("text=Add New Monitor");
|
||||
|
||||
if (expectFail) {
|
||||
await expect(page.getByRole("alert")).toBeVisible();
|
||||
} else {
|
||||
await page.isVisible("text=Add New Monitor");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue