package events import ( "context" "log/slog" "testing" "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, 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{Source: "chat"}, tt.by) if ok != tt.ok || got != tt.want { t.Fatalf("sender = %v %v, want %v %v", got, ok, tt.want, tt.ok) } }) } }