Skip to content

Commit b6803ba

Browse files
committed
fix linter/tests to merge to dev
1 parent 93f0021 commit b6803ba

12 files changed

+162
-113
lines changed

lib/msal-common/test/client/AuthorizationCodeClient.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import {
1717
} from "../utils/StringConstants";
1818
import { ClientConfiguration } from "../../src/config/ClientConfiguration";
1919
import { BaseClient } from "../../src/client/BaseClient";
20-
import { AADServerParamKeys, PromptValue, ResponseMode, SSOTypes } from "../../src/utils/Constants";
20+
import { AADServerParamKeys, PromptValue, ResponseMode, SSOTypes, Prompt } from "../../src/utils/Constants";
2121
import { ClientTestUtils } from "./ClientTestUtils";
2222
import { B2cAuthority } from "../../src/authority/B2cAuthority";
2323

2424
describe("AuthorizationCodeClient unit tests", () => {
2525

2626
afterEach(() => {
27-
config = null;
27+
let config = null;
2828
sinon.restore();
2929
while (B2cAuthority.B2CTrustedHostList.length) {
3030
B2cAuthority.B2CTrustedHostList.pop();
@@ -102,7 +102,7 @@ describe("AuthorizationCodeClient unit tests", () => {
102102
codeChallenge: TEST_CONFIG.TEST_CHALLENGE,
103103
codeChallengeMethod: TEST_CONFIG.CODE_CHALLENGE_METHOD,
104104
state: TEST_CONFIG.STATE,
105-
prompt: PromptValue.SELECT_ACCOUNT,
105+
prompt: Prompt.SELECT_ACCOUNT,
106106
loginHint: TEST_CONFIG.LOGIN_HINT,
107107
domainHint: TEST_CONFIG.DOMAIN_HINT,
108108
claims: TEST_CONFIG.CLAIMS,

lib/msal-common/test/client/ClientTestUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ClientTestUtils {
3131
return {
3232
authOptions: {
3333
clientId: TEST_CONFIG.MSAL_CLIENT_ID,
34-
authority: TEST_CONFIG.validAuthority,
34+
authority: authority,
3535
knownAuthorities: [],
3636
},
3737
storageInterface: {

lib/msal-node/src/cache/CacheContext.ts

+26-17
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,54 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import {
7-
JsonCache,
8-
Deserializer
9-
} from '@azure/msal-common';
6+
import { JsonCache, Deserializer } from '@azure/msal-common';
107
import { Storage } from '../cache/Storage';
118

129
/**
1310
* class managing sync between the persistent cache blob in the disk and the in memory cache of the node
1411
*/
1512
export class CacheContext {
16-
1713
private defaultSerializedCache: JsonCache = {
1814
Account: {},
1915
IdToken: {},
2016
AccessToken: {},
2117
RefreshToken: {},
22-
AppMetadata: {}
18+
AppMetadata: {},
2319
};
2420

25-
constructor() {}
26-
2721
/**
2822
* Update the library cache
2923
* @param storage
3024
*/
3125
setCurrentCache(storage: Storage, cacheObject: JsonCache) {
3226
const cacheWithOverlayedDefaults = this.overlayDefaults(cacheObject);
33-
storage.setCache(Deserializer.deserializeAllCache(cacheWithOverlayedDefaults));
27+
storage.setCache(
28+
Deserializer.deserializeAllCache(cacheWithOverlayedDefaults)
29+
);
3430
}
3531

36-
37-
overlayDefaults (passedInCache: JsonCache): JsonCache {
32+
overlayDefaults(passedInCache: JsonCache): JsonCache {
3833
return {
39-
Account: { ...this.defaultSerializedCache.Account, ...passedInCache.Account },
40-
IdToken: { ...this.defaultSerializedCache.IdToken, ...passedInCache.IdToken },
41-
AccessToken: { ...this.defaultSerializedCache.AccessToken, ...passedInCache.AccessToken },
42-
RefreshToken: { ...this.defaultSerializedCache.RefreshToken, ...passedInCache.RefreshToken },
43-
AppMetadata: { ...this.defaultSerializedCache.AppMetadata, ...passedInCache.AppMetadata}
34+
Account: {
35+
...this.defaultSerializedCache.Account,
36+
...passedInCache.Account,
37+
},
38+
IdToken: {
39+
...this.defaultSerializedCache.IdToken,
40+
...passedInCache.IdToken,
41+
},
42+
AccessToken: {
43+
...this.defaultSerializedCache.AccessToken,
44+
...passedInCache.AccessToken,
45+
},
46+
RefreshToken: {
47+
...this.defaultSerializedCache.RefreshToken,
48+
...passedInCache.RefreshToken,
49+
},
50+
AppMetadata: {
51+
...this.defaultSerializedCache.AppMetadata,
52+
...passedInCache.AppMetadata,
53+
},
4454
};
4555
}
46-
4756
}

lib/msal-node/src/cache/Storage.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License.
44
*/
5-
import {
6-
ICacheStorage,
7-
InMemoryCache
8-
} from '@azure/msal-common';
5+
import { ICacheStorage, InMemoryCache } from '@azure/msal-common';
96
import { CacheOptions } from '../config/Configuration';
107

118
/**
129
* This class implements Storage for node, reading cache from user specified storage location or an extension library
1310
*/
1411
export class Storage implements ICacheStorage {
1512
// Cache configuration, either set by user or default values.
16-
private cacheConfig: CacheOptions;;
13+
private cacheConfig: CacheOptions;
1714
private inMemoryCache: InMemoryCache;
1815

1916
constructor(cacheConfig: CacheOptions) {
2017
this.cacheConfig = cacheConfig;
21-
if (this.cacheConfig.cacheLocation! === "fileCache")
18+
if (this.cacheConfig.cacheLocation! === 'fileCache')
2219
this.inMemoryCache = this.cacheConfig.cacheInMemory!;
2320
}
2421

lib/msal-node/src/client/ClientApplication.ts

+49-26
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ import {
1717
Constants,
1818
B2cAuthority,
1919
JsonCache,
20-
Serializer
20+
Serializer,
2121
} from '@azure/msal-common';
2222
import { Configuration, buildAppConfiguration } from '../config/Configuration';
2323
import { CryptoProvider } from '../crypto/CryptoProvider';
2424
import { Storage } from '../cache/Storage';
2525
import { version } from '../../package.json';
26-
import { Constants as NodeConstants } from "./../utils/Constants";
26+
import { Constants as NodeConstants } from './../utils/Constants';
2727
import { CacheContext } from '../cache/CacheContext';
2828

2929
export abstract class ClientApplication {
30-
3130
private config: Configuration;
3231
private _authority: Authority;
3332
private readonly cryptoProvider: CryptoProvider;
@@ -37,7 +36,7 @@ export abstract class ClientApplication {
3736
/**
3837
* @constructor
3938
* Constructor for the ClientApplication
40-
*/
39+
*/
4140
protected constructor(configuration: Configuration) {
4241
this.config = buildAppConfiguration(configuration);
4342

@@ -57,10 +56,15 @@ export abstract class ClientApplication {
5756
* acquireToken(AuthorizationCodeRequest)
5857
* @param request
5958
*/
60-
async getAuthCodeUrl(request: AuthorizationCodeUrlRequest): Promise<string> {
61-
62-
const authClientConfig = await this.buildOauthClientConfiguration(request.authority);
63-
const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
59+
async getAuthCodeUrl(
60+
request: AuthorizationCodeUrlRequest
61+
): Promise<string> {
62+
const authClientConfig = await this.buildOauthClientConfiguration(
63+
request.authority
64+
);
65+
const authorizationCodeClient = new AuthorizationCodeClient(
66+
authClientConfig
67+
);
6468
return authorizationCodeClient.getAuthCodeUrl(request);
6569
}
6670

@@ -74,10 +78,15 @@ export abstract class ClientApplication {
7478
*
7579
* @param request
7680
*/
77-
async acquireTokenByCode(request: AuthorizationCodeRequest): Promise<AuthenticationResult> {
78-
79-
const authClientConfig = await this.buildOauthClientConfiguration(request.authority);
80-
const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
81+
async acquireTokenByCode(
82+
request: AuthorizationCodeRequest
83+
): Promise<AuthenticationResult> {
84+
const authClientConfig = await this.buildOauthClientConfiguration(
85+
request.authority
86+
);
87+
const authorizationCodeClient = new AuthorizationCodeClient(
88+
authClientConfig
89+
);
8190
return authorizationCodeClient.acquireToken(request);
8291
}
8392

@@ -89,33 +98,42 @@ export abstract class ClientApplication {
8998
* handle the caching and refreshing of tokens automatically.
9099
* @param request
91100
*/
92-
async acquireTokenByRefreshToken(request: RefreshTokenRequest): Promise<string> {
93-
94-
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(request.authority);
95-
const refreshTokenClient = new RefreshTokenClient(refreshTokenClientConfig);
101+
async acquireTokenByRefreshToken(
102+
request: RefreshTokenRequest
103+
): Promise<string> {
104+
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(
105+
request.authority
106+
);
107+
const refreshTokenClient = new RefreshTokenClient(
108+
refreshTokenClientConfig
109+
);
96110
return refreshTokenClient.acquireToken(request);
97111
}
98112

99-
protected async buildOauthClientConfiguration(authority?: string): Promise<ClientConfiguration> {
113+
protected async buildOauthClientConfiguration(
114+
authority?: string
115+
): Promise<ClientConfiguration> {
100116
// using null assertion operator as we ensure that all config values have default values in buildConfiguration()
101117
return {
102118
authOptions: {
103119
clientId: this.config.auth.clientId,
104120
authority: await this.createAuthority(authority),
105-
knownAuthorities: this.config.auth.knownAuthorities
121+
knownAuthorities: this.config.auth.knownAuthorities,
106122
},
107123
loggerOptions: {
108-
loggerCallback: this.config.system!.loggerOptions!.loggerCallback,
109-
piiLoggingEnabled: this.config.system!.loggerOptions!.piiLoggingEnabled,
124+
loggerCallback: this.config.system!.loggerOptions!
125+
.loggerCallback,
126+
piiLoggingEnabled: this.config.system!.loggerOptions!
127+
.piiLoggingEnabled,
110128
},
111129
cryptoInterface: this.cryptoProvider,
112130
networkInterface: this.config.system!.networkClient,
113131
storageInterface: this.storage,
114132
libraryInfo: {
115133
sku: NodeConstants.MSAL_SKU,
116134
version: version,
117-
cpu: process.arch || "",
118-
os: process.platform || ""
135+
cpu: process.arch || '',
136+
os: process.platform || '',
119137
},
120138
};
121139
}
@@ -125,12 +143,17 @@ export abstract class ClientApplication {
125143
* object. If no authority set in application object, then default to common authority.
126144
* @param authorityString
127145
*/
128-
private async createAuthority(authorityString?: string): Promise<Authority> {
146+
private async createAuthority(
147+
authorityString?: string
148+
): Promise<Authority> {
129149
const authority: Authority = authorityString
130-
? AuthorityFactory.createInstance(authorityString, this.config.system!.networkClient!)
150+
? AuthorityFactory.createInstance(
151+
authorityString,
152+
this.config.system!.networkClient!
153+
)
131154
: this.authority;
132155

133-
if(authority.discoveryComplete()){
156+
if (authority.discoveryComplete()) {
134157
return authority;
135158
}
136159

@@ -160,7 +183,7 @@ export abstract class ClientApplication {
160183
* @param cacheObject
161184
*/
162185
initializeCache(cacheObject: JsonCache) {
163-
this.cacheContext.setCurrentCache(this.storage, cacheObject)
186+
this.cacheContext.setCurrentCache(this.storage, cacheObject);
164187
}
165188

166189
/**

lib/msal-node/src/client/PublicClientApplication.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ClientApplication } from './ClientApplication';
1212
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
1313
*/
1414
export class PublicClientApplication extends ClientApplication {
15-
1615
/**
1716
* @constructor
1817
*
@@ -48,8 +47,12 @@ export class PublicClientApplication extends ClientApplication {
4847
* until the end-user completes input of credentials.
4948
* @param request
5049
*/
51-
public async acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<string>{
52-
const deviceCodeConfig = await this.buildOauthClientConfiguration(request.authority);
50+
public async acquireTokenByDeviceCode(
51+
request: DeviceCodeRequest
52+
): Promise<string> {
53+
const deviceCodeConfig = await this.buildOauthClientConfiguration(
54+
request.authority
55+
);
5356
const deviceCodeClient = new DeviceCodeClient(deviceCodeConfig);
5457
return deviceCodeClient.acquireToken(request);
5558
}

lib/msal-node/src/config/Configuration.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@azure/msal-common';
1111
import { NetworkUtils } from '../utils/NetworkUtils';
1212
import { CACHE } from '../utils/Constants';
13-
import debug from "debug";
13+
import debug from 'debug';
1414

1515
/**
1616
* - clientId - Client id of the application.
@@ -21,7 +21,7 @@ export type NodeAuthOptions = {
2121
clientId: string;
2222
authority?: string;
2323
knownAuthorities?: Array<string>;
24-
}
24+
};
2525

2626
/**
2727
* Use this to configure the below cache configuration options:
@@ -63,7 +63,7 @@ export type Configuration = {
6363
const DEFAULT_AUTH_OPTIONS: NodeAuthOptions = {
6464
clientId: '',
6565
authority: '',
66-
knownAuthorities: []
66+
knownAuthorities: [],
6767
};
6868

6969
const DEFAULT_CACHE_OPTIONS: CacheOptions = {
@@ -79,8 +79,12 @@ const DEFAULT_CACHE_OPTIONS: CacheOptions = {
7979
};
8080

8181
const DEFAULT_LOGGER_OPTIONS: LoggerOptions = {
82-
loggerCallback: (level: LogLevel, message: string, containsPii: boolean) => {
83-
debug(`msal:${LogLevel[level]}${containsPii ? "-Pii": ""}`)(message);
82+
loggerCallback: (
83+
level: LogLevel,
84+
message: string,
85+
containsPii: boolean
86+
) => {
87+
debug(`msal:${LogLevel[level]}${containsPii ? '-Pii' : ''}`)(message);
8488
},
8589
piiLoggingEnabled: false,
8690
logLevel: LogLevel.Info,

lib/msal-node/src/utils/Constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ export const CACHE = {
4343
* Constants for headers
4444
*/
4545
export const Constants = {
46-
MSAL_SKU: "msal.js.node",
46+
MSAL_SKU: 'msal.js.node',
4747
};

0 commit comments

Comments
 (0)