Skip to content

Commit d98e88d

Browse files
committed
reconstruct the graph url and update tests
1 parent 15bd08c commit d98e88d

2 files changed

Lines changed: 5 additions & 39 deletions

File tree

provider_azure.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const (
2828
microsoftGraphUSHost = "graph.microsoft.us"
2929
microsoftGraphAPIVersion = "/v1.0"
3030

31+
// Microsoft Graph API paths for group membership information
32+
getMemberObjectsPath = "/me/getMemberObjects"
33+
3134
// Distributed claim fields
3235
claimNamesField = "_claim_names"
3336
claimSourcesField = "_claim_sources"
@@ -70,10 +73,11 @@ func (a *AzureProvider) FetchGroups(_ context.Context, b *jwtAuthBackend, allCla
7073
if err != nil {
7174
return nil, fmt.Errorf("unable to create CA Context: %s", err)
7275
}
73-
groups, err := a.getAzureGroups(a.buildGraphEndpoint("me/getMemberObjects"), tokenSource)
76+
groups, err := a.getAzureGroups(fmt.Sprintf("https://%s%s%s", microsoftGraphHost, microsoftGraphAPIVersion, getMemberObjectsPath), tokenSource)
7477
if err != nil {
7578
return nil, fmt.Errorf("unable to fetch groups from Microsoft Graph API: %s", err)
7679
}
80+
b.Logger().Debug(fmt.Sprintf("groups from Microsoft Graph API: %v", groups))
7781
return groups, nil
7882
}
7983

@@ -158,11 +162,6 @@ func (a *AzureProvider) getClaimSource(logger log.Logger, allClaims map[string]i
158162
return urlParsed.String(), nil
159163
}
160164

161-
// buildGraphEndpoint constructs a Microsoft Graph API endpoint URL
162-
func (a *AzureProvider) buildGraphEndpoint(path string) string {
163-
return fmt.Sprintf("https://%s%s/%s", microsoftGraphHost, microsoftGraphAPIVersion, path)
164-
}
165-
166165
// Fetch user groups from the Microsoft Graph API
167166
func (a *AzureProvider) getAzureGroups(groupsURL string, tokenSource oauth2.TokenSource) (interface{}, error) {
168167
urlParsed, err := url.Parse(groupsURL)

provider_azure_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -441,39 +441,6 @@ func TestAzureProvider_Initialize(t *testing.T) {
441441
})
442442
}
443443

444-
func TestAzureProvider_BuildGraphEndpoint(t *testing.T) {
445-
a := &AzureProvider{}
446-
447-
tests := []struct {
448-
name string
449-
path string
450-
expected string
451-
}{
452-
{
453-
name: "getMemberObjects endpoint",
454-
path: "me/getMemberObjects",
455-
expected: "https://graph.microsoft.com/v1.0/me/getMemberObjects",
456-
},
457-
{
458-
name: "memberOf endpoint",
459-
path: "me/memberOf",
460-
expected: "https://graph.microsoft.com/v1.0/me/memberOf",
461-
},
462-
{
463-
name: "transitiveMemberOf endpoint",
464-
path: "me/transitiveMemberOf",
465-
expected: "https://graph.microsoft.com/v1.0/me/transitiveMemberOf",
466-
},
467-
}
468-
469-
for _, tt := range tests {
470-
t.Run(tt.name, func(t *testing.T) {
471-
result := a.buildGraphEndpoint(tt.path)
472-
assert.Equal(t, tt.expected, result)
473-
})
474-
}
475-
}
476-
477444
func Test_getClaimSources(t *testing.T) {
478445
t.Run("normal case", func(t *testing.T) {
479446
a := &AzureProvider{}

0 commit comments

Comments
 (0)