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 2df270d commit b4839dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 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
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Context {
scrollTime: number;
allowedHostnames: Array<string>;
basicAuthorization: basicAuth | undefined;
requestHeaders: authToken | undefined
requestHeaders: authToken | undefined;

};
uploadFilePath: string;
Expand Down

0 comments on commit b4839dc

Please sign in to comment.