From bdcaeb0de95762bf43d8e71ab10949ad4fcaf873 Mon Sep 17 00:00:00 2001 From: User Date: Wed, 31 Jul 2024 18:01:33 -0500 Subject: [PATCH 1/3] Add random password util and refactor tests --- frontend/tests/login.spec.ts | 5 +++-- frontend/tests/reset-password.spec.ts | 30 ++++++++++++++------------- frontend/tests/sign-up.spec.ts | 12 +++++------ frontend/tests/user-settings.spec.ts | 26 +++++++++++------------ frontend/tests/utils/random.ts | 2 ++ 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/frontend/tests/login.spec.ts b/frontend/tests/login.spec.ts index ed1a8506dc..6274099183 100644 --- a/frontend/tests/login.spec.ts +++ b/frontend/tests/login.spec.ts @@ -67,9 +67,10 @@ test("Log in with invalid email", async ({ page }) => { }) test("Log in with invalid password", async ({ page }) => { + const password = randomPassword() + await page.goto("/login") - // TODO: Add a random password utility - await fillForm(page, firstSuperuser, "changethat") + await fillForm(page, firstSuperuser, password) await page.getByRole("button", { name: "Log In" }).click() await expect(page.getByText("Incorrect email or password")).toBeVisible() diff --git a/frontend/tests/reset-password.spec.ts b/frontend/tests/reset-password.spec.ts index 59cbceeefb..7cf39ff52c 100644 --- a/frontend/tests/reset-password.spec.ts +++ b/frontend/tests/reset-password.spec.ts @@ -31,13 +31,13 @@ test("User can reset password successfully using the link", async ({ page, request, }) => { - const full_name = "Test User" + const fullName = "Test User" const email = randomEmail() - const password = "changethis" - const new_password = "changethat" + const password = randomPassword() + const newPassword = randomPassword() // Sign up a new user - await signUpNewUser(page, full_name, email, password) + await signUpNewUser(page, fullName, email, password) await page.goto("/recover-password") await page.getByPlaceholder("Email").fill(email) @@ -62,34 +62,36 @@ test("User can reset password successfully using the link", async ({ // Set the new password and confirm it await page.goto(url) - await page.getByLabel("Set Password").fill(new_password) - await page.getByLabel("Confirm Password").fill(new_password) + await page.getByLabel("Set Password").fill(newPassword) + await page.getByLabel("Confirm Password").fill(newPassword) await page.getByRole("button", { name: "Reset Password" }).click() await expect(page.getByText("Password updated successfully")).toBeVisible() // Check if the user is able to login with the new password - await logInUser(page, email, new_password) + await logInUser(page, email, newPassword) }) test("Expired or invalid reset link", async ({ page }) => { + const password = randomPassword() const invalidUrl = "/reset-password?token=invalidtoken" await page.goto(invalidUrl) - await page.getByLabel("Set Password").fill("newpassword") - await page.getByLabel("Confirm Password").fill("newpassword") + await page.getByLabel("Set Password").fill(password) + await page.getByLabel("Confirm Password").fill(password) await page.getByRole("button", { name: "Reset Password" }).click() await expect(page.getByText("Invalid token")).toBeVisible() }) test("Weak new password validation", async ({ page, request }) => { - const full_name = "Test User" + const fullName = "Test User" const email = randomEmail() - const password = "password" + const password = randomPassword() + const weakPassword = "123" // Sign up a new user - await signUpNewUser(page, full_name, email, password) + await signUpNewUser(page, fullName, email, password) await page.goto("/recover-password") await page.getByPlaceholder("Email").fill(email) @@ -109,8 +111,8 @@ test("Weak new password validation", async ({ page, request }) => { // Set a weak new password await page.goto(url) - await page.getByLabel("Set Password").fill("123") - await page.getByLabel("Confirm Password").fill("123") + await page.getByLabel("Set Password").fill(weakPassword) + await page.getByLabel("Confirm Password").fill(weakPassword) await page.getByRole("button", { name: "Reset Password" }).click() await expect( diff --git a/frontend/tests/sign-up.spec.ts b/frontend/tests/sign-up.spec.ts index 3f08e92d57..128a36c6d3 100644 --- a/frontend/tests/sign-up.spec.ts +++ b/frontend/tests/sign-up.spec.ts @@ -56,7 +56,7 @@ test("Log In link is visible", async ({ page }) => { test("Sign up with valid name, email, and password", async ({ page }) => { const full_name = "Test User" const email = randomEmail() - const password = "changethis" + const password = randomPassword() await page.goto("/signup") await fillForm(page, full_name, email, password, password) @@ -81,7 +81,7 @@ test("Sign up with invalid email", async ({ page }) => { test("Sign up with existing email", async ({ page }) => { const full_name = "Test User" const email = randomEmail() - const password = "changethis" + const password = randomPassword() // Sign up with an email await page.goto("/signup") @@ -118,8 +118,8 @@ test("Sign up with weak password", async ({ page }) => { test("Sign up with mismatched passwords", async ({ page }) => { const full_name = "Test User" const email = randomEmail() - const password = "changethis" - const password2 = "changethat" + const password = randomPassword() + const password2 = randomPassword() await page.goto("/signup") @@ -132,7 +132,7 @@ test("Sign up with mismatched passwords", async ({ page }) => { test("Sign up with missing full name", async ({ page }) => { const full_name = "" const email = randomEmail() - const password = "changethis" + const password = randomPassword() await page.goto("/signup") @@ -145,7 +145,7 @@ test("Sign up with missing full name", async ({ page }) => { test("Sign up with missing email", async ({ page }) => { const full_name = "Test User" const email = "" - const password = "changethis" + const password = randomPassword() await page.goto("/signup") diff --git a/frontend/tests/user-settings.spec.ts b/frontend/tests/user-settings.spec.ts index b24f1ec5a8..432bb8d3d9 100644 --- a/frontend/tests/user-settings.spec.ts +++ b/frontend/tests/user-settings.spec.ts @@ -1,7 +1,7 @@ import { expect, test } from "@playwright/test" +import { firstSuperuser, firstSuperuserPassword } from "./config.ts" import { randomEmail } from "./utils/random" import { logInUser, logOutUser, signUpNewUser } from "./utils/user" -import { firstSuperuser, firstSuperuserPassword } from "./config.ts" const tabs = ["My profile", "Password", "Appearance"] @@ -29,7 +29,7 @@ test.describe("Edit user full name and email successfully", () => { const fullName = "Test User" const email = randomEmail() const updatedName = "Test User 2" - const password = "password" + const password = randomPassword() // Sign up a new user await signUpNewUser(page, fullName, email, password) @@ -53,7 +53,7 @@ test.describe("Edit user full name and email successfully", () => { const fullName = "Test User" const email = randomEmail() const updatedEmail = randomEmail() - const password = "password" + const password = randomPassword() // Sign up a new user await signUpNewUser(page, fullName, email, password) @@ -79,7 +79,7 @@ test.describe("Edit user with invalid data", () => { test("Edit user email with an invalid email", async ({ page }) => { const fullName = "Test User" const email = randomEmail() - const password = "password" + const password = randomPassword() const invalidEmail = "" // Sign up a new user @@ -99,7 +99,7 @@ test.describe("Edit user with invalid data", () => { test("Cancel edit action restores original name", async ({ page }) => { const fullName = "Test User" const email = randomEmail() - const password = "password" + const password = randomPassword() const updatedName = "Test User" // Sign up a new user @@ -121,7 +121,7 @@ test.describe("Edit user with invalid data", () => { test("Cancel edit action restores original email", async ({ page }) => { const fullName = "Test User" const email = randomEmail() - const password = "password" + const password = randomPassword() const updatedEmail = randomEmail() // Sign up a new user @@ -149,8 +149,8 @@ test.describe("Change password successfully", () => { test("Update password successfully", async ({ page }) => { const fullName = "Test User" const email = randomEmail() - const password = "password" - const NewPassword = "newPassword" + const password = randomPassword() + const NewPassword = randomPassword() // Sign up a new user await signUpNewUser(page, fullName, email, password) @@ -179,7 +179,7 @@ test.describe("Change password with invalid data", () => { test("Update password with weak passwords", async ({ page }) => { const fullName = "Test User" const email = randomEmail() - const password = "password" + const password = randomPassword() const weakPassword = "weak" // Sign up a new user @@ -203,9 +203,9 @@ test.describe("Change password with invalid data", () => { }) => { const fullName = "Test User" const email = randomEmail() - const password = "password" - const newPassword = "newPassword" - const confirmPassword = "confirmPassword" + const password = randomPassword() + const newPassword = randomPassword() + const confirmPassword = randomPassword() // Sign up a new user await signUpNewUser(page, fullName, email, password) @@ -225,7 +225,7 @@ test.describe("Change password with invalid data", () => { test("Current password and new password are the same", async ({ page }) => { const fullName = "Test User" const email = randomEmail() - const password = "password" + const password = randomPassword() // Sign up a new user await signUpNewUser(page, fullName, email, password) diff --git a/frontend/tests/utils/random.ts b/frontend/tests/utils/random.ts index bd2b43ba10..2de4fa7a15 100644 --- a/frontend/tests/utils/random.ts +++ b/frontend/tests/utils/random.ts @@ -4,6 +4,8 @@ export const randomEmail = () => export const randomTeamName = () => `Team ${Math.random().toString(36).substring(7)}` +export const randomPassword = () => `${Math.random().toString(36).substring(10)}` + export const slugify = (text: string) => text .toLowerCase() From 4a4223d218d016bbeb14e929c797be722f3b1f9a Mon Sep 17 00:00:00 2001 From: User Date: Wed, 31 Jul 2024 18:20:20 -0500 Subject: [PATCH 2/3] Updates --- frontend/tests/login.spec.ts | 1 + frontend/tests/reset-password.spec.ts | 2 +- frontend/tests/sign-up.spec.ts | 28 +++++++++++++-------------- frontend/tests/user-settings.spec.ts | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/frontend/tests/login.spec.ts b/frontend/tests/login.spec.ts index 6274099183..97c2284f40 100644 --- a/frontend/tests/login.spec.ts +++ b/frontend/tests/login.spec.ts @@ -1,5 +1,6 @@ import { type Page, expect, test } from "@playwright/test" import { firstSuperuser, firstSuperuserPassword } from "./config.ts" +import { randomPassword } from "./utils/random.ts" test.use({ storageState: { cookies: [], origins: [] } }) diff --git a/frontend/tests/reset-password.spec.ts b/frontend/tests/reset-password.spec.ts index 7cf39ff52c..88ec798791 100644 --- a/frontend/tests/reset-password.spec.ts +++ b/frontend/tests/reset-password.spec.ts @@ -1,6 +1,6 @@ import { expect, test } from "@playwright/test" import { findLastEmail } from "./utils/mailcatcher" -import { randomEmail } from "./utils/random" +import { randomEmail, randomPassword } from "./utils/random" import { logInUser, signUpNewUser } from "./utils/user" test.use({ storageState: { cookies: [], origins: [] } }) diff --git a/frontend/tests/sign-up.spec.ts b/frontend/tests/sign-up.spec.ts index 128a36c6d3..a666123280 100644 --- a/frontend/tests/sign-up.spec.ts +++ b/frontend/tests/sign-up.spec.ts @@ -1,6 +1,6 @@ import { type Page, expect, test } from "@playwright/test" -import { randomEmail } from "./utils/random" +import { randomEmail, randomPassword } from "./utils/random" test.use({ storageState: { cookies: [], origins: [] } }) @@ -79,20 +79,20 @@ test("Sign up with invalid email", async ({ page }) => { }) test("Sign up with existing email", async ({ page }) => { - const full_name = "Test User" + const fullName = "Test User" const email = randomEmail() const password = randomPassword() // Sign up with an email await page.goto("/signup") - await fillForm(page, full_name, email, password, password) + await fillForm(page, fullName, email, password, password) await page.getByRole("button", { name: "Sign Up" }).click() // Sign up again with the same email await page.goto("/signup") - await fillForm(page, full_name, email, password, password) + await fillForm(page, fullName, email, password, password) await page.getByRole("button", { name: "Sign Up" }).click() await page @@ -101,13 +101,13 @@ test("Sign up with existing email", async ({ page }) => { }) test("Sign up with weak password", async ({ page }) => { - const full_name = "Test User" + const fullName = "Test User" const email = randomEmail() const password = "weak" await page.goto("/signup") - await fillForm(page, full_name, email, password, password) + await fillForm(page, fullName, email, password, password) await page.getByRole("button", { name: "Sign Up" }).click() await expect( @@ -116,53 +116,53 @@ test("Sign up with weak password", async ({ page }) => { }) test("Sign up with mismatched passwords", async ({ page }) => { - const full_name = "Test User" + const fullName = "Test User" const email = randomEmail() const password = randomPassword() const password2 = randomPassword() await page.goto("/signup") - await fillForm(page, full_name, email, password, password2) + await fillForm(page, fullName, email, password, password2) await page.getByRole("button", { name: "Sign Up" }).click() await expect(page.getByText("Passwords do not match")).toBeVisible() }) test("Sign up with missing full name", async ({ page }) => { - const full_name = "" + const fullName = "" const email = randomEmail() const password = randomPassword() await page.goto("/signup") - await fillForm(page, full_name, email, password, password) + await fillForm(page, fullName, email, password, password) await page.getByRole("button", { name: "Sign Up" }).click() await expect(page.getByText("Full Name is required")).toBeVisible() }) test("Sign up with missing email", async ({ page }) => { - const full_name = "Test User" + const fullName = "Test User" const email = "" const password = randomPassword() await page.goto("/signup") - await fillForm(page, full_name, email, password, password) + await fillForm(page, fullName, email, password, password) await page.getByRole("button", { name: "Sign Up" }).click() await expect(page.getByText("Email is required")).toBeVisible() }) test("Sign up with missing password", async ({ page }) => { - const full_name = "" + const fullName = "" const email = randomEmail() const password = "" await page.goto("/signup") - await fillForm(page, full_name, email, password, password) + await fillForm(page, fullName, email, password, password) await page.getByRole("button", { name: "Sign Up" }).click() await expect(page.getByText("Password is required")).toBeVisible() diff --git a/frontend/tests/user-settings.spec.ts b/frontend/tests/user-settings.spec.ts index 432bb8d3d9..a3a8a27490 100644 --- a/frontend/tests/user-settings.spec.ts +++ b/frontend/tests/user-settings.spec.ts @@ -1,6 +1,6 @@ import { expect, test } from "@playwright/test" import { firstSuperuser, firstSuperuserPassword } from "./config.ts" -import { randomEmail } from "./utils/random" +import { randomEmail, randomPassword } from "./utils/random" import { logInUser, logOutUser, signUpNewUser } from "./utils/user" const tabs = ["My profile", "Password", "Appearance"] From 8f6dcd77fc9d467eec26f6b5731d334e48bfefd5 Mon Sep 17 00:00:00 2001 From: User Date: Wed, 31 Jul 2024 21:17:47 -0500 Subject: [PATCH 3/3] Update randomPassword --- frontend/tests/utils/random.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/tests/utils/random.ts b/frontend/tests/utils/random.ts index 2de4fa7a15..d96f0833ce 100644 --- a/frontend/tests/utils/random.ts +++ b/frontend/tests/utils/random.ts @@ -4,7 +4,7 @@ export const randomEmail = () => export const randomTeamName = () => `Team ${Math.random().toString(36).substring(7)}` -export const randomPassword = () => `${Math.random().toString(36).substring(10)}` +export const randomPassword = () => `${Math.random().toString(36).substring(2)}` export const slugify = (text: string) => text