Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/platform/security/tools_byrule_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/platform/security/tools_byrule_test.go |
| Original SHA-256 | 39dcf536b183be39f1b420cdc40997e09cb3297f8442a67a6d6293781f93432c |
| Git blob SHA | c2eca392fce1be11c0f51cd9e2b1d523ebaee2d0 |
| Reading-copy SHA-256 | 39dcf536b183be39f1b420cdc40997e09cb3297f8442a67a6d6293781f93432c |
Recovered source transcript
Download complete source text ↓81 lines · 3.6 KB
package security
import "testing"
// TestSuperuserHoldsEveryToolByRule is amendment 6 decision 12. The tenant top seat holds every product
// tool its tenant is entitled to BY RULE, not by grant, so the entitlement grid can never render the top
// seat as broken. This is the exact defect the design partner hit: a superuser with zero grants saw every
// control locked.
func TestSuperuserHoldsEveryToolByRule(t *testing.T) {
got := EffectiveTools(RoleSuperuser, nil)
if len(got) != len(AllTools) {
t.Fatalf("a tenant superuser must hold every tool by rule, got %v", got)
}
for _, want := range AllTools {
if !HasTool(got, want) {
t.Errorf("superuser is missing %s, which by rule it must hold", want)
}
}
}
// TestOperatorHoldsEveryToolEverywhere covers the platform plane: operator holds all tools in every tenant.
func TestOperatorHoldsEveryToolEverywhere(t *testing.T) {
got := EffectiveTools(RoleOperator, []string{})
for _, want := range AllTools {
if !HasTool(got, want) {
t.Errorf("operator is missing %s, which by rule it must hold everywhere", want)
}
}
}
// TestRolesBelowSuperuserKeepGrantedToolsOnly is the other half of decision 12: confer only what you hold
// stands unchanged for every role BELOW superuser, where it is load bearing. A grant driven role must NOT
// gain tools by rule, or the ceiling on spreading access disappears.
func TestRolesBelowSuperuserKeepGrantedToolsOnly(t *testing.T) {
for _, role := range []Role{RoleOwner, RoleAdmin, RoleManager, RoleRecruiter, RoleMember, RoleViewer} {
got := EffectiveTools(role, []string{string(ToolMissionMatch)})
if len(got) != 1 || !HasTool(got, ToolMissionMatch) {
t.Errorf("%s must hold exactly its granted tools, got %v", role, got)
}
if HasTool(got, ToolRecruitMatch) {
t.Errorf("%s gained an ungranted tool, the confer ceiling is broken", role)
}
}
}
// TestEffectiveToolsPreservesAGrantedSetForTheTopSeat proves the by rule set is a superset, never a
// replacement that could DROP a tool an account legitimately holds.
func TestEffectiveToolsPreservesAGrantedSetForTheTopSeat(t *testing.T) {
got := EffectiveTools(RoleSuperuser, []string{string(ToolMissionMatch)})
for _, want := range AllTools {
if !HasTool(got, want) {
t.Errorf("by rule resolution dropped %s", want)
}
}
}
// TestDisabledReasonIsNeverSilent is amendment 6 decision 13. A disabled entitlement control must state
// WHICH reason applies, and the two are distinct: the organization is not entitled, or the actor does not
// personally hold the tool. An empty reason is the bug that made the product look broken.
func TestDisabledReasonIsNeverSilent(t *testing.T) {
// The actor holds missionmatch; the org is entitled to missionmatch and recruitmatch.
orgEntitled := []string{string(ToolMissionMatch), string(ToolRecruitMatch)}
actorHolds := []string{string(ToolMissionMatch)}
if r := ToolDisabledReason(ToolMissionMatch, orgEntitled, actorHolds); r != "" {
t.Errorf("a tool the actor holds must not be disabled, got reason %q", r)
}
if r := ToolDisabledReason(ToolRecruitMatch, orgEntitled, actorHolds); r != ReasonActorLacksTool {
t.Errorf("expected the actor lacks tool reason, got %q", r)
}
if r := ToolDisabledReason(ToolSlateMatch, orgEntitled, actorHolds); r != ReasonOrgNotEntitled {
t.Errorf("expected the org not entitled reason, got %q", r)
}
// Neither reason may ever be the empty string, which is what silent grey looks like.
for _, reason := range []string{ReasonOrgNotEntitled, ReasonActorLacksTool} {
if reason == "" {
t.Error("a disabled reason is empty, which is the silent grey this decision forbids")
}
}
}