Skip to content

Commit d923b93

Browse files
authored
Merge pull request #1478 from AzureAD/sagonzal/msal-node-strict-null-checks
[msal-node] Switch strictNullChecks: true for msal-node
2 parents 9d999e3 + 73f9a0c commit d923b93

File tree

4 files changed

+35
-48
lines changed

4 files changed

+35
-48
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class Storage implements ICacheStorage {
3232
constructor(clientId: string, cacheConfig: CacheOptions) {
3333
this.cacheConfig = cacheConfig;
3434
this.fileStorage = this.initializeFileStorage(
35-
this.cacheConfig.cacheLocation
35+
this.cacheConfig.cacheLocation!
3636
);
3737
this.clientId = clientId;
3838
}

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

+10-23
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ export abstract class ClientApplication {
1818
// Input configuration by developer/user
1919
protected config: ClientConfiguration;
2020

21-
// Crypto interface implementation
22-
protected crypto: CryptoProvider;
23-
24-
// Storage interface implementation
25-
protected storage: Storage;
26-
27-
2821
/**
2922
* @constructor
3023
* Constructor for the ClientApplication to instantiate the PublicClientApplication object
@@ -47,18 +40,8 @@ export abstract class ClientApplication {
4740
* @param {@link (Configuration:type)} configuration object for the MSAL PublicClientApplication instance
4841
*/
4942
protected constructor(configuration: ClientConfiguration) {
50-
// Set the configuration.
51-
this.config = buildConfiguration(configuration);
52-
53-
// Initialize the crypto class.
54-
this.crypto = new CryptoProvider();
55-
// Initialize the network module class.
5643

57-
// Initialize the browser storage class.
58-
this.storage = new Storage(
59-
this.config.auth.clientId,
60-
this.config.cache
61-
);
44+
this.config = buildConfiguration(configuration);
6245
}
6346

6447
/**
@@ -94,15 +77,19 @@ export abstract class ClientApplication {
9477
}
9578

9679
protected buildOauthClientConfiguration(): Configuration {
80+
// using null assertion operator as we ensure that all config values have default values in buildConfiguration()
9781
return {
9882
authOptions: this.config.auth,
9983
loggerOptions: {
100-
loggerCallback: this.config.system.loggerOptions.loggerCallback,
101-
piiLoggingEnabled: this.config.system.loggerOptions.piiLoggingEnabled,
84+
loggerCallback: this.config.system!.loggerOptions!.loggerCallback,
85+
piiLoggingEnabled: this.config.system!.loggerOptions!.piiLoggingEnabled,
10286
},
103-
cryptoInterface: this.crypto,
104-
networkInterface: this.config.system.networkClient,
105-
storageInterface: this.storage,
87+
cryptoInterface: new CryptoProvider(),
88+
networkInterface: this.config.system!.networkClient,
89+
storageInterface: new Storage(
90+
this.config.auth!.clientId,
91+
this.config.cache!
92+
),
10693
};
10794
}
10895
}

lib/msal-node/test/config/ClientConfiguration.spec.ts

+23-23
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ describe('ClientConfiguration tests', () => {
1111
const config: ClientConfiguration = buildConfiguration({});
1212

1313
// network options
14-
expect(config.system.networkClient).toBeDefined();
15-
expect(config.system.networkClient).toBeInstanceOf(HttpClient);
16-
expect(config.system.networkClient.sendGetRequestAsync).toBeDefined();
17-
expect(config.system.networkClient.sendPostRequestAsync).toBeDefined();
14+
expect(config.system!.networkClient).toBeDefined();
15+
expect(config.system!.networkClient).toBeInstanceOf(HttpClient);
16+
expect(config.system!.networkClient!.sendGetRequestAsync).toBeDefined();
17+
expect(config.system!.networkClient!.sendPostRequestAsync).toBeDefined();
1818

1919
// logger options checks
2020
console.error = jest.fn();
2121
console.info = jest.fn();
2222
console.debug = jest.fn();
2323
console.warn = jest.fn();
2424

25-
expect(config.system.loggerOptions).toBeDefined();
26-
expect(config.system.loggerOptions.piiLoggingEnabled).toBe(false);
25+
expect(config.system!.loggerOptions).toBeDefined();
26+
expect(config.system!.loggerOptions!.piiLoggingEnabled).toBe(false);
2727

28-
config.system.loggerOptions.loggerCallback(LogLevel.Error,"error", false);
29-
config.system.loggerOptions.loggerCallback(LogLevel.Info,"info", false);
30-
config.system.loggerOptions.loggerCallback(LogLevel.Verbose,"verbose", false);
31-
config.system.loggerOptions.loggerCallback(LogLevel.Warning,"warning", false);
32-
config.system.loggerOptions.loggerCallback(LogLevel.Warning,"warning", true);
28+
config.system!.loggerOptions!.loggerCallback!(LogLevel.Error,"error", false);
29+
config.system!.loggerOptions!.loggerCallback!(LogLevel.Info,"info", false);
30+
config.system!.loggerOptions!.loggerCallback!(LogLevel.Verbose,"verbose", false);
31+
config.system!.loggerOptions!.loggerCallback!(LogLevel.Warning,"warning", false);
32+
config.system!.loggerOptions!.loggerCallback!(LogLevel.Warning,"warning", true);
3333

3434
expect(console.error).toHaveBeenLastCalledWith("error");
3535
expect(console.info).toHaveBeenLastCalledWith("info");
@@ -39,12 +39,12 @@ describe('ClientConfiguration tests', () => {
3939

4040

4141
// auth options
42-
expect(config.auth.authority).toEqual("");
43-
expect(config.auth.clientId).toEqual("");
42+
expect(config.auth!.authority).toEqual("");
43+
expect(config.auth!.clientId).toEqual("");
4444

4545
// cache options
46-
expect(config.cache.cacheLocation).toEqual(CACHE.FILE_CACHE);
47-
expect(config.cache.storeAuthStateInCookie).toEqual(false);
46+
expect(config.cache!.cacheLocation).toEqual(CACHE.FILE_CACHE);
47+
expect(config.cache!.storeAuthStateInCookie).toEqual(false);
4848
});
4949

5050
test('builds configuration and assigns default functions', () => {
@@ -92,19 +92,19 @@ describe('ClientConfiguration tests', () => {
9292
};
9393

9494
// network options
95-
expect(config.system.networkClient.sendGetRequestAsync(TEST_CONSTANTS.AUTH_CODE_URL, testNetworkOptions)).resolves.toEqual(testNetworkResult);
96-
expect(config.system.networkClient.sendPostRequestAsync(TEST_CONSTANTS.AUTH_CODE_URL, testNetworkOptions)).resolves.toEqual(testNetworkResult);
95+
expect(config.system!.networkClient!.sendGetRequestAsync(TEST_CONSTANTS.AUTH_CODE_URL, testNetworkOptions)).resolves.toEqual(testNetworkResult);
96+
expect(config.system!.networkClient!.sendPostRequestAsync(TEST_CONSTANTS.AUTH_CODE_URL, testNetworkOptions)).resolves.toEqual(testNetworkResult);
9797

9898
// Logger options checks
99-
expect(config.system.loggerOptions).toBeDefined();
100-
expect(config.system.loggerOptions.piiLoggingEnabled).toBe(true);
99+
expect(config.system!.loggerOptions).toBeDefined();
100+
expect(config.system!.loggerOptions!.piiLoggingEnabled).toBe(true);
101101

102102
// auth options
103-
expect(config.auth.authority).toEqual(TEST_CONSTANTS.AUTHORITY);
104-
expect(config.auth.clientId).toEqual(TEST_CONSTANTS.CLIENT_ID);
103+
expect(config.auth!.authority).toEqual(TEST_CONSTANTS.AUTHORITY);
104+
expect(config.auth!.clientId).toEqual(TEST_CONSTANTS.CLIENT_ID);
105105

106106
// cache options
107-
expect(config.cache.cacheLocation).toEqual(TEST_CONSTANTS.CACHE_LOCATION);
108-
expect(config.cache.storeAuthStateInCookie).toEqual(true);
107+
expect(config.cache!.cacheLocation).toEqual(TEST_CONSTANTS.CACHE_LOCATION);
108+
expect(config.cache!.storeAuthStateInCookie).toEqual(true);
109109
});
110110
});

lib/msal-node/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"rootDir": "./",
1111
"strict": true,
1212
"noImplicitAny": true,
13-
"strictNullChecks": false,
13+
"strictNullChecks": true,
1414
"strictFunctionTypes": true,
1515
"strictPropertyInitialization": false,
1616
"noImplicitThis": true,

0 commit comments

Comments
 (0)