Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion pkg/azuread/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"net/url"
"regexp"
Expand Down Expand Up @@ -238,6 +239,24 @@ func (d *Datasource) GetPage(ctx context.Context, request *Request) (*Response,
}

if res.StatusCode != http.StatusOK {
// TEMP: Log the response body for debugging purposes.
body, readErr := io.ReadAll(res.Body)
if readErr != nil {
Comment thread
dhanya-sgnl marked this conversation as resolved.
slog.Error(
"Failed to read error response body",
slog.String("endpoint", endpoint),
"error", readErr,
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logging call is inconsistent with structured logging patterns. Use slog.Any("error", readErr) instead of the bare string and value pair to maintain consistency with other slog attributes.

Suggested change
"error", readErr,
slog.Any("error", readErr),

Copilot uses AI. Check for mistakes.
)
} else {
slog.Error(
"Azure AD API error",
slog.Int("status", res.StatusCode),
slog.String("endpoint", endpoint),
slog.String("response", string(body)),
Comment thread
dhanya-sgnl marked this conversation as resolved.
)
}
// END TEMP.

return response, nil
Comment thread
dhanya-sgnl marked this conversation as resolved.
}

Expand Down Expand Up @@ -385,7 +404,8 @@ func IsAdvancedQuery(request *Request, endpoint string) bool {
}

// Check for 'ne' and 'not' operators using word boundary regex on decoded endpoint.
if neOperatorRegex.MatchString(decodedEndpoint) || notOperatorRegex.MatchString(decodedEndpoint) {
decodedEndpointLower := strings.ToLower(decodedEndpoint)
if neOperatorRegex.MatchString(decodedEndpointLower) || notOperatorRegex.MatchString(decodedEndpointLower) {
return true
}
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/azuread/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,11 @@ func TestIsAdvancedQuery(t *testing.T) {
endpoint: "https://graph.microsoft.com/v1.0/users?$filter=displayName eq 'cannot'&$select=id",
want: false,
},
"filter_odata_not": {
request: &azuread.Request{},
endpoint: "https://graph.microsoft.com/v1.0/groups?$select=id&$top=1&$filter=NOT+groupTypes%2Fany%28c%3Ac+eq+%27DynamicMembership%27%29",
want: true,
},

// Note: Advanced queries don't currently support $expand.
// This test documents that $expand alone does NOT trigger advanced query requirements.
Expand Down
Loading