~bigbes/sr-ht-spec

ref: 61515a575dc7e931829c05eed0cd3c3a441df753 sr-ht-spec/authn/principal_test.go -rw-r--r-- 800 bytes
61515a57 — Eugene Blikh chore(beads): file spec-ejq.2, CI publish blocked on missing apk-ci-s3 secret 24 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)
			}
		})
	}
}