1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

Fix SingleUserStateProvider (#7593)

* Fix SingleUserStateProvider

- Fix cache key to be unique per instance per user

* Add Specific State Provider Tests

* Add Missing await
This commit is contained in:
Justin Baur
2024-01-18 13:02:30 -05:00
committed by GitHub
parent 5810b0c7a2
commit 57609737f1
4 changed files with 152 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
import { Opaque } from "type-fest";
import { UserId } from "../../types/guid";
import { KeyDefinition } from "./key-definition";
import { StateDefinition } from "./state-definition";
@@ -109,4 +111,24 @@ describe("KeyDefinition", () => {
expect(deserializedValue[1]).toBeFalsy();
});
});
describe("buildCacheKey", () => {
const keyDefinition = new KeyDefinition(fakeStateDefinition, "fake", {
deserializer: (s) => s,
});
it("builds unique cache key for each user", () => {
const cacheKeys: string[] = [];
// single user keys
cacheKeys.push(keyDefinition.buildCacheKey("user", "1" as UserId));
cacheKeys.push(keyDefinition.buildCacheKey("user", "2" as UserId));
expect(new Set(cacheKeys).size).toBe(cacheKeys.length);
});
it("throws with bad usage", () => {
expect(() => keyDefinition.buildCacheKey("user", null)).toThrow();
});
});
});