-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[entraid] ignore unsuported groups members and parse nested group mem…
…berships (#48182) This PR fixes a typo where the error was incorrectly ignored and caused failures when group membership included other groups and any unsupported kinds. This PR fixes that by properly returning `unsupportedGroupMember` while also supports parsing groups that are member of other groups. Signed-off-by: Tiago Silva <[email protected]>
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -412,3 +412,65 @@ func TestRetry(t *testing.T) { | |
require.Error(t, err) | ||
}) | ||
} | ||
|
||
const listGroupsMembersPayload = `[ | ||
{ | ||
"@odata.type": "#microsoft.graph.user", | ||
"id": "9f615773-8219-4a5e-9eb1-8e701324c683", | ||
"mail": "[email protected]" | ||
}, | ||
{ | ||
"@odata.type": "#microsoft.graph.device", | ||
"id": "1566d9a7-c652-44e7-a75e-665b77431435", | ||
"mail": "[email protected]" | ||
}, | ||
{ | ||
"@odata.type": "#microsoft.graph.group", | ||
"id": "7db727c5-924a-4f6d-b1f0-d44e6cafa87c", | ||
"displayName": "Test Group 1" | ||
} | ||
]` | ||
|
||
func TestIterateGroupMembers(t *testing.T) { | ||
t.Parallel() | ||
|
||
var membersJSON []json.RawMessage | ||
require.NoError(t, json.Unmarshal([]byte(listGroupsMembersPayload), &membersJSON)) | ||
mux := http.NewServeMux() | ||
groupID := "fd5be192-6e51-4f54-bbdf-30407435ceb7" | ||
mux.Handle("GET /groups/"+groupID+"/members", paginatedHandler(t, membersJSON)) | ||
|
||
srv := httptest.NewServer(mux) | ||
t.Cleanup(func() { srv.Close() }) | ||
|
||
uri, err := url.Parse(srv.URL) | ||
require.NoError(t, err) | ||
client := &Client{ | ||
httpClient: &http.Client{}, | ||
tokenProvider: &fakeTokenProvider{}, | ||
retryConfig: retryConfig, | ||
baseURL: uri, | ||
pageSize: 2, // smaller page size so we actually fetch multiple pages with our small test payload | ||
} | ||
|
||
var members []GroupMember | ||
err = client.IterateGroupMembers(context.Background(), groupID, func(u GroupMember) bool { | ||
members = append(members, u) | ||
return true | ||
}) | ||
|
||
require.NoError(t, err) | ||
require.Len(t, members, 2) | ||
{ | ||
require.IsType(t, &User{}, members[0]) | ||
user := members[0].(*User) | ||
require.Equal(t, "9f615773-8219-4a5e-9eb1-8e701324c683", *user.ID) | ||
require.Equal(t, "[email protected]", *user.Mail) | ||
} | ||
{ | ||
require.IsType(t, &Group{}, members[1]) | ||
group := members[1].(*Group) | ||
require.Equal(t, "7db727c5-924a-4f6d-b1f0-d44e6cafa87c", *group.ID) | ||
require.Equal(t, "Test Group 1", *group.DisplayName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters