| 1 | import * as Cloudflare from "@/Cloudflare"; |
| 2 | import { adopt } from "@/AdoptPolicy"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as Redacted from "effect/Redacted"; |
| 8 | import { MinimumLogLevel } from "effect/References"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: Cloudflare.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService( |
| 13 | MinimumLogLevel, |
| 14 | process.env.DEBUG ? "Debug" : "Info", |
| 15 | ); |
| 16 | |
| 17 | // Deterministic per-test names — same on every run. |
| 18 | const SET_LIST = "alchemy-vulnscanner-cred-list-set"; |
| 19 | const CRED_LIST = "alchemy-vulnscanner-cred-list"; |
| 20 | |
| 21 | test.provider( |
| 22 | "list enumerates the deployed credential", |
| 23 | (stack) => |
| 24 | Effect.gen(function* () { |
| 25 | yield* stack.destroy(); |
| 26 | |
| 27 | const deployed = yield* stack.deploy( |
| 28 | Effect.gen(function* () { |
| 29 | const set = |
| 30 | yield* Cloudflare.VulnerabilityScanner.VulnScannerCredentialSet( |
| 31 | "ListSet", |
| 32 | { |
| 33 | name: SET_LIST, |
| 34 | }, |
| 35 | ).pipe(adopt(true)); |
| 36 | const credential = |
| 37 | yield* Cloudflare.VulnerabilityScanner.VulnScannerCredential( |
| 38 | "ListCred", |
| 39 | { |
| 40 | credentialSetId: set.credentialSetId, |
| 41 | name: CRED_LIST, |
| 42 | location: "header", |
| 43 | locationName: "authorization", |
| 44 | value: Redacted.make("Bearer alchemy-list-test"), |
| 45 | }, |
| 46 | ).pipe(adopt(true)); |
| 47 | return { set, credential }; |
| 48 | }), |
| 49 | ); |
| 50 | |
| 51 | const provider = yield* Provider.findProvider( |
| 52 | Cloudflare.VulnerabilityScanner.VulnScannerCredential, |
| 53 | ); |
| 54 | const all = yield* provider.list(); |
| 55 | |
| 56 | // Parent fan-out over credential sets contains the deployed credential, |
| 57 | // each element shaped exactly like `read`'s Attributes (value is |
| 58 | // write-only and absent from both). |
| 59 | expect( |
| 60 | all.some((x) => x.credentialId === deployed.credential.credentialId), |
| 61 | ).toBe(true); |
| 62 | const found = all.find( |
| 63 | (x) => x.credentialId === deployed.credential.credentialId, |
| 64 | ); |
| 65 | expect(found?.credentialSetId).toEqual(deployed.set.credentialSetId); |
| 66 | expect(found?.name).toEqual(CRED_LIST); |
| 67 | expect(found?.location).toEqual("header"); |
| 68 | expect(found?.locationName).toEqual("authorization"); |
| 69 | expect(found?.accountId).toEqual(deployed.credential.accountId); |
| 70 | |
| 71 | yield* stack.destroy(); |
| 72 | }).pipe(logLevel), |
| 73 | { |
| 74 | tags: [ |
| 75 | "provider:cloudflare", |
| 76 | "provider:cloudflare:vulnerabilityscanner", |
| 77 | "live", |
| 78 | ], |
| 79 | }, |
| 80 | ); |