(t *testing.T)
| 34 | } |
| 35 | |
| 36 | func 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 | |
| 64 | func TestParseAllowListLimit(t *testing.T) { |
| 65 | t.Parallel() |
nothing calls this directly
no test coverage detected