(t *testing.T)
| 160 | } |
| 161 | |
| 162 | func 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{ |
nothing calls this directly
no test coverage detected