@@ -45,4 +45,51 @@ test.describe("login", () => {
4545 await page . waitForLoadState ( "networkidle" )
4646 expect ( await page . isVisible ( "text=Incorrect password" ) )
4747 } )
48+
49+ test ( "should hit the rate limiter for too many unsuccessful logins" , options , async ( { page } ) => {
50+ await page . goto ( CODE_SERVER_ADDRESS , { waitUntil : "networkidle" } )
51+ // Type in password
52+ await page . fill ( ".password" , "password123" )
53+ // Click the submit button and login
54+ // The current RateLimiter allows 2 logins per minute plus
55+ // 12 logins per hour for a total of 14
56+ // See: src/node/routes/login.ts
57+ for ( let i = 1 ; i <= 14 ; i ++ ) {
58+ await page . click ( ".submit" )
59+ await page . waitForLoadState ( "networkidle" )
60+ }
61+
62+ // The 15th should fail
63+ await page . click ( ".submit" )
64+ await page . waitForLoadState ( "networkidle" )
65+ expect ( await page . isVisible ( "text=Login rate limited!" ) )
66+ } )
67+
68+ // This test takes 8mins to run and is probably not worth adding to our e2e suite
69+ // test.only("should not count successful logins against the rate limiter", options, async ({ page }) => {
70+ // for (let i = 1; i <= 14; i++) {
71+ // await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
72+ // await page.fill(".password", PASSWORD)
73+ // await page.click(".submit")
74+ // await page.waitForLoadState("networkidle")
75+ // // Make sure the editor actually loaded
76+ // await page.isVisible("div.monaco-workbench")
77+
78+ // // Delete cookie
79+ // await page.evaluate(() => {
80+ // document.cookie = "key" + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"
81+ // return Promise.resolve()
82+ // })
83+
84+ // // Go back to address, which should be the login page
85+ // await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
86+ // }
87+
88+ // // On the 15th time, we should see the editor
89+ // await page.fill(".password", PASSWORD)
90+ // await page.click(".submit")
91+ // await page.waitForLoadState("networkidle")
92+ // // Make sure the editor actually loaded
93+ // expect(await page.isVisible("div.monaco-workbench"))
94+ // })
4895} )
0 commit comments