A workspace administrator creates a code (160 random bits, 14 days,
single use, stored as SHA-256 only); another workspace's administrator
enters it and the two are connected at once. Each side sees only the
other's display name. Every code that does not work gets the same 404,
and entering codes is limited to 20 per hour per workspace and person.
Either side can end a connection; archiving a workspace ends all of its
connections, and a purged side leaves the other an ended connection
with the name it knew. Both audit logs record each step; the other
side's entry names neither the person nor the address.
Products read the active connections and check one before each
delivery under the new route group connections.read
(GET /v1/internal/tenants/{id}/connections, GET
/v1/internal/connections/{connection}).
The Postgres GetTenant now answers a non-UUID id as not found (404),
as the memory store does, instead of a 500.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
138 lines
7.7 KiB
Go
138 lines
7.7 KiB
Go
package server_test
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/getkin/kin-openapi/openapi3"
|
|
"github.com/getkin/kin-openapi/openapi3filter"
|
|
"github.com/getkin/kin-openapi/routers/gorillamux"
|
|
)
|
|
|
|
// TestOpenAPISpec_loads_and_validates is the contract gate: the committed
|
|
// openapi.yaml must parse, every $ref must resolve, and every documented
|
|
// operation must be reachable from the router. If a handler is missing
|
|
// from the spec or vice-versa, this fails.
|
|
func TestOpenAPISpec_loadsAndIsConsistent(t *testing.T) {
|
|
loader := &openapi3.Loader{Context: context.Background(), IsExternalRefsAllowed: false}
|
|
specPath, _ := filepath.Abs("../../openapi.yaml")
|
|
doc, err := loader.LoadFromFile(specPath)
|
|
if err != nil {
|
|
t.Fatalf("load spec: %v", err)
|
|
}
|
|
if err := doc.Validate(loader.Context); err != nil {
|
|
t.Fatalf("validate spec: %v", err)
|
|
}
|
|
// Replace the servers block so the validator matches any host.
|
|
doc.Servers = openapi3.Servers{{URL: "/"}}
|
|
|
|
router, err := gorillamux.NewRouter(doc)
|
|
if err != nil {
|
|
t.Fatalf("build router: %v", err)
|
|
}
|
|
|
|
// Run a few sample requests through the validator. Each one must be
|
|
// matched to an operation in the spec.
|
|
cases := []struct {
|
|
method, path string
|
|
}{
|
|
{"GET", "/healthz"},
|
|
{"GET", "/readyz"},
|
|
{"GET", "/version"},
|
|
{"GET", "/v1/tenants/by-slug/acme"},
|
|
{"GET", "/v1/entitlements?tenant_id=00000000-0000-0000-0000-000000000001"},
|
|
{"GET", "/v1/api-keys?tenant_id=00000000-0000-0000-0000-000000000001"},
|
|
{"GET", "/v1/api-keys/scopes"},
|
|
{"GET", "/v1/catalog"},
|
|
{"GET", "/v1/audit?limit=10"},
|
|
{"POST", "/v1/internal/keycloak/claims"},
|
|
{"GET", "/v1/tenants?limit=10"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/members"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/role-dataset"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/members/u-1/capabilities"},
|
|
{"DELETE", "/v1/tenants/00000000-0000-0000-0000-000000000001/members/u-1/capabilities/portal:billing.view"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/capability-requests"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/connection-invites"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/connection-invites"},
|
|
{"DELETE", "/v1/tenants/00000000-0000-0000-0000-000000000001/connection-invites/00000000-0000-0000-0000-000000000002"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/connections"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/connections"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/connections/00000000-0000-0000-0000-000000000002/end"},
|
|
{"GET", "/v1/internal/tenants/00000000-0000-0000-0000-000000000001/connections?state=active"},
|
|
{"GET", "/v1/internal/connections/00000000-0000-0000-0000-000000000002"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/capability-requests/00000000-0000-0000-0000-000000000002/approve"},
|
|
{"DELETE", "/v1/tenants/00000000-0000-0000-0000-000000000001/capability-requests/00000000-0000-0000-0000-000000000002"},
|
|
{"PUT", "/v1/tenants/00000000-0000-0000-0000-000000000001/role-dataset"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/role-dataset/revisions/2"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/intake/reports"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/intake/reports"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/intake/reports/SH-2026-00001"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/intake/reports/SH-2026-00001/supplements"},
|
|
{"GET", "/v1/internal/intake/pending?after=3&limit=10"},
|
|
{"POST", "/v1/internal/intake/entries/1/receipts"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/role-dataset/resolve?decision_type=r1.release_d01"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/products/pruefwerk/settings"},
|
|
{"PUT", "/v1/tenants/00000000-0000-0000-0000-000000000001/products/pruefwerk/settings"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/invites"},
|
|
{"PATCH", "/v1/tenants/00000000-0000-0000-0000-000000000001/members/u-1"},
|
|
{"DELETE", "/v1/tenants/00000000-0000-0000-0000-000000000001/members/u-1"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/members/u-1/resend"},
|
|
{"PATCH", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/members/u-1"},
|
|
{"POST", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/preview-grants"},
|
|
{"DELETE", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/preview-grants/werkmeister"},
|
|
{"DELETE", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/members/u-1"},
|
|
{"POST", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/members/u-1/resend"},
|
|
{"GET", "/v1/admin/tenants?q=acme"},
|
|
{"GET", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001"},
|
|
{"POST", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/trial"},
|
|
{"POST", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/invites/resend"},
|
|
{"POST", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/reprovision"},
|
|
{"DELETE", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001"},
|
|
{"GET", "/v1/admin/audit?limit=10"},
|
|
{"POST", "/v1/notifications"},
|
|
{"GET", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/documents"},
|
|
{"POST", "/v1/admin/documents/00000000-0000-0000-0000-000000000002/publish"},
|
|
{"DELETE", "/v1/admin/documents/00000000-0000-0000-0000-000000000002"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/documents/00000000-0000-0000-0000-000000000002/download"},
|
|
{"POST", "/v1/tenants/00000000-0000-0000-0000-000000000001/status"},
|
|
{"POST", "/v1/internal/entitlements/check"},
|
|
{"POST", "/v1/internal/erp/webhook"},
|
|
{"POST", "/v1/internal/erp/reconcile"},
|
|
{"GET", "/v1/internal/erp/status"},
|
|
{"GET", "/v1/subscriptions?tenant_id=00000000-0000-0000-0000-000000000001"},
|
|
{"POST", "/v1/usage/events"},
|
|
{"GET", "/v1/usage/events?tenant_id=00000000-0000-0000-0000-000000000001"},
|
|
{"GET", "/v1/usage/summary?tenant_id=00000000-0000-0000-0000-000000000001&since=2026-11-01T00:00:00Z"},
|
|
{"POST", "/v1/licences"},
|
|
{"POST", "/v1/licences/heartbeat"},
|
|
{"POST", "/v1/licences/ci"},
|
|
{"POST", "/v1/licences/00000000-0000-0000-0000-000000000001/revoke"},
|
|
{"GET", "/.well-known/licence-keys.json"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/managed-services"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/contracts"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/contracts/documents/lb-pruefwerk.pdf"},
|
|
{"GET", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/avv-values"},
|
|
{"PUT", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/contract-documents/avv"},
|
|
{"GET", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/managed-services"},
|
|
{"POST", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/managed-services"},
|
|
{"PATCH", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/managed-services/00000000-0000-0000-0000-000000000002"},
|
|
{"DELETE", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/managed-services/00000000-0000-0000-0000-000000000002"},
|
|
{"PUT", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/managed-services/00000000-0000-0000-0000-000000000002/admin-token"},
|
|
{"GET", "/v1/admin/tenants/00000000-0000-0000-0000-000000000001/module-users?month=2026-11"},
|
|
{"GET", "/v1/tenants/00000000-0000-0000-0000-000000000001/module-users?month=2026-11"},
|
|
{"POST", "/v1/internal/module-users/count"},
|
|
}
|
|
for _, c := range cases {
|
|
req := newRequest(t, c.method, c.path)
|
|
_, _, err := router.FindRoute(req)
|
|
if err != nil {
|
|
t.Errorf("%s %s: not in spec — %v", c.method, c.path, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Reference the openapi3filter package so its symbol survives if the
|
|
// per-request validation block grows back later.
|
|
var _ = openapi3filter.ValidateRequest
|