Files
archie/internal/domain/binding/binding_test.go
T
sam 963f967c56 feat(eda): sources own signing, with UUIDv7 paths and approved unsigned option
A source is the capture endpoint: a UUIDv7 path by default or a unique
URL-safe custom path, signed by default with an Archie-generated secret
(encrypted via the bindings cipher), or unsigned after an approval.
Intake verifies X-Hub-Signature-256/X-Signature-256 against the source
secret before redaction; an unauthenticated event on a signed source is
captured but never dispatched, an event on an approved unsigned source
dispatches and is marked unsigned. The binding secret is retired; migration
0006 derives sources from existing binding and capture source strings,
moving each binding's secret onto its source. SourceStore crosses the
State Store gRPC contract. The dashboard gains a sources panel and flags
unsigned in the capture inspector, binding list and task timeline.
2026-09-24 14:26:21 +10:00

71 lines
1.8 KiB
Go

package binding
import "testing"
func validBinding() Binding {
return Binding{
Name: "sentry alerts",
Matcher: Matcher{Source: "sentry"},
MappingID: "m1",
Workflow: "implement",
}
}
// TestValidateAcceptsNoRepoPin pins backward compatibility: a binding
// with neither Owner nor Repo set (today's only shape) must remain
// valid -- resolveBindingRepo's single-configured-repo fallback still
// applies to it.
func TestValidateAcceptsNoRepoPin(t *testing.T) {
b := validBinding()
if err := b.Validate(); err != nil {
t.Fatalf("Validate() = %v, want nil", err)
}
}
// TestValidateAcceptsBothOwnerAndRepo is the multi-repo fix: a binding
// naming a specific owner/repo must be accepted.
func TestValidateAcceptsBothOwnerAndRepo(t *testing.T) {
b := validBinding()
b.Owner, b.Repo = "acme", "widget"
if err := b.Validate(); err != nil {
t.Fatalf("Validate() = %v, want nil", err)
}
}
func TestValidateRejectsPartialRepoPin(t *testing.T) {
tests := []struct {
name string
owner, repo string
}{
{"owner only", "acme", ""},
{"repo only", "", "widget"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b := validBinding()
b.Owner, b.Repo = tt.owner, tt.repo
if err := b.Validate(); err == nil {
t.Fatalf("Validate() = nil, want error for partial owner/repo pin (owner=%q repo=%q)", tt.owner, tt.repo)
}
})
}
}
func TestMatcherMatchesOnlyDispatchableEventsFromItsSource(t *testing.T) {
m := Matcher{Source: "sentry"}
tests := []struct {
source string
dispatchable bool
want bool
}{
{"sentry", true, true},
{"sentry", false, false},
{"other", true, false},
}
for _, tt := range tests {
if got := m.Matches(tt.source, tt.dispatchable); got != tt.want {
t.Errorf("Matches(%q, %v) = %v, want %v", tt.source, tt.dispatchable, got, tt.want)
}
}
}