Skip to content

Commit 9bfbc00

Browse files
authored
Fix SCIM query params (#2680)
Fixes: #2679.
1 parent 8e34527 commit 9bfbc00

File tree

3 files changed

+59
-16
lines changed

3 files changed

+59
-16
lines changed

github/github_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,33 @@ func testJSONMarshal(t *testing.T, v interface{}, want string) {
169169
}
170170
}
171171

172+
// Test whether the v fields have the url tag and the parsing of v
173+
// produces query parameters that corresponds to the want string.
174+
func testAddURLOptions(t *testing.T, url string, v interface{}, want string) {
175+
t.Helper()
176+
177+
vt := reflect.Indirect(reflect.ValueOf(v)).Type()
178+
for i := 0; i < vt.NumField(); i++ {
179+
field := vt.Field(i)
180+
if alias, ok := field.Tag.Lookup("url"); ok {
181+
if alias == "" {
182+
t.Errorf("The field %+v has a blank url tag", field)
183+
}
184+
} else {
185+
t.Errorf("The field %+v has no url tag specified", field)
186+
}
187+
}
188+
189+
got, err := addOptions(url, v)
190+
if err != nil {
191+
t.Errorf("Unable to add %#v as query parameters", v)
192+
}
193+
194+
if got != want {
195+
t.Errorf("addOptions(%q, %#v) returned %v, want %v", url, v, got, want)
196+
}
197+
}
198+
172199
// Test how bad options are handled. Method f under test should
173200
// return an error.
174201
func testBadOptions(t *testing.T, methodName string, f func() error) {

github/scim.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ type SCIMProvisionedIdentities struct {
6969
//
7070
// Github API docs: https://docs.github.com/en/rest/scim#list-scim-provisioned-identities--parameters
7171
type ListSCIMProvisionedIdentitiesOptions struct {
72-
StartIndex *int `json:"startIndex,omitempty"` // Used for pagination: the index of the first result to return. (Optional.)
73-
Count *int `json:"count,omitempty"` // Used for pagination: the number of results to return. (Optional.)
72+
StartIndex *int `url:"startIndex,omitempty"` // Used for pagination: the index of the first result to return. (Optional.)
73+
Count *int `url:"count,omitempty"` // Used for pagination: the number of results to return. (Optional.)
7474
// Filter results using the equals query parameter operator (eq).
7575
// You can filter results that are equal to id, userName, emails, and external_id.
7676
// For example, to search for an identity with the userName Octocat, you would use this query: ?filter=userName%20eq%20\"Octocat\".
7777
// To filter results for the identity with the email [email protected], you would use this query: ?filter=emails%20eq%20\"[email protected]\".
7878
// (Optional.)
79-
Filter *string `json:"filter,omitempty"`
79+
Filter *string `url:"filter,omitempty"`
8080
}
8181

8282
// ListSCIMProvisionedIdentities lists SCIM provisioned identities.

github/scim_test.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package github
77

88
import (
99
"context"
10+
"fmt"
1011
"net/http"
1112
"testing"
1213
"time"
@@ -428,22 +429,37 @@ func TestUpdateAttributeForSCIMUserOptions_Marshal(t *testing.T) {
428429
testJSONMarshal(t, u, want)
429430
}
430431

431-
func TestListSCIMProvisionedIdentitiesOptions_Marshal(t *testing.T) {
432-
testJSONMarshal(t, &ListSCIMProvisionedIdentitiesOptions{}, `{}`)
432+
func TestListSCIMProvisionedIdentitiesOptions_addOptions(t *testing.T) {
433+
testJSONMarshal(t, &ListSCIMProvisionedIdentitiesOptions{}, `{
434+
"StartIndex": null,
435+
"Count": null,
436+
"Filter": null
437+
}`)
433438

434-
u := &ListSCIMProvisionedIdentitiesOptions{
435-
StartIndex: Int(1),
436-
Count: Int(10),
437-
Filter: String("test"),
438-
}
439+
url := "some/path"
439440

440-
want := `{
441-
"startIndex": 1,
442-
"count": 10,
443-
"filter": "test"
444-
}`
441+
testAddURLOptions(t, url, &ListSCIMProvisionedIdentitiesOptions{}, url)
445442

446-
testJSONMarshal(t, u, want)
443+
testAddURLOptions(
444+
t,
445+
url,
446+
&ListSCIMProvisionedIdentitiesOptions{
447+
StartIndex: Int(1),
448+
Count: Int(10),
449+
},
450+
fmt.Sprintf("%s?count=10&startIndex=1", url),
451+
)
452+
453+
testAddURLOptions(
454+
t,
455+
url,
456+
&ListSCIMProvisionedIdentitiesOptions{
457+
StartIndex: Int(1),
458+
Count: Int(10),
459+
Filter: String("test"),
460+
},
461+
fmt.Sprintf("%s?count=10&filter=test&startIndex=1", url),
462+
)
447463
}
448464

449465
func TestSCIMUserName_Marshal(t *testing.T) {

0 commit comments

Comments
 (0)