Files
aura-crm/production/backend/internal/authz/authz_test.go
T

34 lines
1.1 KiB
Go

package authz
import "testing"
func TestCanAccessAssigned(t *testing.T) {
unassigned := (*string)(nil)
self := "staff-a"
other := "staff-b"
cases := []struct {
name string
permissions []string
masters *string
staffID string
want bool
}{
{"unscoped sees unassigned", []string{"unscoped"}, unassigned, self, true},
{"unscoped sees another master's record", []string{"unscoped"}, &other, self, true},
{"unscoped among other perms sees another master's record", []string{"cash", "unscoped"}, &other, self, true},
{"scoped sees unassigned", nil, unassigned, self, true},
{"scoped sees own record", nil, &self, self, true},
{"scoped blocked from another master's record", nil, &other, self, false},
{"scoped with unrelated perms still blocked", []string{"cash", "analytics"}, &other, self, false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := CanAccessAssigned(tc.permissions, tc.masters, tc.staffID)
if got != tc.want {
t.Errorf("CanAccessAssigned(%v, %v, %q) = %v, want %v", tc.permissions, tc.masters, tc.staffID, got, tc.want)
}
})
}
}