@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 77 lines 3.13 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { IdentitySource, PolicyStore } from "@alchemy.run/aws/VerifiedPermissions";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as avp from "@distilled.cloud/aws/verifiedpermissions";
6 import * as Effect from "effect/Effect";
7 import * as Redacted from "effect/Redacted";
8
9 const unwrap = (v: string | Redacted.Redacted<string> | undefined) =>
10 v === undefined ? undefined : Redacted.isRedacted(v) ? Redacted.value(v) : v;
11
12 const { test } = Test.make({ providers: AWS.providers() });
13
14 const findSource = (policyStoreId: string, identitySourceId: string) =>
15 avp
16 .getIdentitySource({ policyStoreId, identitySourceId })
17 .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)));
18
19 test.provider(
20 "identity source lifecycle: create OIDC source, update client ids, destroy",
21 (stack) =>
22 Effect.gen(function* () {
23 yield* stack.destroy();
24
25 const makeStack = (clientIds: string[]) =>
26 Effect.gen(function* () {
27 const store = yield* PolicyStore("Store", {
28 validationMode: "OFF",
29 });
30 const source = yield* IdentitySource("Oidc", {
31 policyStoreId: store.policyStoreId,
32 principalEntityType: "PhotoApp::User",
33 openIdConnect: {
34 // AVP fetches /.well-known/openid-configuration at create time,
35 // so the issuer must be a live OIDC discovery endpoint
36 issuer: "https://accounts.google.com",
37 tokenSelection: {
38 identityTokenOnly: { clientIds },
39 },
40 },
41 });
42 return { store, source };
43 });
44
45 // create
46 const { store, source } = yield* stack.deploy(makeStack(["alchemy-test-client"]));
47 expect(source.identitySourceId).toBeDefined();
48 expect(source.policyStoreId).toBe(store.policyStoreId);
49
50 // out-of-band verify
51 const created = yield* findSource(store.policyStoreId, source.identitySourceId);
52 expect(unwrap(created?.principalEntityType)).toBe("PhotoApp::User");
53 expect(created?.configuration?.openIdConnectConfiguration?.issuer).toBe(
54 "https://accounts.google.com",
55 );
56
57 // update client ids in place (identitySourceId is stable)
58 const updated = yield* stack.deploy(makeStack(["alchemy-test-client", "second-client"]));
59 expect(updated.source.identitySourceId).toBe(source.identitySourceId);
60
61 const afterUpdate = yield* findSource(store.policyStoreId, source.identitySourceId);
62 const tokenSelection = afterUpdate?.configuration?.openIdConnectConfiguration?.tokenSelection;
63 const observedClientIds = (tokenSelection?.identityTokenOnly?.clientIds ?? []).map((id) =>
64 unwrap(id)!,
65 );
66 expect([...observedClientIds].sort()).toEqual(["alchemy-test-client", "second-client"]);
67
68 // destroy
69 yield* stack.destroy();
70 const gone = yield* findSource(store.policyStoreId, source.identitySourceId);
71 expect(gone).toBeUndefined();
72 }),
73 {
74 tags: ["provider:aws", "provider:aws:verifiedpermissions", "live"],
75 timeout: 180_000,
76 },
77 );