Skip to content

Commit 3c9386a

Browse files
fix(chore): resolving sonar smells to improve quality gate (#171)
* 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
1 parent 99e0b2f commit 3c9386a

28 files changed

+419
-444
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"bracketSpacing": false,
33
"singleQuote": true,
44
"printWidth": 80,
5-
"trailingComma": "all"
5+
"trailingComma": "all",
6+
"arrowParens": "avoid"
67
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/providers/client-authentication.provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class ClientAuthenticateActionProvider
1818
) {}
1919

2020
value(): AuthenticateFn<IAuthClient | undefined> {
21-
return (request) => this.action(request);
21+
return request => this.action(request);
2222
}
2323

2424
async action(request: Request): Promise<IAuthClient | undefined> {

src/release_notes/post-processing.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ module.exports = async function (data, callback) {
1010
const commitTitle = commit.title;
1111
commit.title = commitTitle.substring(0, commitTitle.indexOf('#') - 1);
1212

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

17-
commit.messageLines.forEach((message) => {
17+
commit.messageLines.forEach(message => {
1818
commit.issueno = message.includes('GH-')
1919
? message.replace('GH-', '').trim()
2020
: null;
2121
});
2222

23-
const issueDesc = await getIssueDesc(commit.issueno).then((res) => {
23+
const issueDesc = await getIssueDesc(commit.issueno).then(res => {
2424
return res;
2525
});
2626
commit.issueTitle = issueDesc;
@@ -48,9 +48,9 @@ function getIssueDesc(issueNo) {
4848
`https://github.com/sourcefuse/loopback4-authentication/issues/${encodeURIComponent(
4949
issueNo,
5050
)}`,
51-
(res) => {
51+
res => {
5252
res.setEncoding('utf8');
53-
res.on('data', (chunk) => {
53+
res.on('data', chunk => {
5454
result = result + chunk;
5555
});
5656
res.on('end', () => {
@@ -69,7 +69,7 @@ function getIssueDesc(issueNo) {
6969
});
7070
},
7171
);
72-
req.on('error', (e) => {
72+
req.on('error', e => {
7373
reject(e);
7474
});
7575
req.end();

src/release_notes/release-notes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function addAndCommit() {
5353
await git.push('origin', 'master');
5454
}
5555

56-
generateReleaseNotes().catch((ex) => {
56+
generateReleaseNotes().catch(ex => {
5757
console.error(ex);
5858
process.exit(1);
5959
});

src/strategies/SAML/saml-strategy-factory-provider.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import {
1414
import {AuthErrorKeys} from '../../error-keys';
1515
import {Strategies} from '../../keys';
1616
import {VerifyFunction} from '../../types';
17-
export interface SamlStrategyFactory {
18-
(options: SamlConfig, verifierPassed?: VerifyFunction.SamlFn): Strategy;
19-
}
17+
export type SamlStrategyFactory = (
18+
options: SamlConfig,
19+
verifierPassed?: VerifyFunction.SamlFn,
20+
) => Strategy;
2021

2122
export class SamlStrategyFactoryProvider
2223
implements Provider<SamlStrategyFactory>

src/strategies/SAML/saml-verify.provider.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import {VerifyFunction} from '../../types';
1212
* It will just throw an error saying Not Implemented
1313
*/
1414
export class SamlVerifyProvider implements Provider<VerifyFunction.SamlFn> {
15-
constructor() {
16-
//This is intentional
17-
}
18-
1915
value(): VerifyFunction.SamlFn {
2016
return async (
2117
profile: SamlStrategy.Profile,

src/strategies/passport/passport-apple-oauth2/apple-auth-strategy-factory-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class AppleAuthStrategyFactoryProvider
4040
): Strategy {
4141
const verifyFn = verifierPassed ?? this.verifierAppleAuth;
4242
let strategy;
43-
if (options && options.passReqToCallback === true) {
43+
if (options?.passReqToCallback === true) {
4444
strategy = new Strategy(
4545
options,
4646

src/strategies/passport/passport-apple-oauth2/apple-auth-verify.provider.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {VerifyFunction} from '../../types';
1010
export class AppleAuthVerifyProvider
1111
implements Provider<VerifyFunction.AppleAuthFn>
1212
{
13-
constructor() {}
14-
1513
value(): VerifyFunction.AppleAuthFn {
1614
return async (
1715
accessToken: string,

src/strategies/passport/passport-azure-ad/azuread-auth-strategy-factory-provider.ts

Lines changed: 61 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import {
1212
IOIDCStrategyOptionWithoutRequest,
1313
} from 'passport-azure-ad';
1414

15-
export interface AzureADAuthStrategyFactory {
16-
(
17-
options: IOIDCStrategyOptionWithoutRequest | IOIDCStrategyOptionWithRequest,
18-
verifierPassed?: VerifyFunction.AzureADAuthFn,
19-
): OIDCStrategy;
20-
}
15+
export type AzureADAuthStrategyFactory = (
16+
options: IOIDCStrategyOptionWithoutRequest | IOIDCStrategyOptionWithRequest,
17+
verifierPassed?: VerifyFunction.AzureADAuthFn,
18+
) => OIDCStrategy;
2119

2220
export class AzureADAuthStrategyFactoryProvider
2321
implements Provider<AzureADAuthStrategyFactory>
@@ -31,6 +29,61 @@ export class AzureADAuthStrategyFactoryProvider
3129
return (options, verifier) =>
3230
this.getAzureADAuthStrategyVerifier(options, verifier);
3331
}
32+
createCallbackWithReq(verifyFn: VerifyFunction.AzureADAuthFn) {
33+
return async (
34+
req: Request,
35+
iss: string,
36+
sub: string,
37+
profile: IProfile,
38+
accessToken: string,
39+
refreshToken: string,
40+
done: VerifyCallback,
41+
) => {
42+
if (!profile.oid) {
43+
return done(new Error('No oid found'), null);
44+
}
45+
46+
try {
47+
const user = await verifyFn(
48+
accessToken,
49+
refreshToken,
50+
profile,
51+
done,
52+
req,
53+
);
54+
if (!user) {
55+
throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials);
56+
}
57+
done(null, user);
58+
} catch (err) {
59+
done(err);
60+
}
61+
};
62+
}
63+
createCallbackWithoutReq(verifyFn: VerifyFunction.AzureADAuthFn) {
64+
return async (
65+
iss: string,
66+
sub: string,
67+
profile: IProfile,
68+
accessToken: string,
69+
refreshToken: string,
70+
done: VerifyCallback,
71+
) => {
72+
if (!profile.oid) {
73+
return done(new Error('No oid found'), null);
74+
}
75+
76+
try {
77+
const user = await verifyFn(accessToken, refreshToken, profile, done);
78+
if (!user) {
79+
throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials);
80+
}
81+
done(null, user);
82+
} catch (err) {
83+
done(err);
84+
}
85+
};
86+
}
3487

3588
getAzureADAuthStrategyVerifier(
3689
options: IOIDCStrategyOptionWithoutRequest | IOIDCStrategyOptionWithRequest,
@@ -40,74 +93,14 @@ export class AzureADAuthStrategyFactoryProvider
4093
if (options && options.passReqToCallback === true) {
4194
return new OIDCStrategy(
4295
options,
43-
4496
// eslint-disable-next-line @typescript-eslint/no-misused-promises
45-
async (
46-
req: Request,
47-
iss: string,
48-
sub: string,
49-
profile: IProfile,
50-
accessToken: string,
51-
refreshToken: string,
52-
done: VerifyCallback,
53-
) => {
54-
if (!profile.oid) {
55-
return done(new Error('No oid found'), null);
56-
}
57-
58-
try {
59-
const user = await verifyFn(
60-
accessToken,
61-
refreshToken,
62-
profile,
63-
done,
64-
req,
65-
);
66-
if (!user) {
67-
throw new HttpErrors.Unauthorized(
68-
AuthErrorKeys.InvalidCredentials,
69-
);
70-
}
71-
done(null, user);
72-
} catch (err) {
73-
done(err);
74-
}
75-
},
97+
this.createCallbackWithReq(verifyFn),
7698
);
7799
} else if (options && options.passReqToCallback === false) {
78100
return new OIDCStrategy(
79101
options,
80-
81102
// eslint-disable-next-line @typescript-eslint/no-misused-promises
82-
async (
83-
iss: string,
84-
sub: string,
85-
profile: IProfile,
86-
accessToken: string,
87-
refreshToken: string,
88-
done: VerifyCallback,
89-
) => {
90-
if (!profile.oid) {
91-
return done(new Error('No oid found'), null);
92-
}
93-
94-
try {
95-
const user = await verifyFn(
96-
accessToken,
97-
refreshToken,
98-
profile,
99-
done,
100-
);
101-
if (!user) {
102-
throw new HttpErrors.Unauthorized(
103-
AuthErrorKeys.InvalidCredentials,
104-
);
105-
}
106-
done(null, user);
107-
} catch (err) {
108-
done(err);
109-
}
110-
},
103+
this.createCallbackWithoutReq(verifyFn),
111104
);
112105
} else {
113106
throw new Error('Invalid value for passReqToCallback');

0 commit comments

Comments
 (0)