-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthorized_test.go
51 lines (48 loc) · 1.14 KB
/
authorized_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package filters
import (
"testing"
vocab "github.com/go-ap/activitypub"
)
func Test_Authorized_Match(t *testing.T) {
tests := []struct {
name string
a vocab.IRI
it vocab.Item
want bool
}{
{
name: "empty is not authorized",
},
{
name: "example.com is not allowed",
a: "https://example.com",
it: &vocab.Object{To: vocab.ItemCollection{vocab.IRI("https://example.com/jdoe")}},
want: false,
},
{
name: "example.com is allowed if object has public audience",
a: "https://example.com",
it: &vocab.Object{To: vocab.ItemCollection{vocab.PublicNS}},
want: true,
},
{
name: "example.com is allowed if ",
a: "https://example.com",
it: &vocab.Object{To: vocab.ItemCollection{vocab.PublicNS}},
want: true,
},
{
name: "PublicNS should *NOT* be authorized for object with empty recipients list",
a: vocab.PublicNS,
it: &vocab.Object{Type: vocab.TombstoneType},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Authorized(tt.a).Match(tt.it); got != tt.want {
t.Errorf("Match() = %v, want %v", got, tt.want)
}
})
}
}