Skip to content

Commit

Permalink
Merge pull request #254 from akoserwal/add-pagination-getclients
Browse files Browse the repository at this point in the history
added `first` & `max` to client query parameters to support pagination
  • Loading branch information
Nerzal authored Jan 26, 2021
2 parents 4e44693 + 48b06fe commit bc842fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5273,3 +5273,35 @@ func TestGocloak_TestSetFunctionalOptions(t *testing.T) {
cfg := GetConfig(t)
gocloak.NewClient(cfg.HostName, gocloak.SetAuthRealms("foo"), gocloak.SetAuthAdminRealms("bar"))
}

func TestGocloak_GetClientsWithPagination(t *testing.T) {
cfg := GetConfig(t)
client := NewClientWithDebug(t)
token := GetAdminToken(t, client)
clientID := GetRandomNameP("ClientID")

testClient := gocloak.Client{
ClientID: clientID,
BaseURL: gocloak.StringP("http://example.com"),
}
t.Logf("Client ID: %s", *clientID)

// Creating a client
tearDown, createdClientID := CreateClient(t, client, &testClient)
defer tearDown()
t.Log(createdClientID)
first := 0
max := 1
// Looking for a created client
clients, err := client.GetClients(
context.Background(),
token.AccessToken,
cfg.GoCloak.Realm,
gocloak.GetClientsParams{
First: &first,
Max: &max,
},
)
require.NoError(t, err)
require.Equal(t, max, len(clients))
}
2 changes: 2 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ type ProtocolMapperRepresentation struct {
type GetClientsParams struct {
ClientID *string `json:"clientId,omitempty"`
ViewableOnly *bool `json:"viewableOnly,string,omitempty"`
First *int `json:"first,string,omitempty"`
Max *int `json:"max,string,omitempty"`
}

// UserInfoAddress is representation of the address sub-filed of UserInfo
Expand Down

0 comments on commit bc842fe

Please sign in to comment.