Skip to content

Commit 23765aa

Browse files
Merge pull request #22 from wanteddev/feature/avasconcelos114/auth_injection
Release
2 parents a262fe5 + e1ea0a9 commit 23765aa

File tree

6 files changed

+90
-20
lines changed

6 files changed

+90
-20
lines changed

.github/workflows/push.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ jobs:
3131
run: |
3232
docker tag ghcr.io/wanteddev/lighthouse:${{github.event.release.tag_name}} ghcr.io/wanteddev/lighthouse:latest
3333
docker push ghcr.io/wanteddev/lighthouse:latest
34+
if: "github.event.release.prerelease != true"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
*.http
2+
*.http
3+
.env

src/routes/index.js

Lines changed: 14 additions & 9 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
});
219-
}
220-
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;
223+
} else {
224+
for (const optionKey of Object.keys(values[key])) {
225+
submission[optionKey] = values[key][optionKey].value;
226+
}
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: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,22 @@ 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+
await page.setExtraHTTPHeaders({
34+
'Authorization': options.auth_header,
35+
})
4036
}
4137

38+
if (options.cookie_name && options.cookie_value) {
39+
await page.setCookie({ name: options.cookie_name, value: options.cookie_value, url });
40+
}
41+
await page.goto(url, {
42+
waitUntil: 'networkidle0',
43+
});
44+
await page.waitForSelector('body', {visible: true});
45+
await page.close();
4246
// Lighthouse will open URL. Puppeteer observes `targetchanged` and sets up network conditions.
4347
// Possible race condition.
4448
let opts = {
@@ -83,7 +87,6 @@ async function launchPuppeteer(url, options) {
8387
const {lhr} = await lighthouse(url, opts);
8488
// Return response back to main thread
8589
parentPort.postMessage(lhr);
86-
8790
await browser.close();
8891
return;
8992
} catch(error) {

src/utils/responseBuilder.js

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

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

0 commit comments

Comments
 (0)