~bigbes/sr-ht-spec

ref: 6e59bf0ffc7d16f509dad40063d35bf8f6fb98a7 sr-ht-spec/authn/principal_test.go -rw-r--r-- 800 bytes
6e59bf0f — Eugene Blikh api: advertise an empty scope list, not null 8 days ago
                                                                                
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
package authn

import "testing"

// TestCanRead pins the read-plane ACL every surface shares: the owner and its
// agents may read, and every other principal — including an unrecognised or
// zero Kind — is denied rather than accidentally admitted.
func TestCanRead(t *testing.T) {
	cases := []struct {
		name string
		p    Principal
		want bool
	}{
		{"owner may read", Principal{Kind: KindOwner}, true},
		{"agent may read", Principal{Kind: KindAgent}, true},
		{"anonymous may not", Anonymous(), false},
		{"zero value may not", Principal{}, false},
		{"unknown kind may not", Principal{Kind: "wat"}, false},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			if got := tc.p.CanRead(); got != tc.want {
				t.Errorf("CanRead() = %v, want %v", got, tc.want)
			}
		})
	}
}