Skip to content

Commit 58baac7

Browse files
WIP: Adding ability to inject page with auth header or cookie
1 parent a262fe5 commit 58baac7

File tree

4 files changed

+79
-16
lines changed

4 files changed

+79
-16
lines changed

src/routes/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,35 +209,37 @@ router.post('/receive_submission', async function(req, res) {
209209
user_id: res_data.user.id,
210210
username: res_data.user.username,
211211
channel,
212+
auth_header: undefined,
213+
cookie_name: undefined,
214+
cookie_value: undefined,
212215
};
213216

217+
console.log(JSON.stringify(values));
214218
for (const key in values) {
215219
if (values[key].audit_options && values[key].audit_options.selected_options && values[key].audit_options.selected_options.length > 0) {
216220
values[key].audit_options.selected_options.forEach(option => {
217221
submission[option.value] = true;
218222
});
219223
}
220224

221-
if (values[key].audit_url) {
222-
submission.audit_url = values[key].audit_url.value;
223-
}
224-
225-
if (values[key].schedule) {
226-
submission.schedule = values[key].schedule.value;
225+
for (const optionKey of Object.keys(values[key])) {
226+
submission[optionKey] = values[key][optionKey].value;
227227
}
228228
}
229229

230230
try {
231231
// Ad-hoc run
232232
if (!is_schedule) {
233-
234233
const options = {
235234
throttling: submission.throttling,
236235
performance: submission.performance,
237236
accessibility: submission.accessibility,
238237
'best-practices': submission['best-practices'],
239238
pwa: submission.pwa,
240239
seo: submission.seo,
240+
auth_header: submission.auth_header,
241+
cookie_name: submission.cookie_name,
242+
cookie_value: submission.cookie_value,
241243
};
242244
res.send();
243245
await runAudit(submission.audit_url, submission.user_id, submission.channel, options);
@@ -255,6 +257,9 @@ router.post('/receive_submission', async function(req, res) {
255257
'best-practices': schedule['best-practices'],
256258
pwa: schedule.pwa,
257259
seo: schedule.seo,
260+
auth_header: schedule.auth_header,
261+
cookie_name: schedule.cookie_name,
262+
cookie_value: schedule.cookie_value,
258263
};
259264
await runAudit(schedule.audit_url, schedule.user_id, schedule.channel, options);
260265
});

src/store/schedule.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const schema = new mongoose.Schema({
1616
seo: Boolean,
1717
pwa: Boolean,
1818
throttling: Boolean,
19+
auth_header: String,
20+
cookie_name: String,
21+
cookie_value: String,
1922
});
2023

2124
const ScheduleModel = mongoose.model('Schedule', schema);
@@ -34,6 +37,9 @@ async function createSchedule(payload) {
3437
seo: payload.seo,
3538
pwa: payload.pwa,
3639
throttling: payload.throttling,
40+
auth_header: payload.auth_header,
41+
cookie_name: payload.cookie_name,
42+
cookie_value: payload.cookie_value,
3743
});
3844

3945
const data = await new_schedule.save();

src/utils/lighthouse.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ async function launchPuppeteer(url, options) {
2727
'--disable-dev-shm-usage'
2828
]
2929
});
30+
const page = await browser.newPage();
3031

31-
// Run authentication script (as injected javascript)
32-
if (options.auth_script) {
33-
const page = await browser.newPage();
34-
await page.goto(url, {
35-
waitUntil: 'networkidle0',
36-
});
37-
await page.waitForSelector(options.await_selector, {visible: true});
38-
await page.evaluate(options.auth_script);
39-
await page.waitForNavigation();
32+
if (options.auth_header) {
33+
page.setExtraHTTPHeaders({
34+
'Authorization': options.auth_header,
35+
})
4036
}
4137

38+
if (options.cookie_name && options.cookie_value) {
39+
page.setCookie({ name: options.cookie_name, value: options.cookie_value });
40+
}
41+
42+
await page.waitForNavigation();
4243
// Lighthouse will open URL. Puppeteer observes `targetchanged` and sets up network conditions.
4344
// Possible race condition.
4445
let opts = {

src/utils/responseBuilder.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,57 @@ function generateAuditDialog(is_schedule) {
123123
blocks.push(schedule);
124124
}
125125

126+
const auth_header = {
127+
type: 'input',
128+
element: {
129+
type: 'plain_text_input',
130+
action_id: 'auth_header',
131+
placeholder: {
132+
type: 'plain_text',
133+
text: 'JWT ofma3103dSFNsUJasn311ndSN'
134+
}
135+
},
136+
label: {
137+
type: 'plain_text',
138+
text: 'Authorization Header (optional)'
139+
}
140+
};
141+
blocks.push(auth_header);
142+
143+
const cookie_name = {
144+
type: 'input',
145+
element: {
146+
type: 'plain_text_input',
147+
action_id: 'cookie_name',
148+
placeholder: {
149+
type: 'plain_text',
150+
text: 'jwt_token'
151+
}
152+
},
153+
label: {
154+
type: 'plain_text',
155+
text: 'Cookie Name (optional)'
156+
}
157+
};
158+
blocks.push(cookie_name);
159+
160+
const cookie_value = {
161+
type: 'input',
162+
element: {
163+
type: 'plain_text_input',
164+
action_id: 'cookie_value',
165+
placeholder: {
166+
type: 'plain_text',
167+
text: 'jwt_token'
168+
}
169+
},
170+
label: {
171+
type: 'plain_text',
172+
text: 'Cookie Value (optional)'
173+
}
174+
};
175+
blocks.push(cookie_value);
176+
126177
// Option dropdowns
127178
const options = {
128179
type: 'input',

0 commit comments

Comments
 (0)