Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Option from "effect/Option";
4import { ServerSecretStore } from "../auth/ServerSecretStore.ts";
5import * as ProviderCredentialStore from "./ProviderCredentialStore.ts";
6
7it.effect("isolates provider bindings and preserves opaque credentials", () =>
8 Effect.gen(function* () {
9 const data = new Map<string, Uint8Array>();
10 const secretStore = ServerSecretStore.of({
11 get: (name) => Effect.sync(() => Option.fromUndefinedOr(data.get(name))),
12 set: (name, value) =>
13 Effect.sync(() => {
14 data.set(name, value);
15 }),
16 remove: (name) =>
17 Effect.sync(() => {
18 data.delete(name);
19 }),
20 create: () => Effect.die("unused"),
21 getOrCreateRandom: () => Effect.die("unused"),
22 });
23 const a = yield* ProviderCredentialStore.make("cursor", "../../personal").pipe(
24 Effect.provideService(ServerSecretStore, secretStore),
25 );
26 const b = yield* ProviderCredentialStore.make("cursor", "work").pipe(
27 Effect.provideService(ServerSecretStore, secretStore),
28 );
29 const c = yield* ProviderCredentialStore.make("other", "../../personal").pipe(
30 Effect.provideService(ServerSecretStore, secretStore),
31 );
32 const bytes = Uint8Array.from([0, 255, 128, 1]);
33 yield* a.set(bytes);
34 assert.deepStrictEqual(Option.getOrThrow(yield* a.get), bytes);
35 assert.isTrue(Option.isNone(yield* b.get));
36 assert.isTrue(Option.isNone(yield* c.get));
37 assert.isFalse(a.binding.key.includes("/"));
38 const long = yield* ProviderCredentialStore.make("a".repeat(64), "b".repeat(64)).pipe(
39 Effect.provideService(ServerSecretStore, secretStore),
40 );
41 assert.isBelow(long.binding.key.length, 255);
42 const delimiter = yield* ProviderCredentialStore.make("cur", "sor../../personal").pipe(
43 Effect.provideService(ServerSecretStore, secretStore),
44 );
45 assert.notStrictEqual(delimiter.binding.key, a.binding.key);
46 yield* a.remove;
47 assert.isTrue(Option.isNone(yield* a.get));
48 }),
49);