ignoreNames sets all names to "ignore" to ensure the values are identical.
(t *testing.T, value ast.Value)
| 172 | |
| 173 | // ignoreNames sets all names to "ignore" to ensure the values are identical. |
| 174 | func ignoreNames(t *testing.T, value ast.Value) { |
| 175 | t.Helper() |
| 176 | |
| 177 | // Override the names of the roles |
| 178 | ref := ast.Ref{ |
| 179 | ast.StringTerm("subject"), |
| 180 | ast.StringTerm("roles"), |
| 181 | } |
| 182 | roles, err := value.Find(ref) |
| 183 | require.NoError(t, err) |
| 184 | |
| 185 | rolesArray, ok := roles.(*ast.Array) |
| 186 | require.True(t, ok, "roles is expected to be an array") |
| 187 | |
| 188 | rolesArray.Foreach(func(term *ast.Term) { |
| 189 | obj, _ := term.Value.(ast.Object) |
| 190 | // Ignore all names |
| 191 | obj.Insert(ast.StringTerm("name"), ast.StringTerm("ignore")) |
| 192 | obj.Insert(ast.StringTerm("display_name"), ast.StringTerm("ignore")) |
| 193 | }) |
| 194 | |
| 195 | // Override the names of the scope role |
| 196 | ref = ast.Ref{ |
| 197 | ast.StringTerm("subject"), |
| 198 | ast.StringTerm("scope"), |
| 199 | } |
| 200 | scope, err := value.Find(ref) |
| 201 | require.NoError(t, err) |
| 202 | |
| 203 | scopeObj, ok := scope.(ast.Object) |
| 204 | require.True(t, ok, "scope is expected to be an object") |
| 205 | |
| 206 | scopeObj.Insert(ast.StringTerm("name"), ast.StringTerm("ignore")) |
| 207 | scopeObj.Insert(ast.StringTerm("display_name"), ast.StringTerm("ignore")) |
| 208 | } |
| 209 | |
| 210 | func TestRoleByName(t *testing.T) { |
| 211 | t.Parallel() |
no test coverage detected