2021-04-22 04:31:15 +07:00
|
|
|
import { PASSWORD } from "../utils/constants"
|
2021-06-23 04:34:44 +07:00
|
|
|
import { describe, test, expect } from "./baseFixture"
|
2021-01-29 01:48:57 +07:00
|
|
|
|
2021-06-23 04:34:44 +07:00
|
|
|
describe("login", () => {
|
2021-04-14 07:31:24 +07:00
|
|
|
// Reset the browser so no cookies are persisted
|
|
|
|
// by emptying the storageState
|
2021-06-10 20:09:38 +07:00
|
|
|
test.use({
|
|
|
|
storageState: {},
|
2021-04-22 04:31:15 +07:00
|
|
|
})
|
2021-01-29 01:48:57 +07:00
|
|
|
|
2021-06-10 20:09:38 +07:00
|
|
|
test("should see the login page", async ({ codeServerPage }) => {
|
2021-04-16 05:16:50 +07:00
|
|
|
// It should send us to the login page
|
2021-06-10 20:09:38 +07:00
|
|
|
expect(await codeServerPage.page.title()).toBe("code-server login")
|
2021-04-16 05:16:50 +07:00
|
|
|
})
|
|
|
|
|
2021-06-10 20:09:38 +07:00
|
|
|
test("should be able to login", async ({ codeServerPage }) => {
|
2021-01-29 01:48:57 +07:00
|
|
|
// Type in password
|
2021-06-10 20:09:38 +07:00
|
|
|
await codeServerPage.page.fill(".password", PASSWORD)
|
2021-01-29 01:48:57 +07:00
|
|
|
// Click the submit button and login
|
2021-06-10 20:09:38 +07:00
|
|
|
await codeServerPage.page.click(".submit")
|
|
|
|
await codeServerPage.page.waitForLoadState("networkidle")
|
2021-04-22 04:31:15 +07:00
|
|
|
// We do this because occassionally code-server doesn't load on Firefox
|
|
|
|
// but loads if you reload once or twice
|
2021-06-10 20:09:38 +07:00
|
|
|
await codeServerPage.reloadUntilEditorIsReady()
|
2021-04-06 05:18:13 +07:00
|
|
|
// Make sure the editor actually loaded
|
2021-06-10 20:09:38 +07:00
|
|
|
expect(await codeServerPage.isEditorVisible()).toBe(true)
|
2021-01-29 01:48:57 +07:00
|
|
|
})
|
2021-04-16 05:27:17 +07:00
|
|
|
|
2021-06-10 20:09:38 +07:00
|
|
|
test("should see an error message for missing password", async ({ codeServerPage }) => {
|
2021-04-16 05:27:17 +07:00
|
|
|
// Skip entering password
|
|
|
|
// Click the submit button and login
|
2021-06-10 20:09:38 +07:00
|
|
|
await codeServerPage.page.click(".submit")
|
|
|
|
await codeServerPage.page.waitForLoadState("networkidle")
|
|
|
|
expect(await codeServerPage.page.isVisible("text=Missing password"))
|
2021-04-16 05:27:17 +07:00
|
|
|
})
|
|
|
|
|
2021-06-10 20:09:38 +07:00
|
|
|
test("should see an error message for incorrect password", async ({ codeServerPage }) => {
|
2021-04-16 05:27:17 +07:00
|
|
|
// Type in password
|
2021-06-10 20:09:38 +07:00
|
|
|
await codeServerPage.page.fill(".password", "password123")
|
2021-04-16 05:27:17 +07:00
|
|
|
// Click the submit button and login
|
2021-06-10 20:09:38 +07:00
|
|
|
await codeServerPage.page.click(".submit")
|
|
|
|
await codeServerPage.page.waitForLoadState("networkidle")
|
|
|
|
expect(await codeServerPage.page.isVisible("text=Incorrect password"))
|
2021-04-16 05:27:17 +07:00
|
|
|
})
|
2021-04-16 06:36:35 +07:00
|
|
|
|
2021-06-10 20:09:38 +07:00
|
|
|
test("should hit the rate limiter for too many unsuccessful logins", async ({ codeServerPage }) => {
|
2021-04-16 06:36:35 +07:00
|
|
|
// Type in password
|
2021-06-10 20:09:38 +07:00
|
|
|
await codeServerPage.page.fill(".password", "password123")
|
2021-04-16 06:36:35 +07:00
|
|
|
// 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
|
2021-04-20 01:21:38 +07:00
|
|
|
for (let i = 1; i <= 14; i++) {
|
2021-06-10 20:09:38 +07:00
|
|
|
await codeServerPage.page.click(".submit")
|
|
|
|
await codeServerPage.page.waitForLoadState("networkidle")
|
2021-04-20 01:11:52 +07:00
|
|
|
// We double-check that the correct error message shows
|
|
|
|
// which should be for incorrect password
|
2021-06-10 20:09:38 +07:00
|
|
|
expect(await codeServerPage.page.isVisible("text=Incorrect password"))
|
2021-04-16 06:36:35 +07:00
|
|
|
}
|
|
|
|
|
2021-04-20 01:11:52 +07:00
|
|
|
// The 15th should fail for a different reason:
|
|
|
|
// login rate
|
2021-06-10 20:09:38 +07:00
|
|
|
await codeServerPage.page.click(".submit")
|
|
|
|
await codeServerPage.page.waitForLoadState("networkidle")
|
|
|
|
expect(await codeServerPage.page.isVisible("text=Login rate limited!"))
|
2021-04-16 06:36:35 +07:00
|
|
|
})
|
2021-01-29 01:48:57 +07:00
|
|
|
})
|