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

Function TestUnionAllowLists

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

Source from the content-addressed store, hash-verified

160}
161
162func TestUnionAllowLists(t *testing.T) {
163 t.Parallel()
164
165 id1 := uuid.NewString()
166 id2 := uuid.NewString()
167
168 t.Run("wildcard_short_circuit", func(t *testing.T) {
169 t.Parallel()
170 out, err := rbac.UnionAllowLists(
171 []rbac.AllowListElement{{Type: policy.WildcardSymbol, ID: policy.WildcardSymbol}},
172 []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: id1}},
173 )
174 require.NoError(t, err)
175 require.Equal(t, []rbac.AllowListElement{rbac.AllowListAll()}, out)
176 })
177
178 t.Run("merge_unique_entries", func(t *testing.T) {
179 t.Parallel()
180 out, err := rbac.UnionAllowLists(
181 []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: id1}},
182 []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: id2}},
183 )
184 require.NoError(t, err)
185 require.Len(t, out, 2)
186 require.ElementsMatch(t, []rbac.AllowListElement{
187 {Type: rbac.ResourceWorkspace.Type, ID: id1},
188 {Type: rbac.ResourceWorkspace.Type, ID: id2},
189 }, out)
190 })
191
192 t.Run("typed_wildcard_collapse", func(t *testing.T) {
193 t.Parallel()
194 out, err := rbac.UnionAllowLists(
195 []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: policy.WildcardSymbol}},
196 []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: id1}},
197 )
198 require.NoError(t, err)
199 require.Equal(t, []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: policy.WildcardSymbol}}, out)
200 })
201
202 t.Run("deduplicate_across_inputs", func(t *testing.T) {
203 t.Parallel()
204 out, err := rbac.UnionAllowLists(
205 []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: id1}},
206 []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: id1}},
207 )
208 require.NoError(t, err)
209 require.Equal(t, []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: id1}}, out)
210 })
211
212 t.Run("combine_multiple_types", func(t *testing.T) {
213 t.Parallel()
214 out, err := rbac.UnionAllowLists(
215 []rbac.AllowListElement{{Type: rbac.ResourceWorkspace.Type, ID: id1}},
216 []rbac.AllowListElement{{Type: rbac.ResourceTemplate.Type, ID: id2}},
217 )
218 require.NoError(t, err)
219 require.ElementsMatch(t, []rbac.AllowListElement{

Callers

nothing calls this directly

Calls 6

UnionAllowListsFunction · 0.92
AllowListAllFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45
LenMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected