Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename TokenCache.cacheHasChanged to TokenCache.hasChanged #2332

Merged
merged 6 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Rename TokenCache.cacheHasChanged to TokenCache.hasChanged",
"packageName": "@azure/msal-node",
"email": "sagonzal@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-09-22T20:40:22.007Z"
}
16 changes: 8 additions & 8 deletions lib/msal-node/src/cache/TokenCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const defaultSerializedCache: JsonCache = {
export class TokenCache {

private storage: Storage;
private hasChanged: boolean;
private cacheHasChanged: boolean;
private cacheSnapshot: string;
private readonly persistence: ICachePlugin;
private logger: Logger;

constructor(storage: Storage, logger: Logger, cachePlugin?: ICachePlugin) {
this.hasChanged = false;
this.cacheHasChanged = false;
this.storage = storage;
this.storage.registerChangeEmitter(this.handleChangeEvent.bind(this));
if (cachePlugin) {
Expand All @@ -40,10 +40,10 @@ export class TokenCache {
}

/**
* Set to true if cache state has changed since last time serialized() or writeToPersistence was called
* Set to true if cache state has changed since last time serialize or writeToPersistence was called
*/
cacheHasChanged(): boolean {
return this.hasChanged;
get hasChanged(): boolean {
return this.cacheHasChanged;
}

/**
Expand All @@ -65,7 +65,7 @@ export class TokenCache {
} else {
this.logger.verbose("No cache snapshot to merge");
}
this.hasChanged = false;
this.cacheHasChanged = false;

return JSON.stringify(finalState);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ export class TokenCache {
};

await this.persistence.writeToStorage(getMergedState);
this.hasChanged = false;
this.cacheHasChanged = false;
} else {
throw ClientAuthError.createCachePluginError();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ export class TokenCache {
* Called when the cache has changed state.
*/
private handleChangeEvent() {
this.hasChanged = true;
this.cacheHasChanged = true;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions lib/msal-node/test/cache/TokenCache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("TokenCache tests", () => {
let storage: Storage = new Storage(logger);
const tokenCache = new TokenCache(storage, logger);
expect(tokenCache).toBeInstanceOf(TokenCache);
expect(tokenCache.cacheHasChanged()).toEqual(false);
expect(tokenCache.hasChanged()).toEqual(false);
expect(tokenCache.getAllAccounts()).toEqual([]);
});

Expand All @@ -37,11 +37,11 @@ describe("TokenCache tests", () => {
const tokenCache = new TokenCache(storage, logger);

tokenCache.deserialize(JSON.stringify(cache));
expect(tokenCache.cacheHasChanged()).toEqual(true);
expect(tokenCache.hasChanged()).toEqual(true);

const tokenCacheAfterSerialization = tokenCache.serialize();
expect(JSON.parse(tokenCacheAfterSerialization)).toEqual(cache);
expect(tokenCache.cacheHasChanged()).toEqual(false);
expect(tokenCache.hasChanged()).toEqual(false);
});

it("TokenCache serialize/deserialize, does not remove unrecognized entities", () => {
Expand All @@ -52,11 +52,11 @@ describe("TokenCache tests", () => {
const tokenCache = new TokenCache(storage, logger);

tokenCache.deserialize(JSON.stringify(cache));
expect(tokenCache.cacheHasChanged()).toEqual(true);
expect(tokenCache.hasChanged()).toEqual(true);

const tokenCacheAfterSerialization = tokenCache.serialize();
expect(JSON.parse(tokenCacheAfterSerialization)).toEqual(cache);
expect(tokenCache.cacheHasChanged()).toEqual(false);
expect(tokenCache.hasChanged()).toEqual(false);
});

it("TokenCache.mergeRemovals removes entities from the cache, but does not remove other entities", () => {
Expand All @@ -68,10 +68,10 @@ describe("TokenCache tests", () => {

tokenCache.deserialize(JSON.stringify(cache));
tokenCache.removeAccount(tokenCache.getAllAccounts()[0]);
expect(tokenCache.cacheHasChanged()).toEqual(true);
expect(tokenCache.hasChanged()).toEqual(true);

const tokenCacheAfterSerialization = JSON.parse(tokenCache.serialize());
expect(tokenCache.cacheHasChanged()).toEqual(false);
expect(tokenCache.hasChanged()).toEqual(false);
expect(tokenCacheAfterSerialization.Account).toEqual({});
expect(tokenCacheAfterSerialization.RefreshToken).toEqual({});
expect(tokenCacheAfterSerialization.AccessToken).toEqual({});
Expand Down Expand Up @@ -108,11 +108,11 @@ describe("TokenCache tests", () => {
const tokenCache = new TokenCache(storage, logger, cachePlugin);

await tokenCache.readFromPersistence()
expect(tokenCache.cacheHasChanged()).toBe(true);
expect(tokenCache.hasChanged()).toBe(true);
expect(tokenCache.getAllAccounts().length).toBe(1);

await tokenCache.writeToPersistence();
expect(tokenCache.cacheHasChanged()).toBe(false);
expect(tokenCache.hasChanged()).toBe(false);
expect(require('./cache-test-files/temp-cache.json')).toEqual(require('./cache-test-files/cache-unrecognized-entities.json'));

// try and clean up
Expand Down