diff options
| author | Chia <Chia@93.nz> | 2026-08-05 00:26:25 +1200 |
|---|---|---|
| committer | Chia <Chia@93.nz> | 2026-08-05 00:33:31 +1200 |
| commit | 1a3d7f9a8a181df48f0e911cbe17a3fad3ab9ac9 (patch) | |
| tree | 8c92e1e7326fc67ed077a0a878697f1be14b43da /internal/controlplane/access_test.go | |
| parent | 5b651488b081b65fda8a323f228e139adb79a35d (diff) | |
add some scriptsmain
Diffstat (limited to '')
| -rw-r--r-- | internal/controlplane/access_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/controlplane/access_test.go b/internal/controlplane/access_test.go new file mode 100644 index 0000000..96e3869 --- /dev/null +++ b/internal/controlplane/access_test.go @@ -0,0 +1,39 @@ +package controlplane + +import "testing" + +func TestConsoleRolePermissions(t *testing.T) { + tests := []struct { + role, permission string + want bool + }{ + {RolePlatformAdmin, "platform.write", true}, + {RolePlatformViewer, "platform.read", true}, + {RolePlatformViewer, "platform.write", false}, + {RoleTenantAdmin, "keys.write", true}, + {RoleTenantAdmin, "limits.write", false}, + {RoleTenantBilling, "billing.topup", true}, + {RoleTenantBilling, "keys.read", false}, + {RoleTenantDeveloper, "keys.write", true}, + {RoleTenantDeveloper, "billing.read", false}, + {RoleTenantViewer, "usage.read", true}, + {RoleTenantViewer, "users.read", false}, + } + for _, test := range tests { + t.Run(test.role+"/"+test.permission, func(t *testing.T) { + if got := (ConsoleActor{Role: test.role}).Can(test.permission); got != test.want { + t.Fatalf("Can(%q) = %v, want %v", test.permission, got, test.want) + } + }) + } +} + +func TestTenantRoleNeverGetsPlatformPermissions(t *testing.T) { + roles := []string{RoleTenantAdmin, RoleTenantBilling, RoleTenantDeveloper, RoleTenantViewer} + for _, role := range roles { + actor := ConsoleActor{Role: role} + if actor.Can("platform.read") || actor.Can("platform.write") { + t.Fatalf("role %s received platform access", role) + } + } +} |
