~bigbes/sr-ht-spec

ref: 90eb06ec6f16e09cc7d1ab7558c9464c3764aca8 sr-ht-spec/authn/principal_test.go -rw-r--r-- 800 bytes
90eb06ec — Eugene Blikh feat(cmd): agent tokens and host-side proposals get admin commands 13 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)
			}
		})
	}
}