Files
member-console/internal/domains/external_gate_test.go
T
cgalo5758 88db730fcc Add dual licensing and SPDX headers
Introduce a commercial license option alongside AGPL-3.0-only, require a
CLA for contributors, and document the terms in COMMERCIAL.md and
NOTICE. Add a script to stamp SPDX headers on Go files and apply it
across the tree.
2026-09-06 02:29:42 -05:00

42 lines
1.6 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
package domains
import (
"context"
"errors"
"testing"
)
// TestClaimExternalGateRefusesBeforeAllocating pins the enforcement point
// (centralize-external-claim-gate): a refusing gate stops ClaimExternal
// before ANY registry work. The registry here has a nil database — reaching
// the lock or the queries would panic — so the clean typed refusal is proof
// nothing was allocated, no token minted, no lock taken.
func TestClaimExternalGateRefusesBeforeAllocating(t *testing.T) {
for _, refusal := range []error{ErrExternalClaimsNotEntitled, ErrNoConnectTarget} {
r := NewRegistry(nil, WithExternalClaimGate(func(ctx context.Context, workspaceID string) error {
return refusal
}))
_, err := r.ClaimExternal(context.Background(), "ws-1", "example.org")
if !errors.Is(err, refusal) {
t.Errorf("ClaimExternal with refusing gate: got %v, want %v", err, refusal)
}
}
}
// TestClaimExternalGateReceivesWorkspace pins that the gate is consulted
// with the requesting workspace — the input the entitlement lookup keys on.
func TestClaimExternalGateReceivesWorkspace(t *testing.T) {
var saw string
r := NewRegistry(nil, WithExternalClaimGate(func(ctx context.Context, workspaceID string) error {
saw = workspaceID
return ErrExternalClaimsNotEntitled // refuse so the nil DB is never touched
}))
_, _ = r.ClaimExternal(context.Background(), "ws-42", "example.org")
if saw != "ws-42" {
t.Errorf("gate saw workspace %q, want ws-42", saw)
}
}