2021-04-13 21:02:52 +02:00
|
|
|
import { test, expect } from "@playwright/test"
|
2021-03-10 00:33:01 +01:00
|
|
|
import { CODE_SERVER_ADDRESS, PASSWORD } from "../utils/constants"
|
2021-01-28 19:48:57 +01:00
|
|
|
|
2021-04-13 21:02:52 +02:00
|
|
|
test.describe("login", () => {
|
2021-04-14 02:31:24 +02:00
|
|
|
// Reset the browser so no cookies are persisted
|
|
|
|
// by emptying the storageState
|
|
|
|
const options = {
|
|
|
|
contextOptions: {
|
|
|
|
storageState: {},
|
|
|
|
},
|
|
|
|
}
|
2021-01-28 19:48:57 +01:00
|
|
|
|
2021-04-16 00:16:50 +02:00
|
|
|
test("should see the login page", options, async ({ page }) => {
|
|
|
|
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
|
|
|
// It should send us to the login page
|
|
|
|
expect(await page.title()).toBe("code-server login")
|
|
|
|
})
|
|
|
|
|
2021-04-14 02:31:24 +02:00
|
|
|
test("should be able to login", options, async ({ page }) => {
|
|
|
|
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
2021-01-28 19:48:57 +01:00
|
|
|
// Type in password
|
2021-02-12 20:08:34 +01:00
|
|
|
await page.fill(".password", PASSWORD)
|
2021-01-28 19:48:57 +01:00
|
|
|
// Click the submit button and login
|
|
|
|
await page.click(".submit")
|
2021-04-01 23:52:46 +02:00
|
|
|
await page.waitForLoadState("networkidle")
|
2021-04-06 00:18:13 +02:00
|
|
|
// Make sure the editor actually loaded
|
|
|
|
expect(await page.isVisible("div.monaco-workbench"))
|
2021-01-28 19:48:57 +01:00
|
|
|
})
|
2021-04-16 00:27:17 +02:00
|
|
|
|
|
|
|
test("should see an error message for missing password", options, async ({ page }) => {
|
|
|
|
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
|
|
|
// Skip entering password
|
|
|
|
// Click the submit button and login
|
|
|
|
await page.click(".submit")
|
|
|
|
await page.waitForLoadState("networkidle")
|
|
|
|
expect(await page.isVisible("text=Missing password"))
|
|
|
|
})
|
|
|
|
|
|
|
|
test("should see an error message for incorrect password", options, async ({ page }) => {
|
|
|
|
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
|
|
|
// Type in password
|
|
|
|
await page.fill(".password", "password123")
|
|
|
|
// Click the submit button and login
|
|
|
|
await page.click(".submit")
|
|
|
|
await page.waitForLoadState("networkidle")
|
|
|
|
expect(await page.isVisible("text=Incorrect password"))
|
|
|
|
})
|
2021-04-16 01:36:35 +02:00
|
|
|
|
|
|
|
test("should hit the rate limiter for too many unsuccessful logins", options, async ({ page }) => {
|
|
|
|
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
|
|
|
// Type in password
|
|
|
|
await page.fill(".password", "password123")
|
|
|
|
// Click the submit button and login
|
|
|
|
// The current RateLimiter allows 2 logins per minute plus
|
|
|
|
// 12 logins per hour for a total of 14
|
|
|
|
// See: src/node/routes/login.ts
|
|
|
|
for (let i = 1; i <= 14; i++) {
|
|
|
|
await page.click(".submit")
|
|
|
|
await page.waitForLoadState("networkidle")
|
|
|
|
}
|
|
|
|
|
|
|
|
// The 15th should fail
|
|
|
|
await page.click(".submit")
|
|
|
|
await page.waitForLoadState("networkidle")
|
|
|
|
expect(await page.isVisible("text=Login rate limited!"))
|
|
|
|
})
|
|
|
|
|
|
|
|
// This test takes 8mins to run and is probably not worth adding to our e2e suite
|
|
|
|
// test.only("should not count successful logins against the rate limiter", options, async ({ page }) => {
|
|
|
|
// for (let i = 1; i <= 14; i++) {
|
|
|
|
// await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
|
|
|
// await page.fill(".password", PASSWORD)
|
|
|
|
// await page.click(".submit")
|
|
|
|
// await page.waitForLoadState("networkidle")
|
|
|
|
// // Make sure the editor actually loaded
|
|
|
|
// await page.isVisible("div.monaco-workbench")
|
|
|
|
|
|
|
|
// // Delete cookie
|
|
|
|
// await page.evaluate(() => {
|
|
|
|
// document.cookie = "key" + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
|
|
|
// return Promise.resolve()
|
|
|
|
// })
|
|
|
|
|
|
|
|
// // Go back to address, which should be the login page
|
|
|
|
// await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // On the 15th time, we should see the editor
|
|
|
|
// await page.fill(".password", PASSWORD)
|
|
|
|
// await page.click(".submit")
|
|
|
|
// await page.waitForLoadState("networkidle")
|
|
|
|
// // Make sure the editor actually loaded
|
|
|
|
// expect(await page.isVisible("div.monaco-workbench"))
|
|
|
|
// })
|
2021-01-28 19:48:57 +01:00
|
|
|
})
|