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

Function TestParseAllowListNormalize

coderd/rbac/allowlist_test.go:36–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34}
35
36func TestParseAllowListNormalize(t *testing.T) {
37 t.Parallel()
38 id1 := uuid.New().String()
39 id2 := uuid.New().String()
40
41 // Global wildcard short-circuits
42 out, err := rbac.ParseAllowList([]string{"workspace:" + id1, "*:*", "template:" + id2}, 128)
43 require.NoError(t, err)
44 require.Equal(t, []rbac.AllowListElement{{Type: "*", ID: "*"}}, out)
45
46 // Typed wildcard collapses typed ids
47 out, err = rbac.ParseAllowList([]string{"workspace:*", "workspace:" + id1, "workspace:" + id2}, 128)
48 require.NoError(t, err)
49 require.Equal(t, []rbac.AllowListElement{{Type: "workspace", ID: "*"}}, out)
50
51 // Typed wildcard entries persist even without explicit IDs
52 out, err = rbac.ParseAllowList([]string{"template:*"}, 128)
53 require.NoError(t, err)
54 require.Equal(t, []rbac.AllowListElement{{Type: "template", ID: "*"}}, out)
55
56 // Dedup ids and sort deterministically
57 out, err = rbac.ParseAllowList([]string{"template:" + id2, "template:" + id2, "template:" + id1}, 128)
58 require.NoError(t, err)
59 require.Len(t, out, 2)
60 require.Equal(t, "template", out[0].Type)
61 require.Equal(t, "template", out[1].Type)
62}
63
64func TestParseAllowListLimit(t *testing.T) {
65 t.Parallel()

Callers

nothing calls this directly

Calls 5

ParseAllowListFunction · 0.92
NewMethod · 0.65
StringMethod · 0.45
EqualMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected