Skip to content

Commit fbe1039

Browse files
committed
Escape regex input
1 parent 2225e93 commit fbe1039

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

load_testing/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NewBrowserContextOptions } from "k6/browser"
22

33
export const BACKEND_BASE_URL: string = __ENV.BACKEND_BASE_URL
44
export const FRONTEND_BASE_URL: string = __ENV.FRONTEND_BASE_URL
5+
export const SSO_BASE_URL: string = __ENV.SSO_BASE_URL
56

67
export const IGNORE_HTTPS_ERRORS: boolean =
78
(__ENV.IGNORE_HTTPS_ERRORS || "false").toLowerCase() == "true"

load_testing/frontend/test.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import {
44
randomIntBetween,
55
randomItem,
66
} from "https://jslib.k6.io/k6-utils/1.2.0/index.js"
7-
import { BROWSER_CONTEXT_OPTIONS, FRONTEND_BASE_URL } from "../config.ts"
7+
import {
8+
BROWSER_CONTEXT_OPTIONS,
9+
FRONTEND_BASE_URL,
10+
SSO_BASE_URL,
11+
} from "../config.ts"
812
import { AuthCredential, credentials } from "../auth.ts"
13+
import { escapeRegex } from "../utils.ts"
914

1015
async function home(page: Page) {
1116
await page.goto(FRONTEND_BASE_URL)
@@ -47,7 +52,7 @@ async function login(page: Page) {
4752

4853
if (!!credential) {
4954
console.debug("Skipping login because no credentials provided")
50-
return
55+
return false
5156
}
5257

5358
const loginButton = page.getByTestId("login-button-desktop")
@@ -56,12 +61,16 @@ async function login(page: Page) {
5661
await loginKeycloak(page)
5762

5863
await page.waitForURL(/.*\/dashboard.*/)
64+
65+
return true
5966
}
6067

68+
const KEYCLOAK_OIDC_RE = new RegExp(
69+
`${escapeRegex(SSO_BASE_URL)}\/realms\/olapps\/protocol\/openid-connect\/auth.*`,
70+
)
71+
6172
async function loginKeycloak(page: Page, credential: AuthCredential) {
62-
await page.waitForURL(
63-
/https:\/sso(\-qa)?\.ol\.mit\.edu\/realms\/olapps\/protocol\/openid-connect\/auth.*/,
64-
)
73+
await page.waitForURL(KEYCLOAK_OIDC_RE)
6574

6675
const credentialnameInput = await page.locator("input#username")
6776
await credentialnameInput.type(credential.email)
@@ -86,8 +95,10 @@ export async function testFrontend() {
8695
await topics(page)
8796
await departments(page)
8897
await units(page)
89-
await login(page)
90-
await dashboard(page)
98+
const loggedIn = await login(page)
99+
if (loggedIn) {
100+
await dashboard(page)
101+
}
91102
} finally {
92103
await page.close()
93104
}

load_testing/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function escapeRegex(str: string): string {
2+
return str.replace(/[\.\+\*\$\?\^\(\)\{\}\\\[\]\|]/g, "\\$&")
3+
}

0 commit comments

Comments
 (0)