The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { UserPool, UserPoolClient } from "@alchemy.run/aws/Cognito"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as cip from "@distilled.cloud/aws/cognito-identity-provider"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | test.provider( |
| 11 | "create, update auth flows and validity, replace on generateSecret", |
| 12 | (stack) => |
| 13 | Effect.gen(function* () { |
| 14 | yield* stack.destroy(); |
| 15 | |
| 16 | const outputs = yield* stack.deploy( |
| 17 | Effect.gen(function* () { |
| 18 | const pool = yield* UserPool("ClientTestPool", {}); |
| 19 | const client = yield* UserPoolClient("Client", { |
| 20 | userPoolId: pool.userPoolId, |
| 21 | explicitAuthFlows: ["ALLOW_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"], |
| 22 | }); |
| 23 | return { pool, client }; |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | expect(outputs.client.clientId).toBeTruthy(); |
| 28 | expect(outputs.client.clientSecret).toBeUndefined(); |
| 29 | expect(outputs.client.userPoolId).toBe(outputs.pool.userPoolId); |
| 30 | |
| 31 | // out-of-band verification via distilled |
| 32 | const created = yield* cip.describeUserPoolClient({ |
| 33 | UserPoolId: outputs.pool.userPoolId, |
| 34 | ClientId: outputs.client.clientId, |
| 35 | }); |
| 36 | expect([...(created.UserPoolClient?.ExplicitAuthFlows ?? [])].sort()).toEqual([ |
| 37 | "ALLOW_REFRESH_TOKEN_AUTH", |
| 38 | "ALLOW_USER_PASSWORD_AUTH", |
| 39 | ]); |
| 40 | |
| 41 | // mutate token validity in place |
| 42 | const updated = yield* stack.deploy( |
| 43 | Effect.gen(function* () { |
| 44 | const pool = yield* UserPool("ClientTestPool", {}); |
| 45 | const client = yield* UserPoolClient("Client", { |
| 46 | userPoolId: pool.userPoolId, |
| 47 | explicitAuthFlows: ["ALLOW_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"], |
| 48 | accessTokenValidity: 30, |
| 49 | idTokenValidity: 30, |
| 50 | tokenValidityUnits: { accessToken: "minutes", idToken: "minutes" }, |
| 51 | }); |
| 52 | return { pool, client }; |
| 53 | }), |
| 54 | ); |
| 55 | expect(updated.client.clientId).toBe(outputs.client.clientId); |
| 56 | |
| 57 | const afterUpdate = yield* cip.describeUserPoolClient({ |
| 58 | UserPoolId: outputs.pool.userPoolId, |
| 59 | ClientId: outputs.client.clientId, |
| 60 | }); |
| 61 | expect(afterUpdate.UserPoolClient?.AccessTokenValidity).toBe(30); |
| 62 | expect(afterUpdate.UserPoolClient?.TokenValidityUnits?.AccessToken).toBe("minutes"); |
| 63 | |
| 64 | // generateSecret is immutable ⇒ replacement with a fresh client id |
| 65 | const replaced = yield* stack.deploy( |
| 66 | Effect.gen(function* () { |
| 67 | const pool = yield* UserPool("ClientTestPool", {}); |
| 68 | const client = yield* UserPoolClient("Client", { |
| 69 | userPoolId: pool.userPoolId, |
| 70 | generateSecret: true, |
| 71 | explicitAuthFlows: ["ALLOW_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"], |
| 72 | }); |
| 73 | return { pool, client }; |
| 74 | }), |
| 75 | ); |
| 76 | expect(replaced.client.clientId).not.toBe(outputs.client.clientId); |
| 77 | expect(replaced.client.clientSecret).toBeTruthy(); |
| 78 | |
| 79 | yield* stack.destroy(); |
| 80 | const gone = yield* cip |
| 81 | .describeUserPoolClient({ |
| 82 | UserPoolId: outputs.pool.userPoolId, |
| 83 | ClientId: replaced.client.clientId, |
| 84 | }) |
| 85 | .pipe( |
| 86 | Effect.map(() => false), |
| 87 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)), |
| 88 | ); |
| 89 | expect(gone).toBe(true); |
| 90 | }), |
| 91 | { tags: ["provider:aws", "provider:aws:cognito", "live"], timeout: 120_000 }, |
| 92 | ); |