@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 82 lines 2.78 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as agw2 from "@distilled.cloud/aws/apigatewayv2";
5 import * as Effect from "effect/Effect";
6
7 const { test } = Test.make({ providers: AWS.providers() });
8
9 // CreateAuthorizer validates that the issuer serves a live
10 // `/.well-known/openid-configuration` discovery document (probed:
11 // BadRequestException "Issuer must have a valid discovery endpoint" for
12 // placeholder domains). Tokens are only validated at request time, so any
13 // stable public OIDC issuer exercises the CRUD lifecycle.
14 const ISSUER = "https://accounts.google.com";
15
16 test.provider(
17 "create, update, delete JWT authorizer",
18 (stack) =>
19 Effect.gen(function* () {
20 yield* stack.destroy();
21
22 const deployAuthorizer = (audience: string[]) =>
23 stack.deploy(
24 Effect.gen(function* () {
25 const api = yield* AWS.ApiGatewayV2.Api("AuthApi", {});
26 const authorizer = yield* AWS.ApiGatewayV2.Authorizer("JwtAuthorizer", {
27 api,
28 authorizerType: "JWT",
29 identitySource: ["$request.header.Authorization"],
30 jwtConfiguration: {
31 Issuer: ISSUER,
32 Audience: audience,
33 },
34 });
35 return {
36 apiId: api.apiId,
37 authorizerId: authorizer.authorizerId,
38 name: authorizer.name,
39 };
40 }),
41 );
42
43 const out = yield* deployAuthorizer(["aud-1"]);
44 expect(out.authorizerId).toBeTruthy();
45
46 // Out-of-band verification via distilled.
47 const remote = yield* agw2.getAuthorizer({
48 ApiId: out.apiId,
49 AuthorizerId: out.authorizerId,
50 });
51 expect(remote.AuthorizerType).toBe("JWT");
52 expect(remote.JwtConfiguration?.Issuer).toBe(ISSUER);
53 expect(remote.JwtConfiguration?.Audience).toEqual(["aud-1"]);
54
55 // Update the audience in place (same authorizerId).
56 const updated = yield* deployAuthorizer(["aud-1", "aud-2"]);
57 expect(updated.authorizerId).toBe(out.authorizerId);
58
59 const afterUpdate = yield* agw2.getAuthorizer({
60 ApiId: out.apiId,
61 AuthorizerId: out.authorizerId,
62 });
63 expect(afterUpdate.JwtConfiguration?.Audience).toEqual(["aud-1", "aud-2"]);
64
65 yield* stack.destroy();
66
67 const gone = yield* agw2
68 .getAuthorizer({
69 ApiId: out.apiId,
70 AuthorizerId: out.authorizerId,
71 })
72 .pipe(
73 Effect.map(() => "still-exists" as const),
74 Effect.catchTag("NotFoundException", () => Effect.succeed("deleted" as const)),
75 );
76 expect(gone).toBe("deleted");
77 }),
78 {
79 tags: ["provider:aws", "provider:aws:apigatewayv2", "live"],
80 timeout: 240_000,
81 },
82 );