Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
parthlambdatest committed Sep 19, 2024
1 parent db6bf5b commit 8b76cfc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/lib/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default (options: Record<string, string>): Context => {
let env: Env = getEnv();
let webConfig: WebConfig;
let mobileConfig: MobileConfig;
let basicAuthObj: basicAuth
let requestHeaderObj: authToken
let basicAuthObj: basicAuth;
let requestHeaderObj: authToken;
let config = constants.DEFAULT_CONFIG;
let port: number;
let resolutionOff: boolean;
Expand Down
17 changes: 9 additions & 8 deletions src/lib/processSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,19 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
// handle discovery config
ctx.config.allowedHostnames.push(new URL(snapshot.url).hostname);
if (ctx.config.enableJavaScript) ALLOWED_RESOURCES.push('script');

if (ctx.config.basicAuthorization || ctx.config.requestHeaders) {
ctx.log.debug(`Adding basic authorization to the headers for root url`);
let token;
if(ctx.config.basicAuthorization){
token = Buffer.from(`${ctx.config.basicAuthorization.username}:${ctx.config.basicAuthorization.password}`).toString('base64');
} else {
token = ctx.config.requestHeaders.auth
ctx.log.debug(`Adding basic authorization to the headers for url ${requestUrl}`);
let basicToken;
if (ctx.config.basicAuthorization){
let token = Buffer.from(`${ctx.config.basicAuthorization.username}:${ctx.config.basicAuthorization.password}`).toString('base64');
basicToken = `Basic ${token}`
} else if (ctx.config.requestHeaders) {
basicToken = ctx.config.requestHeaders.auth
}
requestOptions.headers = {
...request.headers(),
Authorization: `Basic ${token}`
Authorization: basicToken
};
}

Expand Down

0 comments on commit 8b76cfc

Please sign in to comment.