Skip to content

Commit 78334c2

Browse files
authored
Merge pull request #1444 from AzureAD/msal-node-cache-entities
[msal-node] Cache-1: Msal node cache entities
2 parents ad1a86c + b6803ba commit 78334c2

File tree

71 files changed

+2964
-655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2964
-655
lines changed

lib/msal-browser/src/cache/BrowserStorage.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License.
44
*/
5-
import { ICacheStorage, Constants, PersistentCacheKeys, TemporaryCacheKeys } from "@azure/msal-common";
5+
import { ICacheStorage, Constants, PersistentCacheKeys, TemporaryCacheKeys, InMemoryCache } from "@azure/msal-common";
66
import { CacheOptions } from "../config/Configuration";
77
import { BrowserAuthError } from "../error/BrowserAuthError";
88
import { BrowserConfigurationAuthError } from "../error/BrowserConfigurationAuthError";
@@ -251,4 +251,24 @@ export class BrowserStorage implements ICacheStorage {
251251
const expr = new Date(today.getTime() + cookieLifeDays * COOKIE_LIFE_MULTIPLIER);
252252
return expr.toUTCString();
253253
}
254+
255+
/**
256+
* Dummy implementation until browser cache is migrated
257+
*/
258+
getCache(): InMemoryCache {
259+
return {
260+
accounts: {},
261+
idTokens: {},
262+
accessTokens: {},
263+
refreshTokens: {},
264+
appMetadata: {}
265+
};
266+
}
267+
268+
/**
269+
* Dummy implementation until browser cache is migrated
270+
*/
271+
setCache() {
272+
// sets nothing
273+
}
254274
}

lib/msal-browser/test/interaction_handler/InteractionHandler.spec.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "chai";
22
import { InteractionHandler } from "../../src/interaction_handler/InteractionHandler";
3-
import { SPAClient, PkceCodes, NetworkRequestOptions, LogLevel, CodeResponse, Account, TokenResponse } from "@azure/msal-common";
3+
import { SPAClient, PkceCodes, NetworkRequestOptions, LogLevel, CodeResponse, Account, TokenResponse, InMemoryCache } from "@azure/msal-common";
44
import { Configuration, buildConfiguration } from "../../src/config/Configuration";
55
import { TEST_CONFIG, RANDOM_TEST_GUID, TEST_URIS, TEST_DATA_CLIENT_INFO, TEST_TOKENS, TEST_TOKEN_LIFETIMES, TEST_HASHES } from "../utils/StringConstants";
66
import { BrowserStorage } from "../../src/cache/BrowserStorage";
@@ -15,11 +15,11 @@ class TestInteractionHandler extends InteractionHandler {
1515

1616
showUI(requestUrl: string): Window {
1717
throw new Error("Method not implemented.");
18-
}
19-
18+
}
19+
2020
initiateAuthRequest(requestUrl: string): Window | Promise<HTMLIFrameElement> {
2121
throw new Error("Method not implemented.");
22-
}
22+
}
2323
}
2424

