UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

60 lines (56 loc) 2.5 kB
import { Temporal } from "@js-temporal/polyfill"; import { URLPattern } from "urlpattern-polyfill"; globalThis.addEventListener = () => {}; import { assertEquals } from "../assert_equals-CTYbeopb.js"; import { assert } from "../assert-DmFG7ppO.js"; import { assertInstanceOf } from "../assert_instance_of-CF09JHYM.js"; import { MemoryKvStore } from "../kv-BMY6Qf_A.js"; import "../docloader-C8mmLN-Y.js"; import "../url-kTAI6_KP.js"; import "../multibase-DeCHcK8L.js"; import { CryptographicKey, Multikey } from "../vocab-dDpPQ0fF.js"; import "../langstr-DbWheeIS.js"; import { KvKeyCache } from "../keycache-BPwY_Up0.js"; import { test } from "../testing-BZ0dJ4qn.js"; //#region federation/keycache.test.ts test("KvKeyCache.set()", async () => { const kv = new MemoryKvStore(); const cache = new KvKeyCache(kv, ["pk"]); await cache.set(new URL("https://example.com/key"), new CryptographicKey({ id: new URL("https://example.com/key") })); assertEquals(await kv.get(["pk", "https://example.com/key"]), { "@context": "https://w3id.org/security/v1", id: "https://example.com/key", type: "CryptographicKey" }); await cache.set(new URL("https://example.com/key2"), new Multikey({ id: new URL("https://example.com/key2") })); assertEquals(await kv.get(["pk", "https://example.com/key2"]), { "@context": "https://w3id.org/security/multikey/v1", id: "https://example.com/key2", type: "Multikey" }); await cache.set(new URL("https://example.com/null"), null); assert(cache.nullKeys.has("https://example.com/null")); }); test("KvKeyCache.get()", async () => { const kv = new MemoryKvStore(); const cache = new KvKeyCache(kv, ["pk"]); await kv.set(["pk", "https://example.com/key"], { "@context": "https://w3id.org/security/v1", id: "https://example.com/key", type: "CryptographicKey" }); const cryptoKey = await cache.get(new URL("https://example.com/key")); assertInstanceOf(cryptoKey, CryptographicKey); assertEquals(cryptoKey?.id?.href, "https://example.com/key"); await kv.set(["pk", "https://example.com/key2"], { "@context": "https://w3id.org/security/multikey/v1", id: "https://example.com/key2", type: "Multikey" }); const multikey = await cache.get(new URL("https://example.com/key2")); assertInstanceOf(multikey, Multikey); assertEquals(multikey?.id?.href, "https://example.com/key2"); cache.nullKeys.add("https://example.com/null"); assertEquals(await cache.get(new URL("https://example.com/null")), null); }); //#endregion