Prerequisites: docker compose -f docker-compose.federated.yml --profile federated up -d
DB-only: FEDERATED_INTEGRATION=1 pnpm --filter @mosaicstack/gateway test src/__tests__/integration/federation-m2.integration.test.ts
Design notes
CaService is mocked via useValue in DB-only tests so Step-CA env vars are not required
Two separate describe blocks with different gate conditions
Each test creates isolated data with a unique RUN_ID UUID prefix
afterAll cleans up in FK-safe order: tokens -> grants -> peers -> users
Uses createDb/DbHandle from @mosaicstack/db (avoids direct drizzle-orm/postgres-js import)
## Summary
Integration tests for the Mosaic federation M2 milestone (FED-M2-09).
Closes #461
### Tests covered
- **#1** — `createGrant` writes a `pending` row to DB; scope and status verified (`FEDERATED_INTEGRATION=1`)
- **#5** — `clientKeyPem` stored in DB is a sealed ciphertext, not a PEM (`FEDERATED_INTEGRATION=1`)
- **#7** — `createGrant` rejects scope with unknown resource type with `FederationScopeError` (`FEDERATED_INTEGRATION=1`)
- **#8** — `listGrants` returns accurate status for pending/revoked grants; peer list correct (`FEDERATED_INTEGRATION=1`)
- **#2** — `EnrollmentService.redeem` returns a valid PEM certificate via real Step-CA (`STEP_CA_AVAILABLE=1`)
- **#3** — Second `EnrollmentService.redeem` with the same token throws `GoneException` (`STEP_CA_AVAILABLE=1`)
### Gate env vars
DB-only tests (#1, #5, #7, #8): `FEDERATED_INTEGRATION=1`
Step-CA tests (#2, #3) additional vars:
- `STEP_CA_AVAILABLE=1`
- `STEP_CA_URL=https://localhost:9000`
- `STEP_CA_PROVISIONER_KEY_JSON` — from `docker exec $(docker ps -qf name=step-ca) cat /home/step/secrets/mosaic-fed.json`
- `STEP_CA_ROOT_CERT_PATH=/tmp/step-ca-root.crt` — copy from `docker cp $(docker ps -qf name=step-ca):/home/step/certs/root_ca.crt /tmp/step-ca-root.crt`
### How to run
Prerequisites: `docker compose -f docker-compose.federated.yml --profile federated up -d`
DB-only: `FEDERATED_INTEGRATION=1 pnpm --filter @mosaicstack/gateway test src/__tests__/integration/federation-m2.integration.test.ts`
### Design notes
- CaService is mocked via `useValue` in DB-only tests so Step-CA env vars are not required
- Two separate describe blocks with different gate conditions
- Each test creates isolated data with a unique `RUN_ID` UUID prefix
- afterAll cleans up in FK-safe order: tokens -> grants -> peers -> users
- Uses `createDb`/`DbHandle` from `@mosaicstack/db` (avoids direct drizzle-orm/postgres-js import)
Ensure BETTER_AUTH_SECRET is set before seal() is called in test #5, add
it to the DB-only run command in the header comment, and surface cleanup
errors to stderr instead of silently swallowing them.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Integration tests for the Mosaic federation M2 milestone (FED-M2-09).
Closes #461
Tests covered
createGrantwrites apendingrow to DB; scope and status verified (FEDERATED_INTEGRATION=1)clientKeyPemstored in DB is a sealed ciphertext, not a PEM (FEDERATED_INTEGRATION=1)createGrantrejects scope with unknown resource type withFederationScopeError(FEDERATED_INTEGRATION=1)listGrantsreturns accurate status for pending/revoked grants; peer list correct (FEDERATED_INTEGRATION=1)EnrollmentService.redeemreturns a valid PEM certificate via real Step-CA (STEP_CA_AVAILABLE=1)EnrollmentService.redeemwith the same token throwsGoneException(STEP_CA_AVAILABLE=1)Gate env vars
DB-only tests (#1, #5, #7, #8):
FEDERATED_INTEGRATION=1Step-CA tests (#2, #3) additional vars:
STEP_CA_AVAILABLE=1STEP_CA_URL=https://localhost:9000STEP_CA_PROVISIONER_KEY_JSON— fromdocker exec $(docker ps -qf name=step-ca) cat /home/step/secrets/mosaic-fed.jsonSTEP_CA_ROOT_CERT_PATH=/tmp/step-ca-root.crt— copy fromdocker cp $(docker ps -qf name=step-ca):/home/step/certs/root_ca.crt /tmp/step-ca-root.crtHow to run
Prerequisites:
docker compose -f docker-compose.federated.yml --profile federated up -dDB-only:
FEDERATED_INTEGRATION=1 pnpm --filter @mosaicstack/gateway test src/__tests__/integration/federation-m2.integration.test.tsDesign notes
useValuein DB-only tests so Step-CA env vars are not requiredRUN_IDUUID prefixcreateDb/DbHandlefrom@mosaicstack/db(avoids direct drizzle-orm/postgres-js import)