| 1 | import * as AWS from "@/AWS"; |
| 2 | import { SigningCertificate, User } from "@/AWS/IAM"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import * as IAM from "@distilled.cloud/aws/iam"; |
| 6 | import { describe, expect } from "alchemy-test"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { testCertificateBody } from "./fixtures.ts"; |
| 9 | import { withSigningCertificateFixture } from "./SigningCertificateTestLease.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: AWS.providers() }); |
| 12 | |
| 13 | describe( |
| 14 | "AWS.IAM.SigningCertificate", |
| 15 | { tags: ["provider:aws", "provider:aws:iam", "live"] }, |
| 16 | () => { |
| 17 | // Canonical `list()` test: IAM is a global service and |
| 18 | // `listSigningCertificates` requires a `UserName`, so the provider enumerates |
| 19 | // every user first and then lists certificates per user. Deploy a real user + |
| 20 | // signing certificate (with a checked-in valid X.509 certificate body), |
| 21 | // resolve the provider from context with the typed `findProvider`, call |
| 22 | // `list()`, and assert the deployed certificate appears in the |
| 23 | // exhaustively-paginated result. |
| 24 | test.provider("list enumerates the deployed signing certificate", (stack) => |
| 25 | withSigningCertificateFixture( |
| 26 | Effect.gen(function* () { |
| 27 | yield* stack.destroy(); |
| 28 | |
| 29 | const deployed = yield* stack.deploy( |
| 30 | Effect.gen(function* () { |
| 31 | const user = yield* User("SigningCertListOwner", {}); |
| 32 | const certificate = yield* SigningCertificate( |
| 33 | "SigningCertListCert", |
| 34 | { |
| 35 | userName: user.userName, |
| 36 | certificateBody: testCertificateBody, |
| 37 | }, |
| 38 | ); |
| 39 | return { user, certificate }; |
| 40 | }), |
| 41 | ); |
| 42 | |
| 43 | const provider = yield* Provider.findProvider(SigningCertificate); |
| 44 | const all = yield* provider.list(); |
| 45 | |
| 46 | const found = all.find( |
| 47 | (entry) => |
| 48 | entry.certificateId === deployed.certificate.certificateId, |
| 49 | ); |
| 50 | expect(found).toBeDefined(); |
| 51 | expect(found?.userName).toBe(deployed.user.userName); |
| 52 | expect(found?.certificateBody).toBeDefined(); |
| 53 | expect(found?.status).toBe("Active"); |
| 54 | |
| 55 | yield* stack.destroy(); |
| 56 | |
| 57 | // The user (and with it the signing certificate) is gone. |
| 58 | const deletedUser = yield* IAM.getUser({ |
| 59 | UserName: deployed.user.userName, |
| 60 | }).pipe(Effect.option); |
| 61 | expect(deletedUser._tag).toBe("None"); |
| 62 | }), |
| 63 | ), |
| 64 | ); |
| 65 | }, |
| 66 | ); |