| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as firebaseappcheck from "@distilled.cloud/gcp/firebaseappcheck_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | logLevel, |
| 8 | runLifecycle, |
| 9 | missingResourcePolicy, |
| 10 | waitUntilResourcePolicyGone, |
| 11 | } from "./common.ts"; |
| 12 | |
| 13 | const { test } = Test.make({ providers: GCP.providers() }); |
| 14 | |
| 15 | test.provider( |
| 16 | "getProjectsServicesResourcePolicies on a missing policy fails with a typed tag", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | yield* stack.destroy(); |
| 20 | |
| 21 | const missing = yield* missingResourcePolicy(); |
| 22 | const error = yield* Effect.flip( |
| 23 | firebaseappcheck.getProjectsServicesResourcePolicies({ |
| 24 | name: missing, |
| 25 | }), |
| 26 | ); |
| 27 | expect(error._tag).toEqual("ServiceDisabled"); |
| 28 | |
| 29 | yield* stack.destroy(); |
| 30 | }).pipe(logLevel), |
| 31 | { |
| 32 | tags: ["provider:gcp", "provider:gcp:firebaseappcheck", "live"], |
| 33 | timeout: 90_000, |
| 34 | }, |
| 35 | ); |
| 36 | |
| 37 | test.provider.skipIf(!runLifecycle)( |
| 38 | "create, update, and delete a resource policy", |
| 39 | (stack) => |
| 40 | Effect.gen(function* () { |
| 41 | yield* stack.destroy(); |
| 42 | |
| 43 | const created = yield* stack.deploy( |
| 44 | Effect.gen(function* () { |
| 45 | return yield* GCP.FirebaseAppCheck.ServicesResourcePolicy( |
| 46 | "IosOauth", |
| 47 | { enforcementMode: "UNENFORCED" }, |
| 48 | ); |
| 49 | }), |
| 50 | ); |
| 51 | |
| 52 | expect(created.name).toContain("/resourcePolicies/"); |
| 53 | expect(created.resourcePolicyId).toEqual(expect.any(String)); |
| 54 | expect(created.serviceId).toEqual("oauth2.googleapis.com"); |
| 55 | expect(created.enforcementMode).toEqual("UNENFORCED"); |
| 56 | expect(created.targetResource).toContain("/oauthClients/alc-"); |
| 57 | |
| 58 | const fetched = |
| 59 | yield* firebaseappcheck.getProjectsServicesResourcePolicies({ |
| 60 | name: created.name, |
| 61 | }); |
| 62 | expect(fetched.name).toEqual(created.name); |
| 63 | expect(fetched.enforcementMode).toEqual("UNENFORCED"); |
| 64 | expect(fetched.targetResource).toEqual(created.targetResource); |
| 65 | |
| 66 | const updated = yield* stack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | return yield* GCP.FirebaseAppCheck.ServicesResourcePolicy( |
| 69 | "IosOauth", |
| 70 | { |
| 71 | targetResource: created.targetResource, |
| 72 | enforcementMode: "OFF", |
| 73 | }, |
| 74 | ); |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | expect(updated.name).toEqual(created.name); |
| 79 | expect(updated.enforcementMode).toEqual("OFF"); |
| 80 | expect(updated.targetResource).toEqual(created.targetResource); |
| 81 | |
| 82 | yield* stack.destroy(); |
| 83 | |
| 84 | const gone = yield* waitUntilResourcePolicyGone(created.name); |
| 85 | expect(gone).toEqual("gone"); |
| 86 | }).pipe(logLevel), |
| 87 | { |
| 88 | tags: ["provider:gcp", "provider:gcp:firebaseappcheck", "live"], |
| 89 | timeout: 90_000, |
| 90 | }, |
| 91 | ); |