Skip to content

Commit

Permalink
Merge pull request #472 from okta/fix-dpop-pagination
Browse files Browse the repository at this point in the history
fix dpop pagination
  • Loading branch information
duytiennguyen-okta authored Jul 9, 2024
2 parents e13c84a + fc1480b commit 0fc0b87
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
37 changes: 37 additions & 0 deletions .generator/templates/private_key_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package okta

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -86,3 +87,39 @@ func Test_Dpop_Get_User(t *testing.T) {
err = cleanUpUser(user.GetId())
require.NoError(t, err, "Clean up user should not error")
}

func Test_Dpop_Pagination(t *testing.T) {
configuration, err := NewConfiguration(WithAuthorizationMode("PrivateKey"), WithScopes([]string{"okta.users.manage", "okta.users.read"}))
require.NoError(t, err, "Creating a new config should not error")
client := NewAPIClient(configuration)
uc := testFactory.NewValidTestUserCredentialsWithPassword()
profile := testFactory.NewValidTestUserProfile()
body := CreateUserRequest{Credentials: uc, Profile: profile}
createdUser1, _, err := client.UserAPI.CreateUser(client.cfg.Context).Body(body).Activate(true).Execute()
require.NoError(t, err, "Creating a new user should not error")
uc = testFactory.NewValidTestUserCredentialsWithPassword()
profile = testFactory.NewValidTestUserProfile()
body = CreateUserRequest{Credentials: uc, Profile: profile}
createdUser2, _, err := client.UserAPI.CreateUser(client.cfg.Context).Body(body).Activate(true).Execute()
require.NoError(t, err, "Creating a new user should not error")
user1, resp, err := client.UserAPI.ListUsers(client.cfg.Context).Limit(1).Execute()
require.NoError(t, err)
assert.Equal(t, 1, len(user1), "User1 did not return 1 user")
user1Profile := user1[0].GetProfile()
hasNext := resp.HasNextPage()
assert.True(t, hasNext, "Should return true for HasNextPage")
var user2 []User
res, err := resp.Next(&user2)
require.NoError(t, err)
respBody, err := ioutil.ReadAll(res.Body)
res.Body.Close()
require.NoError(t, err)
assert.NotEmpty(t, string(respBody), "body is empty")
assert.Equal(t, 1, len(user2), "User2 did not return 1 user")
user2Profile := user2[0].GetProfile()
assert.NotEqual(t, user2Profile.GetEmail(), user1Profile.GetEmail(), "Emails should not be the same")
err = cleanUpUser(createdUser1.GetId())
require.NoError(t, err, "Should not error when deactivating")
err = cleanUpUser(createdUser2.GetId())
require.NoError(t, err, "Should not error when deactivating")
}
6 changes: 5 additions & 1 deletion .generator/templates/response.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func (res *APIResponse) Next(v interface{}) (*APIResponse, error) {
if res.cli == nil {
return nil, errors.New("no initial response provided from previous request")
}
req, err := res.cli.prepareRequest(res.cli.cfg.Context, res.NextPage(), http.MethodGet, nil, map[string]string{"Accept": "application/json"},nil, nil, nil)
URL, err := url.Parse(res.NextPage())
if err != nil {
return nil, err
}
req, err := res.cli.prepareRequest(res.cli.cfg.Context, URL.Path, http.MethodGet, nil, map[string]string{"Accept": "application/json"}, URL.Query(), nil, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0fc0b87

Please sign in to comment.