Reworked Azure auth testing
This commit is contained in:
parent
ce328cd1cd
commit
4020ca40f5
5 changed files with 60 additions and 64 deletions
|
@ -1,70 +1,52 @@
|
||||||
describe("Azure AD", () => {
|
describe("Check Azure AD auth", () => {
|
||||||
it("Go to MS sign in", async () => {
|
const callbackUrl = "https://leaky-ships.mal-noh.de/"
|
||||||
await page.goto("https://leaky-ships.mal-noh.de/")
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/a.png" })
|
|
||||||
await page.click("#start")
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/b.png" })
|
|
||||||
await page.waitForSelector("#login")
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/c.png" })
|
|
||||||
await page.click("#login")
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/d.png" })
|
|
||||||
await page.waitForSelector("#microsoft")
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/e.png" })
|
|
||||||
await page.click("#microsoft")
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/f.png" })
|
|
||||||
}, 10000)
|
|
||||||
|
|
||||||
it("MS sign in", async () => {
|
it("Login process...", async () => {
|
||||||
// Listen for frame navigations and log the URL changes
|
let redirected = false
|
||||||
// page.on("framenavigated", (frame) => {
|
let thirdParty = false
|
||||||
// const frameUrl = frame.url()
|
page.on("framenavigated", (frame) => {
|
||||||
// console.log("Window Location Changed:", frameUrl)
|
if (redirected) return
|
||||||
// })
|
const frameUrl = frame.url()
|
||||||
|
// console.log("Window Location Changed:", frameUrl)
|
||||||
|
if (frameUrl === callbackUrl) redirected = true
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
await page.goto("https://leaky-ships.mal-noh.de/signin")
|
||||||
|
await page.waitForSelector("#microsoft")
|
||||||
|
await page.click("#microsoft")
|
||||||
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/1.png" })
|
thirdParty = true
|
||||||
await page.waitForNavigation()
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/2.png" })
|
|
||||||
// await page.screenshot({ path: "__tests__/screenshots/4.png" })
|
|
||||||
const email = process.env.AUTH_EMAIL
|
|
||||||
const password = process.env.AUTH_PW
|
|
||||||
|
|
||||||
console.log(email)
|
await page.waitForNavigation()
|
||||||
|
|
||||||
await page.waitForSelector('input[type="email"]')
|
await page.waitForSelector('input[type="email"]')
|
||||||
await page.waitForSelector('input[type="password"]')
|
const emailInput = await page.$('input[type="email"]')
|
||||||
await page.screenshot({ path: "__tests__/screenshots/3.png" })
|
await emailInput.type(process.env.AUTH_EMAIL)
|
||||||
|
|
||||||
// Find the email input field and type the email
|
await page.waitForSelector('input[value="Next"]')
|
||||||
const emailInput = await page.$('input[type="email"]')
|
const nextInput = await page.$('input[value="Next"]')
|
||||||
await emailInput.type(email)
|
await nextInput.click()
|
||||||
await page.screenshot({ path: "__tests__/screenshots/4.png" })
|
|
||||||
|
|
||||||
await page.waitForSelector('input[value="Next"]')
|
await page.waitForSelector('input[type="password"]')
|
||||||
// Submit the form (if necessary)
|
const passwordInput = await page.$('input[type="password"]')
|
||||||
const submitInput1 = await page.$('input[type="submit"]')
|
await passwordInput.type(process.env.AUTH_PW)
|
||||||
await submitInput1.click()
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/5.png" })
|
|
||||||
|
|
||||||
// Find the password input field and type the password
|
await page.waitForSelector('input[value="Sign in"]')
|
||||||
const passwordInput = await page.$('input[type="password"]')
|
const signinInput = await page.$('input[value="Sign in"]')
|
||||||
await passwordInput.type(password)
|
await signinInput.click()
|
||||||
await page.screenshot({ path: "__tests__/screenshots/6.png" })
|
|
||||||
|
|
||||||
await page.waitForSelector('input[value="Sign in"]')
|
await page.waitForSelector('input[value="No"]')
|
||||||
// Submit the form (if necessary)
|
const noInput = await page.$('input[value="No"]')
|
||||||
const submitInput = await page.$('input[value="Sign in"]')
|
await noInput.click()
|
||||||
await submitInput.click()
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/7.png" })
|
|
||||||
|
|
||||||
await page.waitForSelector('input[value="No"]')
|
await page.waitForFunction(`window.location.href === '${callbackUrl}'`)
|
||||||
// Submit the form (if necessary)
|
} catch (e) {
|
||||||
const noInput = await page.$('input[value="No"]')
|
if (!redirected || thirdParty) throw e
|
||||||
await noInput.click()
|
}
|
||||||
await page.screenshot({ path: "__tests__/screenshots/8.png" })
|
|
||||||
|
|
||||||
const callbackUrl = "https://leaky-ships.mal-noh.de/"
|
|
||||||
await page.waitForFunction(`window.location.href === '${callbackUrl}'`)
|
|
||||||
// await page.waitForNavigation({ waitUntil: "networkidle0" })
|
|
||||||
await page.screenshot({ path: "__tests__/screenshots/9.png" })
|
|
||||||
}, 15000)
|
}, 15000)
|
||||||
|
|
||||||
|
it("Is logged in", async () => {
|
||||||
|
await page.goto("https://leaky-ships.mal-noh.de/signin")
|
||||||
|
await page.waitForFunction(`window.location.href === '${callbackUrl}'`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
16
leaky-ships/build-start-test.sh
Executable file
16
leaky-ships/build-start-test.sh
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Build the project
|
||||||
|
pnpm run build
|
||||||
|
|
||||||
|
# Start the server in the background
|
||||||
|
pnpm run start &
|
||||||
|
|
||||||
|
# Store the process ID (PID) of the server
|
||||||
|
SERVER_PID=$!
|
||||||
|
|
||||||
|
# Run the tests
|
||||||
|
pnpm test
|
||||||
|
|
||||||
|
# Abort the server process
|
||||||
|
kill $SERVER_PID
|
|
@ -1,9 +1,5 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
verbose: true,
|
verbose: true,
|
||||||
preset: "jest-puppeteer",
|
preset: "jest-puppeteer",
|
||||||
watchPathIgnorePatterns: [
|
|
||||||
"<rootDir>/(?!__tests__)/", // Exclude all paths except for __tests__
|
|
||||||
"<rootDir>/(?!\\.next/)/", // Exclude all paths except for .next/
|
|
||||||
],
|
|
||||||
setupFiles: ["dotenv/config"],
|
setupFiles: ["dotenv/config"],
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"test": "jest --watchAll"
|
"test": "jest -w 1",
|
||||||
|
"build-start-test": "./build-start-test.sh"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.4.0",
|
"@fortawesome/fontawesome-svg-core": "^6.4.0",
|
||||||
|
|
1
leaky-ships/stop-server.sh
Executable file
1
leaky-ships/stop-server.sh
Executable file
|
@ -0,0 +1 @@
|
||||||
|
kill $(lsof -i :3000 -t)
|
Loading…
Add table
Add a link
Reference in a new issue