|
1 | 1 | import puppeteer from 'puppeteer'; |
2 | 2 | import { validateSession } from '../common/validate.mjs'; |
3 | | -import { authenticate } from './lib/calendar.mjs'; |
4 | 3 | import { getEnvKey } from '../common/envkeys.mjs'; |
5 | 4 | import { exportProjectToGitHub } from '../common/project.mjs'; |
6 | 5 | import { parseSessionMeetings } from '../common/meetings.mjs'; |
7 | 6 |
|
| 7 | + |
| 8 | +/** |
| 9 | + * Login to W3C server. |
| 10 | + * |
| 11 | + * The function throws if login fails. |
| 12 | + */ |
| 13 | +export async function authenticate(page, login, password, redirectUrl) { |
| 14 | + const url = await page.evaluate(() => window.location.href); |
| 15 | + if (!url.endsWith('/login')) { |
| 16 | + return; |
| 17 | + } |
| 18 | + |
| 19 | + const usernameInput = await page.waitForSelector('input#username'); |
| 20 | + await usernameInput.type(login); |
| 21 | + |
| 22 | + const passwordInput = await page.waitForSelector('input#password'); |
| 23 | + await passwordInput.type(password); |
| 24 | + |
| 25 | + const submitButton = await page.waitForSelector('button[type=submit]'); |
| 26 | + await submitButton.click(); |
| 27 | + |
| 28 | + await page.waitForNavigation(); |
| 29 | + const newUrl = await page.evaluate(() => window.location.href); |
| 30 | + if (newUrl !== redirectUrl) { |
| 31 | + throw new Error('Could not login. Invalid credentials?'); |
| 32 | + } |
| 33 | +} |
| 34 | + |
8 | 35 | export default async function (project, number, options) { |
9 | 36 | const meeting = project.metadata.meeting.toLowerCase().replace(/\s+/g, ''); |
10 | 37 | const registrantsUrl = options?.url ?? |
|
0 commit comments