Skip to content

Commit

Permalink
test(temp): comment out even more tests, focus on Singpass, return bo…
Browse files Browse the repository at this point in the history
…gus string for UIN
  • Loading branch information
justynoh committed Mar 10, 2023
1 parent bc1e85e commit cce7761
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 121 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Build
env:
NODE_OPTIONS: '--max-old-space-size=4096'
NODE_OPTIONS: '--max-old-space-size=4096 --openssl-legacy-provider'
run: npm run build
- name: Run Playwright tests
run: npx playwright test
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
unsafe-perm=true
legacy-peer-deps=true
48 changes: 24 additions & 24 deletions __tests__/e2e/email-submission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,33 @@ test.describe('Email form submission', () => {
await runTest(page, { formFields, formLogics, formSettings })
})

test('Create and submit email mode form with Corppass authentication', async ({
page,
}) => {
// Define
const formFields = ALL_FIELDS
const formLogics = NO_LOGIC
const formSettings = getSettings({
authType: FormAuthType.CP,
})
// test('Create and submit email mode form with Corppass authentication', async ({
// page,
// }) => {
// // Define
// const formFields = ALL_FIELDS
// const formLogics = NO_LOGIC
// const formSettings = getSettings({
// authType: FormAuthType.CP,
// })

// Test
await runTest(page, { formFields, formLogics, formSettings })
})
// // Test
// await runTest(page, { formFields, formLogics, formSettings })
// })

test('Create and submit email mode form with SGID authentication', async ({
page,
}) => {
// Define
const formFields = ALL_FIELDS
const formLogics = NO_LOGIC
const formSettings = getSettings({
authType: FormAuthType.SGID,
})
// test('Create and submit email mode form with SGID authentication', async ({
// page,
// }) => {
// // Define
// const formFields = ALL_FIELDS
// const formLogics = NO_LOGIC
// const formSettings = getSettings({
// authType: FormAuthType.SGID,
// })

// Test
await runTest(page, { formFields, formLogics, formSettings })
})
// // Test
// await runTest(page, { formFields, formLogics, formSettings })
// })

// test('Create and submit email mode form with MyInfo fields', async ({
// page,
Expand Down
34 changes: 1 addition & 33 deletions __tests__/e2e/helpers/submitForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,7 @@ const authForm = async (
})
.click()

// Redirected to mockpass - perform the login on the mockpass page.
await page.getByRole('button', { name: 'Login' }).click()

// let uin = formSettings.nric
// switch (formSettings.authType) {
// case FormAuthType.CP:
// case FormAuthType.SP:
// await page.getByLabel('NRIC').fill(formSettings.nric)
// if (formSettings.authType === FormAuthType.CP) {
// if (!formSettings.uen) throw new Error('No uen provided!')
// uin = formSettings.uen
// await page.getByLabel('UEN').fill(formSettings.uen)
// }
// await page
// .locator('#sectionA')
// .getByRole('button', { name: 'Login' })
// .click()
// break
// case FormAuthType.SGID:
// case FormAuthType.MyInfo:
// await page.getByRole('button', { name: 'Select username' }).click()
// await page
// .getByRole('link', { name: `${formSettings.nric} [MyInfo]` })
// .click()
// break
// }

await page.getByRole('button', { name: 'Select username' }).click()
await page.getByRole('link', { name: formSettings.nric }).click()
if (formSettings.authType === FormAuthType.MyInfo) {
// Click acceptance button on MyInfo consent page
await page.getByRole('button', { name: 'Submit' }).click()
}
// Mockpass talks to FormSG to login here.

// Redirected to the form fields page. Verify log out button is visible with
// the correct uin, to verify that we have been logged in correctly.
Expand Down
107 changes: 54 additions & 53 deletions __tests__/e2e/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { expect, test } from '@playwright/test'
import cuid from 'cuid'
Expand All @@ -10,75 +11,75 @@ test.describe('login', () => {
await page.goto(ROOT_PAGE)
})

test('Reject emails that do not have white-listed domains', async ({
page,
}) => {
await page.getByRole('link', { name: /log in/i }).click()
await expect(page).toHaveURL(`${ROOT_PAGE}/login`)
// test('Reject emails that do not have white-listed domains', async ({
// page,
// }) => {
// await page.getByRole('link', { name: /log in/i }).click()
// await expect(page).toHaveURL(`${ROOT_PAGE}/login`)

// Enter log in email.
await page
.getByRole('textbox', { name: /log in/i })
.fill('[email protected]')
// // Enter log in email.
// await page
// .getByRole('textbox', { name: /log in/i })
// .fill('[email protected]')

await page.getByRole('button', { name: /log in/i }).click()
// await page.getByRole('button', { name: /log in/i }).click()

// Ensure error message is seen
await expect(
page.getByText('This is not a whitelisted public service email domain.'),
).toBeVisible()
})
// // Ensure error message is seen
// await expect(
// page.getByText('This is not a whitelisted public service email domain.'),
// ).toBeVisible()
// })

