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 { ProfilePermission, SigningProfile } from "@alchemy.run/aws/Signer"; |
| 3 | import { describe, expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as signer from "@distilled.cloud/aws/signer"; |
| 6 | import * as sts from "@distilled.cloud/aws/sts"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | describe( |
| 12 | "AWS.Signer.ProfilePermission", |
| 13 | { tags: ["provider:aws", "provider:aws:signer", "live"] }, |
| 14 | () => { |
| 15 | test.provider( |
| 16 | "adds a cross-account permission, converges action changes in place, removes on destroy", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | yield* stack.destroy(); |
| 20 | |
| 21 | const { Account } = yield* sts.getCallerIdentity({}); |
| 22 | const principal = Account!; |
| 23 | |
| 24 | // CREATE |
| 25 | const created = yield* stack.deploy( |
| 26 | Effect.gen(function* () { |
| 27 | const profile = yield* SigningProfile("PermProfile", { |
| 28 | platformId: "AWSLambda-SHA384-ECDSA", |
| 29 | }); |
| 30 | const permission = yield* ProfilePermission("CiCanSign", { |
| 31 | profileName: profile.profileName, |
| 32 | action: "signer:StartSigningJob", |
| 33 | principal, |
| 34 | }); |
| 35 | return { profileName: permission.profileName, statementId: permission.statementId }; |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | // Verify out-of-band via distilled |
| 40 | const observed = yield* signer.listProfilePermissions({ |
| 41 | profileName: created.profileName, |
| 42 | }); |
| 43 | const statement = (observed.permissions ?? []).find( |
| 44 | (p) => p.statementId === created.statementId, |
| 45 | ); |
| 46 | expect(statement).toBeDefined(); |
| 47 | expect(statement!.action).toBe("signer:StartSigningJob"); |
| 48 | expect(statement!.principal).toBe(principal); |
| 49 | |
| 50 | // UPDATE — no update API: the provider removes + re-adds under the |
| 51 | // SAME statement id (no replacement of the logical resource). |
| 52 | const updated = yield* stack.deploy( |
| 53 | Effect.gen(function* () { |
| 54 | const profile = yield* SigningProfile("PermProfile", { |
| 55 | platformId: "AWSLambda-SHA384-ECDSA", |
| 56 | }); |
| 57 | const permission = yield* ProfilePermission("CiCanSign", { |
| 58 | profileName: profile.profileName, |
| 59 | action: "signer:GetSigningProfile", |
| 60 | principal, |
| 61 | }); |
| 62 | return { profileName: permission.profileName, statementId: permission.statementId }; |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(updated.profileName).toEqual(created.profileName); |
| 67 | expect(updated.statementId).toEqual(created.statementId); |
| 68 | |
| 69 | const afterUpdate = yield* signer.listProfilePermissions({ |
| 70 | profileName: created.profileName, |
| 71 | }); |
| 72 | const updatedStatement = (afterUpdate.permissions ?? []).find( |
| 73 | (p) => p.statementId === created.statementId, |
| 74 | ); |
| 75 | expect(updatedStatement).toBeDefined(); |
| 76 | expect(updatedStatement!.action).toBe("signer:GetSigningProfile"); |
| 77 | |
| 78 | // DESTROY — the statement is removed (the profile is canceled by its |
| 79 | // own delete, but its policy must no longer contain our statement). |
| 80 | yield* stack.destroy(); |
| 81 | const afterDestroy = yield* signer |
| 82 | .listProfilePermissions({ profileName: created.profileName }) |
| 83 | .pipe( |
| 84 | Effect.catchTag("ResourceNotFoundException", () => |
| 85 | Effect.succeed({ |
| 86 | permissions: [] as signer.Permission[], |
| 87 | } as signer.ListProfilePermissionsResponse), |
| 88 | ), |
| 89 | ); |
| 90 | expect( |
| 91 | (afterDestroy.permissions ?? []).find((p) => p.statementId === created.statementId), |
| 92 | ).toBeUndefined(); |
| 93 | }), |
| 94 | { timeout: 120_000 }, |
| 95 | ); |
| 96 | }, |
| 97 | ); |