The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { |
| 3 | ServiceSpecificCredential, |
| 4 | SigningCertificate, |
| 5 | SSHPublicKey, |
| 6 | User, |
| 7 | } from "@alchemy.run/aws/IAM"; |
| 8 | import { describe, expect } from "@alchemy.run/test"; |
| 9 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 10 | import * as IAM from "@distilled.cloud/aws/iam"; |
| 11 | import * as Effect from "effect/Effect"; |
| 12 | import { testCertificateBody, testSshPublicKey } from "./fixtures.ts"; |
| 13 | import { withSigningCertificateFixture } from "./SigningCertificateTestLease.ts"; |
| 14 | |
| 15 | const { test } = Test.make({ providers: AWS.providers() }); |
| 16 | |
| 17 | describe( |
| 18 | "AWS.IAM credential resources", |
| 19 | { tags: ["provider:aws", "provider:aws:iam", "live"] }, |
| 20 | () => { |
| 21 | test.provider("create, update, and delete a service-specific credential", (stack) => |
| 22 | Effect.gen(function* () { |
| 23 | yield* stack.destroy(); |
| 24 | |
| 25 | const deployed = yield* stack.deploy( |
| 26 | Effect.gen(function* () { |
| 27 | const user = yield* User("CredentialOwner", {}); |
| 28 | const credential = yield* ServiceSpecificCredential("ServiceCredential", { |
| 29 | userName: user.userName, |
| 30 | serviceName: "codecommit.amazonaws.com", |
| 31 | status: "Active", |
| 32 | }); |
| 33 | return { user, credential }; |
| 34 | }), |
| 35 | ); |
| 36 | |
| 37 | expect(deployed.credential.servicePassword).toBeDefined(); |
| 38 | |
| 39 | const created = yield* IAM.listServiceSpecificCredentials({ |
| 40 | UserName: deployed.user.userName, |
| 41 | ServiceName: deployed.credential.serviceName, |
| 42 | }); |
| 43 | expect( |
| 44 | created.ServiceSpecificCredentials?.some( |
| 45 | (entry) => |
| 46 | entry.ServiceSpecificCredentialId === deployed.credential.serviceSpecificCredentialId, |
| 47 | ), |
| 48 | ).toBe(true); |
| 49 | |
| 50 | yield* stack.deploy( |
| 51 | Effect.gen(function* () { |
| 52 | const user = yield* User("CredentialOwner", {}); |
| 53 | yield* ServiceSpecificCredential("ServiceCredential", { |
| 54 | userName: user.userName, |
| 55 | serviceName: "codecommit.amazonaws.com", |
| 56 | status: "Inactive", |
| 57 | }); |
| 58 | }), |
| 59 | ); |
| 60 | |
| 61 | const updated = yield* IAM.listServiceSpecificCredentials({ |
| 62 | UserName: deployed.user.userName, |
| 63 | ServiceName: deployed.credential.serviceName, |
| 64 | }); |
| 65 | const metadata = updated.ServiceSpecificCredentials?.find( |
| 66 | (entry) => |
| 67 | entry.ServiceSpecificCredentialId === deployed.credential.serviceSpecificCredentialId, |
| 68 | ); |
| 69 | expect(metadata?.Status).toBe("Inactive"); |
| 70 | |
| 71 | yield* stack.destroy(); |
| 72 | |
| 73 | const deleted = yield* IAM.listServiceSpecificCredentials({ |
| 74 | UserName: deployed.user.userName, |
| 75 | ServiceName: deployed.credential.serviceName, |
| 76 | }).pipe(Effect.option); |
| 77 | expect( |
| 78 | deleted._tag === "None" || |
| 79 | !deleted.value.ServiceSpecificCredentials?.some( |
| 80 | (entry) => |
| 81 | entry.ServiceSpecificCredentialId === |
| 82 | deployed.credential.serviceSpecificCredentialId, |
| 83 | ), |
| 84 | ).toBe(true); |
| 85 | }), |
| 86 | ); |
| 87 | |
| 88 | test.provider("create, update, and delete SSH and signing credentials for a user", (stack) => |
| 89 | withSigningCertificateFixture( |
| 90 | Effect.gen(function* () { |
| 91 | yield* stack.destroy(); |
| 92 | |
| 93 | const deployed = yield* stack.deploy( |
| 94 | Effect.gen(function* () { |
| 95 | const user = yield* User("CredentialUser", {}); |
| 96 | const sshKey = yield* SSHPublicKey("UserSshKey", { |
| 97 | userName: user.userName, |
| 98 | sshPublicKeyBody: testSshPublicKey, |
| 99 | status: "Active", |
| 100 | }); |
| 101 | const signingCertificate = yield* SigningCertificate("UserSigningCertificate", { |
| 102 | userName: user.userName, |
| 103 | certificateBody: testCertificateBody, |
| 104 | status: "Active", |
| 105 | }); |
| 106 | return { user, sshKey, signingCertificate }; |
| 107 | }), |
| 108 | ); |
| 109 | |
| 110 | const createdKey = yield* IAM.getSSHPublicKey({ |
| 111 | UserName: deployed.user.userName, |
| 112 | SSHPublicKeyId: deployed.sshKey.sshPublicKeyId, |
| 113 | Encoding: "SSH", |
| 114 | }); |
| 115 | expect(createdKey.SSHPublicKey?.Status).toBe("Active"); |
| 116 | |
| 117 | const createdCerts = yield* IAM.listSigningCertificates({ |
| 118 | UserName: deployed.user.userName, |
| 119 | }); |
| 120 | expect( |
| 121 | createdCerts.Certificates.some( |
| 122 | (entry) => entry.CertificateId === deployed.signingCertificate.certificateId, |
| 123 | ), |
| 124 | ).toBe(true); |
| 125 | |
| 126 | yield* stack.deploy( |
| 127 | Effect.gen(function* () { |
| 128 | const user = yield* User("CredentialUser", {}); |
| 129 | yield* SSHPublicKey("UserSshKey", { |
| 130 | userName: user.userName, |
| 131 | sshPublicKeyBody: testSshPublicKey, |
| 132 | status: "Inactive", |
| 133 | }); |
| 134 | yield* SigningCertificate("UserSigningCertificate", { |
| 135 | userName: user.userName, |
| 136 | certificateBody: testCertificateBody, |
| 137 | status: "Inactive", |
| 138 | }); |
| 139 | }), |
| 140 | ); |
| 141 | |
| 142 | const updatedKey = yield* IAM.getSSHPublicKey({ |
| 143 | UserName: deployed.user.userName, |
| 144 | SSHPublicKeyId: deployed.sshKey.sshPublicKeyId, |
| 145 | Encoding: "SSH", |
| 146 | }); |
| 147 | expect(updatedKey.SSHPublicKey?.Status).toBe("Inactive"); |
| 148 | |
| 149 | const updatedCerts = yield* IAM.listSigningCertificates({ |
| 150 | UserName: deployed.user.userName, |
| 151 | }); |
| 152 | const updatedCert = updatedCerts.Certificates.find( |
| 153 | (entry) => entry.CertificateId === deployed.signingCertificate.certificateId, |
| 154 | ); |
| 155 | expect(updatedCert?.Status).toBe("Inactive"); |
| 156 | |
| 157 | yield* stack.destroy(); |
| 158 | |
| 159 | const deletedKey = yield* IAM.getSSHPublicKey({ |
| 160 | UserName: deployed.user.userName, |
| 161 | SSHPublicKeyId: deployed.sshKey.sshPublicKeyId, |
| 162 | Encoding: "SSH", |
| 163 | }).pipe(Effect.option); |
| 164 | expect(deletedKey._tag).toBe("None"); |
| 165 | |
| 166 | const deletedCerts = yield* IAM.listSigningCertificates({ |
| 167 | UserName: deployed.user.userName, |
| 168 | }).pipe(Effect.option); |
| 169 | expect( |
| 170 | deletedCerts._tag === "None" || |
| 171 | !deletedCerts.value.Certificates.some( |
| 172 | (entry) => entry.CertificateId === deployed.signingCertificate.certificateId, |
| 173 | ), |
| 174 | ).toBe(true); |
| 175 | }), |
| 176 | ), |
| 177 | ); |
| 178 | }, |
| 179 | ); |