diff --git a/src/routes/index.js b/src/routes/index.js index d755e9d..6fafa8e 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -209,8 +209,12 @@ router.post('/receive_submission', async function(req, res) { user_id: res_data.user.id, username: res_data.user.username, channel, + auth_header: undefined, + cookie_name: undefined, + cookie_value: undefined, }; + console.log(JSON.stringify(values)); for (const key in values) { if (values[key].audit_options && values[key].audit_options.selected_options && values[key].audit_options.selected_options.length > 0) { values[key].audit_options.selected_options.forEach(option => { @@ -218,19 +222,14 @@ router.post('/receive_submission', async function(req, res) { }); } - if (values[key].audit_url) { - submission.audit_url = values[key].audit_url.value; - } - - if (values[key].schedule) { - submission.schedule = values[key].schedule.value; + for (const optionKey of Object.keys(values[key])) { + submission[optionKey] = values[key][optionKey].value; } } try { // Ad-hoc run if (!is_schedule) { - const options = { throttling: submission.throttling, performance: submission.performance, @@ -238,6 +237,9 @@ router.post('/receive_submission', async function(req, res) { 'best-practices': submission['best-practices'], pwa: submission.pwa, seo: submission.seo, + auth_header: submission.auth_header, + cookie_name: submission.cookie_name, + cookie_value: submission.cookie_value, }; res.send(); await runAudit(submission.audit_url, submission.user_id, submission.channel, options); @@ -255,6 +257,9 @@ router.post('/receive_submission', async function(req, res) { 'best-practices': schedule['best-practices'], pwa: schedule.pwa, seo: schedule.seo, + auth_header: schedule.auth_header, + cookie_name: schedule.cookie_name, + cookie_value: schedule.cookie_value, }; await runAudit(schedule.audit_url, schedule.user_id, schedule.channel, options); }); diff --git a/src/store/schedule.js b/src/store/schedule.js index f695a50..ad32046 100644 --- a/src/store/schedule.js +++ b/src/store/schedule.js @@ -16,6 +16,9 @@ const schema = new mongoose.Schema({ seo: Boolean, pwa: Boolean, throttling: Boolean, + auth_header: String, + cookie_name: String, + cookie_value: String, }); const ScheduleModel = mongoose.model('Schedule', schema); @@ -34,6 +37,9 @@ async function createSchedule(payload) { seo: payload.seo, pwa: payload.pwa, throttling: payload.throttling, + auth_header: payload.auth_header, + cookie_name: payload.cookie_name, + cookie_value: payload.cookie_value, }); const data = await new_schedule.save(); diff --git a/src/utils/lighthouse.js b/src/utils/lighthouse.js index a4af532..b718fdc 100644 --- a/src/utils/lighthouse.js +++ b/src/utils/lighthouse.js @@ -27,18 +27,19 @@ async function launchPuppeteer(url, options) { '--disable-dev-shm-usage' ] }); + const page = await browser.newPage(); - // Run authentication script (as injected javascript) - if (options.auth_script) { - const page = await browser.newPage(); - await page.goto(url, { - waitUntil: 'networkidle0', - }); - await page.waitForSelector(options.await_selector, {visible: true}); - await page.evaluate(options.auth_script); - await page.waitForNavigation(); + if (options.auth_header) { + page.setExtraHTTPHeaders({ + 'Authorization': options.auth_header, + }) } + if (options.cookie_name && options.cookie_value) { + page.setCookie({ name: options.cookie_name, value: options.cookie_value }); + } + + await page.waitForNavigation(); // Lighthouse will open URL. Puppeteer observes `targetchanged` and sets up network conditions. // Possible race condition. let opts = { diff --git a/src/utils/responseBuilder.js b/src/utils/responseBuilder.js index 148ecf5..c34649b 100644 --- a/src/utils/responseBuilder.js +++ b/src/utils/responseBuilder.js @@ -123,6 +123,57 @@ function generateAuditDialog(is_schedule) { blocks.push(schedule); } + const auth_header = { + type: 'input', + element: { + type: 'plain_text_input', + action_id: 'auth_header', + placeholder: { + type: 'plain_text', + text: 'JWT ofma3103dSFNsUJasn311ndSN' + } + }, + label: { + type: 'plain_text', + text: 'Authorization Header (optional)' + } + }; + blocks.push(auth_header); + + const cookie_name = { + type: 'input', + element: { + type: 'plain_text_input', + action_id: 'cookie_name', + placeholder: { + type: 'plain_text', + text: 'jwt_token' + } + }, + label: { + type: 'plain_text', + text: 'Cookie Name (optional)' + } + }; + blocks.push(cookie_name); + + const cookie_value = { + type: 'input', + element: { + type: 'plain_text_input', + action_id: 'cookie_value', + placeholder: { + type: 'plain_text', + text: 'jwt_token' + } + }, + label: { + type: 'plain_text', + text: 'Cookie Value (optional)' + } + }; + blocks.push(cookie_value); + // Option dropdowns const options = { type: 'input',