test('Login success for white-listed domains', async ({ page }) => {
// Create legit user.
const legitUserEmail = `totally-legit-user${cuid()}@data.gov.sg`
// test('Login success for white-listed domains', async ({ page }) => {
// // Create legit user.
// const legitUserEmail = `totally-legit-user${cuid()}@data.gov.sg`

await page.getByRole('link', { name: 'Log in' }).click()
await expect(page).toHaveURL(`${ROOT_PAGE}/login`)
// await page.getByRole('link', { name: 'Log in' }).click()
// await expect(page).toHaveURL(`${ROOT_PAGE}/login`)

await page.getByRole('textbox', { name: /log in/i }).fill(legitUserEmail)
await page.getByRole('button', { name: /log in/i }).click()
// await page.getByRole('textbox', { name: /log in/i }).fill(legitUserEmail)
// await page.getByRole('button', { name: /log in/i }).click()

// Ensure OTP success message is seen
await expect(
page.getByText(`Enter OTP sent to ${legitUserEmail}`),
).toBeVisible()
// // Ensure OTP success message is seen
// await expect(
// page.getByText(`Enter OTP sent to ${legitUserEmail}`),
// ).toBeVisible()

// Log in with OTP
const otp = await extractOtp(legitUserEmail)
expect(otp).toBeTruthy()
// // Log in with OTP
// const otp = await extractOtp(legitUserEmail)
// expect(otp).toBeTruthy()

await page.locator('input[name="otp"]').fill(otp!)
// await page.locator('input[name="otp"]').fill(otp!)

await page.getByRole('button', { name: 'Sign in' }).click()
await expect(page).toHaveURL(`${ROOT_PAGE}/dashboard`)
})
// await page.getByRole('button', { name: 'Sign in' }).click()
// await expect(page).toHaveURL(`${ROOT_PAGE}/dashboard`)
// })

test('Prevent login if OTP is incorrect', async ({ page }) => {
// Create legit user.
const legitUserEmail = `totally-legit-user${cuid()}@data.gov.sg`
// test('Prevent login if OTP is incorrect', async ({ page }) => {
// // Create legit user.
// const legitUserEmail = `totally-legit-user${cuid()}@data.gov.sg`

await page.getByRole('link', { name: 'Log in' }).click()
await expect(page).toHaveURL(`${ROOT_PAGE}/login`)
// await page.getByRole('link', { name: 'Log in' }).click()
// await expect(page).toHaveURL(`${ROOT_PAGE}/login`)

await page.getByRole('textbox', { name: /log in/i }).fill(legitUserEmail)
await page.getByRole('button', { name: /log in/i }).click()
// await page.getByRole('textbox', { name: /log in/i }).fill(legitUserEmail)
// await page.getByRole('button', { name: /log in/i }).click()

// Ensure OTP success message is seen
await expect(
page.getByText(`Enter OTP sent to ${legitUserEmail}`),
).toBeVisible()
// // Ensure OTP success message is seen
// await expect(
// page.getByText(`Enter OTP sent to ${legitUserEmail}`),
// ).toBeVisible()

// Get OTP
const otp = await extractOtp(legitUserEmail)
// // Get OTP
// const otp = await extractOtp(legitUserEmail)

// Increment OTP by 1, keep to 6 digits
const newOtp = String(parseInt(otp!, 10) + 1).slice(0, 6)
// // Increment OTP by 1, keep to 6 digits
// const newOtp = String(parseInt(otp!, 10) + 1).slice(0, 6)

await page.locator('input[name="otp"]').fill(newOtp)
// await page.locator('input[name="otp"]').fill(newOtp)

await page.getByRole('button', { name: 'Sign in' }).click()
// Ensure error message is seen
await expect(page.getByText('OTP is invalid.')).toBeVisible()
})
// await page.getByRole('button', { name: 'Sign in' }).click()
// // Ensure error message is seen
// await expect(page.getByText('OTP is invalid.')).toBeVisible()
// })
})
9 changes: 4 additions & 5 deletions __tests__/e2e/setup/.test-env
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ SP_OIDC_NDI_DISCOVERY_ENDPOINT=http://localhost:5156/singpass/v2/.well-known/ope
SP_OIDC_NDI_JWKS_ENDPOINT=http://localhost:5156/singpass/v2/.well-known/keys
SP_OIDC_RP_CLIENT_ID=rpClientId
SP_OIDC_RP_REDIRECT_URL=http://localhost:5000/api/v3/singpass/login
SP_OIDC_RP_JWKS_PUBLIC_PATH=./tests/certs/test_sp_rp_public_jwks.json
SP_OIDC_RP_JWKS_SECRET_PATH=./tests/certs/test_sp_rp_secret_jwks.json
SP_OIDC_RP_JWKS_PUBLIC_PATH=./__tests__/e2e/setup/certs/test_sp_rp_public_jwks.json
SP_OIDC_RP_JWKS_SECRET_PATH=./__tests__/e2e/setup/certs/test_sp_rp_secret_jwks.json
CP_OIDC_NDI_DISCOVERY_ENDPOINT=http://localhost:5156/corppass/v2/.well-known/openid-configuration
CP_OIDC_NDI_JWKS_ENDPOINT=http://localhost:5156/corppass/v2/.well-known/keys
CP_OIDC_RP_CLIENT_ID=rpClientId
CP_OIDC_RP_REDIRECT_URL=http://localhost:5000/api/v3/corppass/login
CP_OIDC_RP_JWKS_PUBLIC_PATH=./tests/certs/test_cp_rp_public_jwks.json
CP_OIDC_RP_JWKS_SECRET_PATH=./tests/certs/test_cp_rp_secret_jwks.json
CP_OIDC_RP_JWKS_PUBLIC_PATH=./__tests__/e2e/setup/certs/test_cp_rp_public_jwks.json
CP_OIDC_RP_JWKS_SECRET_PATH=./__tests__/e2e/setup/certs/test_cp_rp_secret_jwks.json

