Skip to content

Commit

Permalink
fix(chore): resolving sonar smells to improve quality gate (#171)
Browse files Browse the repository at this point in the history
* fix(chore): resolving sonar smells to improve quality gate

resolving sonar smells to improve quality gate

GH-142

* fix(chore): changed the name of a function

changed the name of a function

GH-142

* fix(chore): fixed the parentheses sonar issues

fixed the parentheses sonar issues

GH-142
  • Loading branch information
arpit1503khanna authored Nov 22, 2023
1 parent 99e0b2f commit 3c9386a
Show file tree
Hide file tree
Showing 28 changed files with 419 additions and 444 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"bracketSpacing": false,
"singleQuote": true,
"printWidth": 80,
"trailingComma": "all"
"trailingComma": "all",
"arrowParens": "avoid"
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/providers/client-authentication.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ClientAuthenticateActionProvider
) {}

value(): AuthenticateFn<IAuthClient | undefined> {
return (request) => this.action(request);
return request => this.action(request);
}

async action(request: Request): Promise<IAuthClient | undefined> {
Expand Down
12 changes: 6 additions & 6 deletions src/release_notes/post-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ module.exports = async function (data, callback) {
const commitTitle = commit.title;
commit.title = commitTitle.substring(0, commitTitle.indexOf('#') - 1);

commit.messageLines = commit.messageLines.filter((message) => {
commit.messageLines = commit.messageLines.filter(message => {
if (message.indexOf('efs/remotes/origin') === -1) return message;
});

commit.messageLines.forEach((message) => {
commit.messageLines.forEach(message => {
commit.issueno = message.includes('GH-')
? message.replace('GH-', '').trim()
: null;
});

const issueDesc = await getIssueDesc(commit.issueno).then((res) => {
const issueDesc = await getIssueDesc(commit.issueno).then(res => {
return res;
});
commit.issueTitle = issueDesc;
Expand Down Expand Up @@ -48,9 +48,9 @@ function getIssueDesc(issueNo) {
`https://github.com/sourcefuse/loopback4-authentication/issues/${encodeURIComponent(
issueNo,
)}`,
(res) => {
res => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
res.on('data', chunk => {
result = result + chunk;
});
res.on('end', () => {
Expand All @@ -69,7 +69,7 @@ function getIssueDesc(issueNo) {
});
},
);
req.on('error', (e) => {
req.on('error', e => {
reject(e);
});
req.end();
Expand Down
2 changes: 1 addition & 1 deletion src/release_notes/release-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function addAndCommit() {
await git.push('origin', 'master');
}

generateReleaseNotes().catch((ex) => {
generateReleaseNotes().catch(ex => {
console.error(ex);
process.exit(1);
});
7 changes: 4 additions & 3 deletions src/strategies/SAML/saml-strategy-factory-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import {
import {AuthErrorKeys} from '../../error-keys';
import {Strategies} from '../../keys';
import {VerifyFunction} from '../../types';
export interface SamlStrategyFactory {
(options: SamlConfig, verifierPassed?: VerifyFunction.SamlFn): Strategy;
}
export type SamlStrategyFactory = (
options: SamlConfig,
verifierPassed?: VerifyFunction.SamlFn,
) => Strategy;

export class SamlStrategyFactoryProvider
implements Provider<SamlStrategyFactory>
Expand Down
4 changes: 0 additions & 4 deletions src/strategies/SAML/saml-verify.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import {VerifyFunction} from '../../types';
* It will just throw an error saying Not Implemented
*/
export class SamlVerifyProvider implements Provider<VerifyFunction.SamlFn> {
constructor() {
//This is intentional
}

value(): VerifyFunction.SamlFn {
return async (
profile: SamlStrategy.Profile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class AppleAuthStrategyFactoryProvider
): Strategy {
const verifyFn = verifierPassed ?? this.verifierAppleAuth;
let strategy;
if (options && options.passReqToCallback === true) {
if (options?.passReqToCallback === true) {
strategy = new Strategy(
options,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {VerifyFunction} from '../../types';
export class AppleAuthVerifyProvider
implements Provider<VerifyFunction.AppleAuthFn>
{
constructor() {}

value(): VerifyFunction.AppleAuthFn {
return async (
accessToken: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import {
IOIDCStrategyOptionWithoutRequest,
} from 'passport-azure-ad';

export interface AzureADAuthStrategyFactory {
(
options: IOIDCStrategyOptionWithoutRequest | IOIDCStrategyOptionWithRequest,
verifierPassed?: VerifyFunction.AzureADAuthFn,
): OIDCStrategy;
}
export type AzureADAuthStrategyFactory = (
options: IOIDCStrategyOptionWithoutRequest | IOIDCStrategyOptionWithRequest,
verifierPassed?: VerifyFunction.AzureADAuthFn,
) => OIDCStrategy;

export class AzureADAuthStrategyFactoryProvider
implements Provider<AzureADAuthStrategyFactory>
Expand All @@ -31,6 +29,61 @@ export class AzureADAuthStrategyFactoryProvider
return (options, verifier) =>
this.getAzureADAuthStrategyVerifier(options, verifier);
}
createCallbackWithReq(verifyFn: VerifyFunction.AzureADAuthFn) {
return async (
req: Request,
iss: string,
sub: string,
profile: IProfile,
accessToken: string,
refreshToken: string,
done: VerifyCallback,
) => {
if (!profile.oid) {
return done(new Error('No oid found'), null);
}

try {
const user = await verifyFn(
accessToken,
refreshToken,
profile,
done,
req,
);
if (!user) {
throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials);
}
done(null, user);
} catch (err) {
done(err);
}
};
}
createCallbackWithoutReq(verifyFn: VerifyFunction.AzureADAuthFn) {
return async (
iss: string,
sub: string,
profile: IProfile,
accessToken: string,
refreshToken: string,
done: VerifyCallback,
) => {
if (!profile.oid) {
return done(new Error('No oid found'), null);
}

try {
const user = await verifyFn(accessToken, refreshToken, profile, done);
if (!user) {
throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials);
}
done(null, user);
} catch (err) {
done(err);
}
};
}

getAzureADAuthStrategyVerifier(
options: IOIDCStrategyOptionWithoutRequest | IOIDCStrategyOptionWithRequest,
Expand All @@ -40,74 +93,14 @@ export class AzureADAuthStrategyFactoryProvider
if (options && options.passReqToCallback === true) {
return new OIDCStrategy(
options,

// eslint-disable-next-line @typescript-eslint/no-misused-promises
async (
req: Request,
iss: string,
sub: string,
profile: IProfile,
accessToken: string,
refreshToken: string,
done: VerifyCallback,
) => {
if (!profile.oid) {
return done(new Error('No oid found'), null);
}

try {
const user = await verifyFn(
accessToken,
refreshToken,
profile,
done,
req,
);
if (!user) {
throw new HttpErrors.Unauthorized(
AuthErrorKeys.InvalidCredentials,
);
}
done(null, user);
} catch (err) {
done(err);
}
},
this.createCallbackWithReq(verifyFn),
);
} else if (options && options.passReqToCallback === false) {
return new OIDCStrategy(
options,

// eslint-disable-next-line @typescript-eslint/no-misused-promises
async (
iss: string,
sub: string,
profile: IProfile,
accessToken: string,
refreshToken: string,
done: VerifyCallback,
) => {
if (!profile.oid) {
return done(new Error('No oid found'), null);
}

try {
const user = await verifyFn(
accessToken,
refreshToken,
profile,
done,
);
if (!user) {
throw new HttpErrors.Unauthorized(
AuthErrorKeys.InvalidCredentials,
);
}
done(null, user);
} catch (err) {
done(err);
}
},
this.createCallbackWithoutReq(verifyFn),
);
} else {
throw new Error('Invalid value for passReqToCallback');
Expand Down
Loading

0 comments on commit 3c9386a

Please sign in to comment.