Skip to content

Commit

Permalink
test: add e2e tests for recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Aug 24, 2023
1 parent 91116de commit d88d8cf
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 32 deletions.
2 changes: 1 addition & 1 deletion test/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default defineConfig({
command:
"make .bin/MailHog && .bin/MailHog -smtp-bind-addr=localhost:8026",
cwd: "../..",
reuseExistingServer: true,
reuseExistingServer: false,
url: "http://localhost:8025/",
},
],
Expand Down
106 changes: 75 additions & 31 deletions test/e2e/playwright/tests/app_recovery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,90 @@ import { test } from "../fixtures"
import { search } from "../actions/mail"
import { extractCode } from "../lib/helper"

test.use({
configOverride: {
identity: {
default_schema_id: "email",
schemas: [
{
id: "email",
url: "file://test/e2e/profiles/email/identity.traits.schema.json",
},
],
test.describe.configure({ mode: "parallel" })
test.describe("Recovery", () => {
test.use({
configOverride: {
identity: {
default_schema_id: "email",
schemas: [
{
id: "email",
url: "file://test/e2e/profiles/email/identity.traits.schema.json",
},
],
},
},
},
})
})

test("recovery works", async ({ page, identity }) => {
await page.goto("/Recovery")
test("succeeds with a valid email address", async ({ page, identity }) => {
await page.goto("/Recovery")

const emailInput = page.getByTestId("email")
await emailInput.waitFor()
await page.getByTestId("email").fill(identity.traits.email)
await page.getByTestId("submit-form").click()
await expect(page.getByTestId("ui/message/1060003")).toBeVisible()

await emailInput.fill(identity.traits.email)
const mails = await search(identity.traits.email, "to")
expect(mails).toHaveLength(1)

await page.getByTestId("submit-form").click()
const code = extractCode(mails[0])
const wrongCode = "0" + code

await page.getByTestId("ui/message/1060003").waitFor()
await test.step("enter wrong code", async () => {
await page.getByTestId("code").fill(wrongCode)
await page.getByText("Submit").click()
await expect(page.getByTestId("ui/message/4060006")).toBeVisible()
})

const mails = await search(identity.traits.email, "to")
expect(mails).toHaveLength(1)
await test.step("enter correct code", async () => {
await page.getByTestId("code").fill(code)
await page.getByText("Submit").click()
await page.waitForURL(/Settings/)
await expect(page.getByTestId("ui/message/1060001").first()).toBeVisible()
})
})

const code = extractCode(mails[0])
test("wrong email address does not get sent", async ({ page, identity }) => {
await page.goto("/Recovery")

const codeInput = page.getByTestId("code")
await codeInput.fill(code)
const wrongEmailAddress = "wrong-" + identity.traits.email
await page.getByTestId("email").fill(wrongEmailAddress)
await page.getByTestId("submit-form").click()
await expect(page.getByTestId("ui/message/1060003")).toBeVisible()

await page.getByTestId("field/method/code").getByTestId("submit-form").click()
try {
await search(identity.traits.email, "to")
expect(false).toBeTruthy()
} catch (e) {
// this is expected
}
})

await page.getByTestId("ui/message/1060001").waitFor()
})
test("fails with an invalid code", async ({ page, identity }) => {
await page.goto("/Recovery")

await page.getByTestId("email").fill(identity.traits.email)
await page.getByTestId("submit-form").click()
await page.getByTestId("ui/message/1060003").isVisible()

const mails = await search(identity.traits.email, "to")
expect(mails).toHaveLength(1)

// TODO: add test for
// - recovery with a not registered email
// - recovery with a not verified email
// - recovery brute force
const code = extractCode(mails[0])
const wrongCode = "0" + code

await test.step("enter wrong repeatetly", async () => {
for (let i = 0; i < 10; i++) {
await page.getByTestId("code").fill(wrongCode)
await page.getByText("Submit").click()
await expect(page.getByTestId("ui/message/4060006")).toBeVisible()
}
})

await test.step("enter correct code fails", async () => {
await page.getByTestId("code").fill(code)
await page.getByText("Submit").click()
await expect(page.getByTestId("ui/message/4060006")).toBeVisible()
})
})
})

0 comments on commit d88d8cf

Please sign in to comment.