2525
const clearFunc = (): void => {
@@ -77,6 +77,18 @@ describe("InteractionHandler.ts Unit Tests", () => {
7777
}
7878
},
7979
storageInterface: {
80+
getCache: (): InMemoryCache => {
81+
return {
82+
accounts: {},
83+
idTokens: {},
84+
accessTokens: {},
85+
refreshTokens: {},
86+
appMetadata: {},
87+
};
88+
},
89+
setCache: (): void => {
90+
// dummy impl;
91+
},
8092
clear: clearFunc,
8193
containsKey: (key: string): boolean => {
8294
return true;

lib/msal-browser/test/interaction_handler/PopupHandler.spec.ts

+35-12
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import chai from "chai";
22
import chaiAsPromised from "chai-as-promised"
33
chai.use(chaiAsPromised);
44
const expect = chai.expect;
5-
import { PkceCodes, SPAClient, NetworkRequestOptions, LogLevel, Account, TokenResponse, CodeResponse } from "@azure/msal-common";
5+
import { PkceCodes, SPAClient, NetworkRequestOptions, LogLevel, InMemoryCache } from "@azure/msal-common";
66
import { PopupHandler } from "../../src/interaction_handler/PopupHandler";
77
import { BrowserStorage } from "../../src/cache/BrowserStorage";
88
import { Configuration, buildConfiguration } from "../../src/config/Configuration";
9-
import { TEST_CONFIG, TEST_TOKENS, TEST_TOKEN_LIFETIMES, TEST_DATA_CLIENT_INFO, TEST_URIS, RANDOM_TEST_GUID, TEST_HASHES } from "../utils/StringConstants";
9+
import { TEST_CONFIG, TEST_URIS } from "../utils/StringConstants";
1010
import sinon from "sinon";
1111
import { InteractionHandler } from "../../src/interaction_handler/InteractionHandler";
1212
import { BrowserAuthErrorMessage, BrowserAuthError } from "../../src/error/BrowserAuthError";
@@ -50,8 +50,9 @@ describe("PopupHandler.ts Unit Tests", () => {
5050
const authCodeModule = new SPAClient({
5151
authOptions: configObj.auth,
5252
systemOptions: {
53-
tokenRenewalOffsetSeconds: configObj.system.tokenRenewalOffsetSeconds,
54-
telemetry: configObj.system.telemetry
53+
tokenRenewalOffsetSeconds:
54+
configObj.system.tokenRenewalOffsetSeconds,
55+
telemetry: configObj.system.telemetry,
5556
},
5657
cryptoInterface: {
5758
createNewGuid: (): string => {
@@ -65,9 +66,21 @@ describe("PopupHandler.ts Unit Tests", () => {
6566
},
6667
generatePkceCodes: async (): Promise<PkceCodes> => {
6768
return testPkceCodes;
68-
}
69+
},
6970
},
7071
storageInterface: {
72+
getCache: (): InMemoryCache => {
73+
return {
74+
accounts: {},
75+
idTokens: {},
76+
accessTokens: {},
77+
refreshTokens: {},
78+
appMetadata: {},
79+
};
80+
},
81+
setCache: (): void => {
82+
// dummy impl;
83+
},
7184
clear: clearFunc,
7285
containsKey: (key: string): boolean => {
7386
return true;
@@ -79,24 +92,34 @@ describe("PopupHandler.ts Unit Tests", () => {
7992
return testKeySet;
8093
},
8194
removeItem: removeFunc,
82-
setItem: setFunc
95+
setItem: setFunc,
8396
},
8497
networkInterface: {
85-
sendGetRequestAsync: async (url: string, options?: NetworkRequestOptions): Promise<any> => {
98+
sendGetRequestAsync: async (
99+
url: string,
100+
options?: NetworkRequestOptions
101+
): Promise<any> => {
86102
return testNetworkResult;
87103
},
88-
sendPostRequestAsync: async (url: string, options?: NetworkRequestOptions): Promise<any> => {
104+
sendPostRequestAsync: async (
105+
url: string,
106+
options?: NetworkRequestOptions
107+
): Promise<any> => {
89108
return testNetworkResult;
90-
}
109+
},
91110
},
92111
loggerOptions: {
93-
loggerCallback: (level: LogLevel, message: string, containsPii: boolean): void => {
112+
loggerCallback: (
113+
level: LogLevel,
114+
message: string,
115+
containsPii: boolean
116+
): void => {
94117
if (containsPii) {
95118
console.log(`Log level: ${level} Message: ${message}`);
96119
}
97120
},
98-
piiLoggingEnabled: true
99-
}
121+
piiLoggingEnabled: true,
122+
},
100123
});
101124
browserStorage = new BrowserStorage(TEST_CONFIG.MSAL_CLIENT_ID, configObj.cache);
102125
popupHandler = new PopupHandler(authCodeModule, browserStorage);

lib/msal-browser/test/interaction_handler/RedirectHandler.spec.ts

+34-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import chaiAsPromised from "chai-as-promised"
33
chai.use(chaiAsPromised);
44
const expect = chai.expect;
55
import { Configuration, buildConfiguration } from "../../src/config/Configuration";
6-
import { SPAClient, PkceCodes, NetworkRequestOptions, LogLevel, TemporaryCacheKeys, CodeResponse, TokenResponse, Account } from "@azure/msal-common";
6+
import { SPAClient, PkceCodes, NetworkRequestOptions, LogLevel, TemporaryCacheKeys, CodeResponse, TokenResponse, Account, InMemoryCache } from "@azure/msal-common";
77
import { TEST_CONFIG, TEST_URIS, TEST_TOKENS, TEST_DATA_CLIENT_INFO, RANDOM_TEST_GUID, TEST_HASHES, TEST_TOKEN_LIFETIMES } from "../utils/StringConstants";
88
import { BrowserStorage } from "../../src/cache/BrowserStorage";
99
import { RedirectHandler } from "../../src/interaction_handler/RedirectHandler";
@@ -50,8 +50,9 @@ describe("RedirectHandler.ts Unit Tests", () => {
5050
const authCodeModule = new SPAClient({
5151
authOptions: configObj.auth,
5252
systemOptions: {
53-
tokenRenewalOffsetSeconds: configObj.system.tokenRenewalOffsetSeconds,
54-
telemetry: configObj.system.telemetry
53+
tokenRenewalOffsetSeconds:
54+
configObj.system.tokenRenewalOffsetSeconds,
55+
telemetry: configObj.system.telemetry,
5556
},
5657
cryptoInterface: {
5758
createNewGuid: (): string => {
@@ -65,9 +66,21 @@ describe("RedirectHandler.ts Unit Tests", () => {
6566
},
6667
generatePkceCodes: async (): Promise<PkceCodes> => {
6768
return testPkceCodes;
68-
}
69+
},
6970
},
7071
storageInterface: {
72+
getCache: (): InMemoryCache => {
73+
return {
74+
accounts: {},
75+
idTokens: {},
76+
accessTokens: {},
77+
refreshTokens: {},
78+
appMetadata: {},
79+
};
80+
},
81+
setCache: (): void => {
82+
// dummy impl;
83+
},
7184
clear: clearFunc,
7285
containsKey: (key: string): boolean => {
7386
return true;
@@ -79,24 +92,34 @@ describe("RedirectHandler.ts Unit Tests", () => {
7992
return testKeySet;
8093
},
8194
removeItem: removeFunc,
82-
setItem: setFunc
95+
setItem: setFunc,
8396
},
8497
networkInterface: {
85-
sendGetRequestAsync: async (url: string, options?: NetworkRequestOptions): Promise<any> => {
98+
sendGetRequestAsync: async (
99+
url: string,
100+
options?: NetworkRequestOptions
101+
): Promise<any> => {
86102
return testNetworkResult;
87103
},
88-
sendPostRequestAsync: async (url: string, options?: NetworkRequestOptions): Promise<any> => {
104+
sendPostRequestAsync: async (
105+
url: string,
106+
options?: NetworkRequestOptions
107+
): Promise<any> => {
89108
return testNetworkResult;
90-
}
109+
},
91110
},
92111
loggerOptions: {
93-
loggerCallback: (level: LogLevel, message: string, containsPii: boolean): void => {
112+
loggerCallback: (
113+
level: LogLevel,
114+
message: string,
115+
containsPii: boolean
116+
): void => {
94117
if (containsPii) {
95118
console.log(`Log level: ${level} Message: ${message}`);
96119
}
97120
},
98-
piiLoggingEnabled: true
99-
}
121+
piiLoggingEnabled: true,
122+
},
100123
});
101124
browserStorage = new BrowserStorage(TEST_CONFIG.MSAL_CLIENT_ID, configObj.cache);
102125
redirectHandler = new RedirectHandler(authCodeModule, browserStorage);

lib/msal-browser/test/interaction_handler/SilentHandler.spec.ts

+34-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import chai from "chai";
22
import chaiAsPromised from "chai-as-promised"
33
chai.use(chaiAsPromised);
44
const expect = chai.expect;
5-
import { PkceCodes, SPAClient, NetworkRequestOptions, LogLevel } from "@azure/msal-common";
5+
import { PkceCodes, SPAClient, NetworkRequestOptions, LogLevel, InMemoryCache } from "@azure/msal-common";
66
import sinon from "sinon";
77
import { SilentHandler } from "../../src/interaction_handler/SilentHandler";
88
import { BrowserStorage } from "../../src/cache/BrowserStorage";
@@ -50,8 +50,9 @@ describe("SilentHandler.ts Unit Tests", () => {
5050
authCodeModule = new SPAClient({
5151
authOptions: configObj.auth,
5252
systemOptions: {
53-
tokenRenewalOffsetSeconds: configObj.system.tokenRenewalOffsetSeconds,
54-
telemetry: configObj.system.telemetry
53+
tokenRenewalOffsetSeconds:
54+
configObj.system.tokenRenewalOffsetSeconds,
55+
telemetry: configObj.system.telemetry,
5556
},
5657
cryptoInterface: {
5758
createNewGuid: (): string => {
@@ -65,9 +66,21 @@ describe("SilentHandler.ts Unit Tests", () => {
6566
},
6667
generatePkceCodes: async (): Promise<PkceCodes> => {
6768
return testPkceCodes;
68-
}
69+
},
6970
},
7071
storageInterface: {
72+
getCache: (): InMemoryCache => {
73+
return {
74+
accounts: {},
75+
idTokens: {},
76+
accessTokens: {},
77+
refreshTokens: {},
78+
appMetadata: {},
79+
};
80+
},
81+
setCache: (): void => {
82+
// dummy impl;
83+
},
7184
clear: clearFunc,
7285
containsKey: (key: string): boolean => {
7386
return true;
@@ -79,24 +92,34 @@ describe("SilentHandler.ts Unit Tests", () => {
7992
return testKeySet;
8093
},
8194
removeItem: removeFunc,
82-
setItem: setFunc
95+
setItem: setFunc,
8396
},
8497
networkInterface: {
85-
sendGetRequestAsync: async (url: string, options?: NetworkRequestOptions): Promise<any> => {
98+
sendGetRequestAsync: async (
99+
url: string,
100+
options?: NetworkRequestOptions
101+
): Promise<any> => {
86102
return testNetworkResult;
87103
},
88-
sendPostRequestAsync: async (url: string, options?: NetworkRequestOptions): Promise<any> => {
104+
sendPostRequestAsync: async (
105+
url: string,
106+
options?: NetworkRequestOptions
107+
): Promise<any> => {
89108
return testNetworkResult;
90-
}
109+
},
91110
},
92111
loggerOptions: {
93-
loggerCallback: (level: LogLevel, message: string, containsPii: boolean): void => {
112+
loggerCallback: (
113+
level: LogLevel,
114+
message: string,
115+
containsPii: boolean
116+
): void => {
94117
if (containsPii) {
95118
console.log(`Log level: ${level} Message: ${message}`);
96119
}
97120
},
98-
piiLoggingEnabled: true
99-
}
121+
piiLoggingEnabled: true,
122+
},
100123
});
101124
browserStorage = new BrowserStorage(TEST_CONFIG.MSAL_CLIENT_ID, configObj.cache);
102125
silentHandler = new SilentHandler(authCodeModule, browserStorage, DEFAULT_IFRAME_TIMEOUT_MS);

lib/msal-common/src/authority/AuthorityFactory.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { StringUtils } from "./../utils/StringUtils";
1313
import { UrlString } from "./../url/UrlString";
1414
import { Constants } from "../utils/Constants";
1515

16-
export class AuthorityFactory {
16+
export class AuthorityFactory {
1717

1818
/**
1919
* Parse the url and determine the type of authority
@@ -43,6 +43,7 @@ export class AuthorityFactory {
4343
}
4444

4545
const type = AuthorityFactory.detectAuthorityFromUrl(authorityUrl);
46+
4647
// Depending on above detection, create the right type.
4748
switch (type) {
4849
case AuthorityType.Aad:

lib/msal-common/src/cache/CacheHelpers.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class CacheHelpers {
2323

2424
constructor(cacheImpl: ICacheStorage) {
2525
this.cacheStorage = cacheImpl;
26+
2627
}
2728

2829
/**
@@ -167,11 +168,11 @@ export class CacheHelpers {
167168

168169
/**
169170
* Checks that any parameters are exact matches for key value, since key.match in the above functions only do contains checks, not exact matches.
170-
* @param atKey
171-
* @param clientId
172-
* @param authority
173-
* @param resource
174-
* @param homeAccountIdentifier
171+
* @param atKey
172+
* @param clientId
173+
* @param authority
174+
* @param resource
175+
* @param homeAccountIdentifier
175176
*/
176177
private checkForExactKeyMatch(atKey: AccessTokenKey, clientId: string, authority: string, resource?: string, homeAccountIdentifier?: string): boolean {
177178
const hasClientId = (atKey.clientId === clientId);

0 commit comments

Comments
 (0)