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

main
ts 110 lines 3.77 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { AWSEnvironment } from "@alchemy.run/aws/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as ag from "@distilled.cloud/aws/api-gateway";
5 import * as Output from "alchemy/Output";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8 import { TestFunction, TestFunctionLive } from "../Lambda/handler.ts";
9 import { assertRestApiDeleted } from "./assertions.ts";
10 import * as Test from "./Test.ts";
11
12 const { test } = Test.make({ providers: AWS.providers() });
13
14 const authorizerUri = process.env.ALCHEMY_TEST_AUTHORIZER_URI;
15
16 /**
17 * Requires a Lambda authorizer invocation URI accepted by API Gateway.
18 */
19 test.provider.skipIf(!!process.env.FAST || !authorizerUri)(
20 "create and update Lambda TOKEN authorizer",
21 (stack) =>
22 Effect.gen(function* () {
23 yield* stack.destroy();
24
25 const uri = authorizerUri!;
26
27 const { api, authorizer } = yield* stack.deploy(
28 Effect.gen(function* () {
29 const api = yield* AWS.ApiGateway.RestApi("AgAuthorizerApi", {
30 endpointConfiguration: { types: ["REGIONAL"] },
31 });
32 const authorizer = yield* AWS.ApiGateway.Authorizer("AgAuthorizer", {
33 restApiId: api.restApiId,
34 type: "TOKEN",
35 authorizerUri: uri,
36 identitySource: "method.request.header.Authorization",
37 authorizerResultTtl: "60 seconds",
38 });
39 return { api, authorizer };
40 }),
41 );
42
43 yield* stack.deploy(
44 Effect.gen(function* () {
45 const apiAgain = yield* AWS.ApiGateway.RestApi("AgAuthorizerApi", {
46 endpointConfiguration: { types: ["REGIONAL"] },
47 });
48 yield* AWS.ApiGateway.Authorizer("AgAuthorizer", {
49 restApiId: apiAgain.restApiId,
50 type: "TOKEN",
51 authorizerUri: uri,
52 identitySource: "method.request.header.Authorization",
53 authorizerResultTtl: "120 seconds",
54 });
55 }),
56 );
57
58 const remote = yield* ag.getAuthorizer({
59 restApiId: api.restApiId,
60 authorizerId: authorizer.authorizerId,
61 });
62 expect(remote.authorizerResultTtlInSeconds).toEqual(120);
63
64 yield* stack.destroy();
65 yield* assertRestApiDeleted(api.restApiId);
66 }),
67 { tags: ["provider:aws", "provider:aws:apigateway", "live"] },
68 );
69
70 test.provider.skipIf(!!process.env.FAST)(
71 "list enumerates the deployed authorizer",
72 (stack) =>
73 Effect.gen(function* () {
74 yield* stack.destroy();
75
76 const { region } = yield* AWSEnvironment.current;
77
78 const { authorizer } = yield* stack.deploy(
79 Effect.gen(function* () {
80 const fn = yield* TestFunction.pipe(Effect.provide(TestFunctionLive));
81 const api = yield* AWS.ApiGateway.RestApi("AgAuthorizerListApi", {
82 endpointConfiguration: { types: ["REGIONAL"] },
83 });
84 const authorizer = yield* AWS.ApiGateway.Authorizer("AgAuthorizerList", {
85 restApiId: api.restApiId,
86 type: "TOKEN",
87 authorizerUri: Output.map(
88 fn.functionArn,
89 (arn: string) =>
90 `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${arn}/invocations`,
91 ),
92 identitySource: "method.request.header.Authorization",
93 });
94 return { authorizer };
95 }),
96 );
97
98 const provider = yield* Provider.findProvider(AWS.ApiGateway.Authorizer);
99 const all = yield* provider.list();
100
101 expect(all.some((a) => a.authorizerId === authorizer.authorizerId)).toBe(true);
102
103 yield* stack.destroy();
104 yield* assertRestApiDeleted(authorizer.restApiId);
105 }),
106 {
107 tags: ["provider:aws", "provider:aws:apigateway", "provider:aws:lambda", "live"],
108 timeout: 300_000,
109 },
110 );