MCPcopy Index your code
hub / github.com/coder/coder / TestAPIKeyScopesExpand

Function TestAPIKeyScopesExpand

coderd/database/modelmethods_internal_test.go:13–144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestAPIKeyScopesExpand(t *testing.T) {
14 t.Parallel()
15 t.Run("builtins", func(t *testing.T) {
16 t.Parallel()
17 cases := []struct {
18 name string
19 scopes APIKeyScopes
20 want func(t *testing.T, s rbac.Scope)
21 }{
22 {
23 name: "all",
24 scopes: APIKeyScopes{ApiKeyScopeCoderAll},
25 want: func(t *testing.T, s rbac.Scope) {
26 requirePermission(t, s, rbac.ResourceWildcard.Type, policy.Action(policy.WildcardSymbol))
27 requireAllowAll(t, s)
28 },
29 },
30 {
31 name: "application_connect",
32 scopes: APIKeyScopes{ApiKeyScopeCoderApplicationConnect},
33 want: func(t *testing.T, s rbac.Scope) {
34 requirePermission(t, s, rbac.ResourceWorkspace.Type, policy.ActionApplicationConnect)
35 requireAllowAll(t, s)
36 },
37 },
38 }
39 for _, tc := range cases {
40 t.Run(tc.name, func(t *testing.T) {
41 t.Parallel()
42 s, err := tc.scopes.expandRBACScope()
43 require.NoError(t, err)
44 tc.want(t, s)
45 })
46 }
47 })
48
49 t.Run("low_level_pairs", func(t *testing.T) {
50 t.Parallel()
51 cases := []struct {
52 name string
53 scopes APIKeyScopes
54 res string
55 act policy.Action
56 }{
57 {name: "workspace:read", scopes: APIKeyScopes{ApiKeyScopeWorkspaceRead}, res: rbac.ResourceWorkspace.Type, act: policy.ActionRead},
58 {name: "template:use", scopes: APIKeyScopes{ApiKeyScopeTemplateUse}, res: rbac.ResourceTemplate.Type, act: policy.ActionUse},
59 }
60 for _, tc := range cases {
61 t.Run(tc.name, func(t *testing.T) {
62 t.Parallel()
63 s, err := tc.scopes.expandRBACScope()
64 require.NoError(t, err)
65 requirePermission(t, s, tc.res, tc.act)
66 requireAllowAll(t, s)
67 })
68 }
69 })
70

Callers

nothing calls this directly

Calls 15

expandRBACScopeMethod · 0.95
ExpandMethod · 0.95
ScopeSetMethod · 0.95
ActionTypeAlias · 0.92
requirePermissionFunction · 0.85
requireAllowAllFunction · 0.85
wantMethod · 0.80
WithAllowListMethod · 0.80
RunMethod · 0.65
NewMethod · 0.65
ExpandMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected