1import * as AWS from "@/AWS";
2import { SSHPublicKey, User } from "@/AWS/IAM";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import * as IAM from "@distilled.cloud/aws/iam";
6import { describe, expect } from "alchemy-test";
7import * as Effect from "effect/Effect";
8import { testSshPublicKey } from "./fixtures.ts";
9
10const { test } = Test.make({ providers: AWS.providers() });
11
12describe(
13 "AWS.IAM.SSHPublicKey",
14 { tags: ["provider:aws", "provider:aws:iam", "live"] },
15 () => {
16 // Canonical `list()` test: IAM is a global service and `listSSHPublicKeys`
17 // requires a `UserName`, so the provider enumerates every user first and then
18 // lists keys per user, hydrating each via `getSSHPublicKey`. Deploy a real
19 // user + SSH key (with a checked-in valid RSA public key), resolve the
20 // provider from context with the typed `findProvider`, call `list()`, and
21 // assert the deployed key appears in the exhaustively-paginated result.
22 test.provider("list enumerates the deployed SSH public key", (stack) =>
23 Effect.gen(function* () {
24 yield* stack.destroy();
25
26 const deployed = yield* stack.deploy(
27 Effect.gen(function* () {
28 const user = yield* User("SSHKeyListOwner", {});
29 const key = yield* SSHPublicKey("SSHKeyListKey", {
30 userName: user.userName,
31 sshPublicKeyBody: testSshPublicKey,
32 });
33 return { user, key };
34 }),
35 );
36
37 const provider = yield* Provider.findProvider(SSHPublicKey);
38 const all = yield* provider.list();
39
40 const found = all.find(
41 (entry) => entry.sshPublicKeyId === deployed.key.sshPublicKeyId,
42 );
43 expect(found).toBeDefined();
44 expect(found?.userName).toBe(deployed.user.userName);
45 expect(found?.sshPublicKeyBody).toBeDefined();
46 expect(found?.fingerprint).toBeDefined();
47
48 yield* stack.destroy();
49
50 // The user (and with it the SSH public key) is gone.
51 const deletedUser = yield* IAM.getUser({
52 UserName: deployed.user.userName,
53 }).pipe(Effect.option);
54 expect(deletedUser._tag).toBe("None");
55 }),
56 );
57 },
58);