Files
archie/modules/events/sender_test.go
T
sam 30aa351eb6 feat(events,drafts): give sources an immutable id and a scope (#2127, #2027)
A source is keyed by a uuid, owned by the organisation or one person, and
labelled within that scope. The webhook path is a separate unique column, so
renaming either leaves stored events, event types, triggers, groups, mappings
and drafts alone. Delivery policies, sealed secrets and group keys use the id.
2026-11-24 02:43:51 +11:00

50 lines
1.6 KiB
Go

package events
import (
"context"
"log/slog"
"testing"
"github.com/google/uuid"
"github.com/samcharles93/archie-core/modules/events/internal/store"
"github.com/samcharles93/archie-core/modules/governance"
)
type connectorSource struct{ src store.Source }
func (o connectorSource) Source(context.Context, string, uuid.UUID) (store.Source, error) {
return o.src, nil
}
func (o connectorSource) SourceByPath(context.Context, string, string) (store.Source, error) {
return o.src, nil
}
// TestSenderMustBelongToTheSourcesConnector guards channel identities: the
// issuer of a linked credential comes from the source's connector, so a
// connector can't answer or link as an account of another connector.
func TestSenderMustBelongToTheSourcesConnector(t *testing.T) {
tests := []struct {
name string
by string
want governance.Subject
ok bool
}{
{name: "its own account", by: "telegram:1001", want: governance.Subject{Issuer: "telegram", Subject: "1001"}, ok: true},
{name: "an account with a colon in its id", by: "telegram:a:b", want: governance.Subject{Issuer: "telegram", Subject: "a:b"}, ok: true},
{name: "another connector's account", by: "slack:1001"},
{name: "no connector", by: "1001"},
{name: "no account", by: "telegram:"},
}
m := &Module{reader: connectorSource{store.Source{Connector: "telegram"}}, log: slog.New(slog.DiscardHandler)}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, got, ok := m.sender(t.Context(), store.Event{SourceID: uuid.NullUUID{UUID: hookID, Valid: true}}, tt.by)
if ok != tt.ok || got != tt.want {
t.Fatalf("sender = %v %v, want %v %v", got, ok, tt.want, tt.ok)
}
})
}
}