MYINFO_CLIENT_CONFIG=dev
MYINFO_FORMSG_KEY_PATH=./node_modules/@opengovsg/mockpass/static/certs/key.pem
Expand Down Expand Up @@ -84,6 +84,5 @@ REACT_MIGRATION_ADMIN_ROLLOUT=100
# Mockpass env vars
MOCKPASS_NRIC=S8979373D
MOCKPASS_UEN=123456789A
SHOW_LOGIN_PAGE=true
SP_RP_JWKS_ENDPOINT=http://localhost:5000/singpass/.well-known/jwks.json
CP_RP_JWKS_ENDPOINT=http://localhost:5000/api/v3/corppass/.well-known/jwks.json
22 changes: 22 additions & 0 deletions __tests__/e2e/setup/certs/test_cp_rp_public_jwks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"keys": [
{
"kty": "EC",
"use": "sig",
"crv": "P-521",
"kid": "sig-1658197410",
"x": "ACpWhB_ylUHl1lJd0m75UFhBbgLvmeTj5ieyAkOfqO0jZ6PAEEBXbEmRLpElt0CF5trzgK_n1vv25NKkXC1LrU_x",
"y": "Ae3WEayBs-MCluNcow18W3ks6K3nw3Zo18IZZhyYBXN8_HcpzLCrepcCPvs6-q4dUj5DlvYnvobxf2tBU7UDXZPZ",
"alg": "ES512"
},
{
"kty": "EC",
"use": "enc",
"crv": "P-521",
"kid": "enc-1658197405",
"x": "ATkhBceKJGRTuU5U6qmJtP7-78Xg1NBJQr5eQNBt3zHm__N-MkYLj1EbDY8w0khUFIrTkdas2tE9owQAQqSbqwzo",
"y": "AJBlQ0rSBbAAWxNeLs2Wk92Wd0SrbnI5HRY4Xfapz6tDaI5gaBIV3yH6fjVC516lEdvfmpxNe_L3102ZyMwUn6nf",
"alg": "ECDH-ES+A256KW"
}
]
}
24 changes: 24 additions & 0 deletions __tests__/e2e/setup/certs/test_cp_rp_secret_jwks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"keys": [
{
"kty": "EC",
"d": "AQ4L4eNqfeD-hPGn391T8BCBVeCayoQSt0-aEKGyCmKogqs1qnhC5ori2XaetKi0FGmk8CFhnhkYC5Ic4wDanvxF",
"use": "sig",
"crv": "P-521",
"kid": "sig-1658197410",
"x": "ACpWhB_ylUHl1lJd0m75UFhBbgLvmeTj5ieyAkOfqO0jZ6PAEEBXbEmRLpElt0CF5trzgK_n1vv25NKkXC1LrU_x",
"y": "Ae3WEayBs-MCluNcow18W3ks6K3nw3Zo18IZZhyYBXN8_HcpzLCrepcCPvs6-q4dUj5DlvYnvobxf2tBU7UDXZPZ",
"alg": "ES512"
},
{
"kty": "EC",
"d": "AR4bd2zX1BDwWNJNxfcXPk7WiCje-F14QXNwOzQeNGL0d6fIoIPjXkafYcaKuR4PhAW_WXlCYPCebsYmV6QAIvEK",
"use": "enc",
"crv": "P-521",
"kid": "enc-1658197405",
"x": "ATkhBceKJGRTuU5U6qmJtP7-78Xg1NBJQr5eQNBt3zHm__N-MkYLj1EbDY8w0khUFIrTkdas2tE9owQAQqSbqwzo",
"y": "AJBlQ0rSBbAAWxNeLs2Wk92Wd0SrbnI5HRY4Xfapz6tDaI5gaBIV3yH6fjVC516lEdvfmpxNe_L3102ZyMwUn6nf",
"alg": "ECDH-ES+A256KW"
}
]
}
22 changes: 22 additions & 0 deletions __tests__/e2e/setup/certs/test_sp_rp_public_jwks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"keys": [
{
"kty": "EC",
"use": "sig",
"crv": "P-521",
"kid": "sig-2022-06-04T09:22:28Z",
"x": "AAj_CAKL9NmP6agPCMto6_LiYQqko3o3ZWTtBg75bA__Z8yKEv_CwHzaibkVLnJ9XKWxCQeyEk9ROLhJoJuZxnsI",
"y": "AZeoe0v-EwqD3oo1V5lxUAmC80qHt-ybqOsl1mYKPgE_ctGcD4hj8tVhmD0Of6ARuKVTxNWej-X82hEW_7Aa-XpR",
"alg": "ES512"
},
{
"kty": "EC",
"use": "enc",
"crv": "P-521",
"kid": "enc-2022-06-04T13:46:15Z",
"x": "AB-16HyJwnlSZbQtqhFskADqFrm6rgX9XeaV8FgynX61750GCRbYjoueDosSNt-qzK5QNHskdQw0QZ700YF2JIlb",
"y": "AZwYlSBSdV-CxGRMz6ovTvWxKJ6e44gaZHf-YfbJV7w9VdAJb3OuzbHNGRuzNDjEa8eH-paLDaAB84ezrEm1SRHq",
"alg": "ECDH-ES+A256KW"
}
]
}
24 changes: 24 additions & 0 deletions __tests__/e2e/setup/certs/test_sp_rp_secret_jwks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"keys": [
{
"kty": "EC",
"d": "AFOzlND2sq43ykty-VZXw-IEIOyHkBsNXUU77o5yEYcktpoMe9Dl3jsaXwzRK6wtDJH_uoz4IG1Uj4J_WyH5O3GS",
"use": "sig",
"crv": "P-521",
"kid": "sig-2022-06-04T09:22:28Z",
"x": "AAj_CAKL9NmP6agPCMto6_LiYQqko3o3ZWTtBg75bA__Z8yKEv_CwHzaibkVLnJ9XKWxCQeyEk9ROLhJoJuZxnsI",
"y": "AZeoe0v-EwqD3oo1V5lxUAmC80qHt-ybqOsl1mYKPgE_ctGcD4hj8tVhmD0Of6ARuKVTxNWej-X82hEW_7Aa-XpR",
"alg": "ES512"
},
{
"kty": "EC",
"d": "AP7xECOnlKW-FuLpe1h3ULZoqFzScFrbyAEQTFFG49j5HRHl0k13-6_6nWnwJ9Y8sTrGOWH4GszmDBBZGGvESJQr",
"use": "enc",
"crv": "P-521",
"kid": "enc-2022-06-04T13:46:15Z",
"x": "AB-16HyJwnlSZbQtqhFskADqFrm6rgX9XeaV8FgynX61750GCRbYjoueDosSNt-qzK5QNHskdQw0QZ700YF2JIlb",
"y": "AZwYlSBSdV-CxGRMz6ovTvWxKJ6e44gaZHf-YfbJV7w9VdAJb3OuzbHNGRuzNDjEa8eH-paLDaAB84ezrEm1SRHq",
"alg": "ECDH-ES+A256KW"
}
]
}
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const config: PlaywrightTestConfig = {
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 1 : 0,
retries: process.env.CI ? 0 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
Expand All @@ -39,7 +39,7 @@ const config: PlaywrightTestConfig = {
baseURL: 'http://localhost:5000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
trace: 'on', // 'on-first-retry',
},

/* Configure projects for major browsers */
Expand Down
Loading

0 comments on commit cce7761

Please sign in to comment.