Skip to content

Commit

Permalink
Revert "fix: do not omit last page on identity list (#3169)" (#3184)
Browse files Browse the repository at this point in the history
This reverts commit f95f48a.
  • Loading branch information
aeneasr authored Mar 23, 2023
1 parent eb854be commit 73b5f13
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 45 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ require (
github.com/ory/mail/v3 v3.0.0
github.com/ory/nosurf v1.2.7
github.com/ory/x v0.0.537
github.com/peterhellberg/link v1.2.0
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.9.1
github.com/pquerna/otp v1.4.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,6 @@ github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/peterhellberg/link v1.2.0 h1:UA5pg3Gp/E0F2WdX7GERiNrPQrM1K6CVJUUWfHa4t6c=
github.com/peterhellberg/link v1.2.0/go.mod h1:gYfAh+oJgQu2SrZHg5hROVRQe1ICoK0/HHJTcE0edxc=
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
Expand Down
2 changes: 1 addition & 1 deletion identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (h *Handler) list(w http.ResponseWriter, r *http.Request, _ httprouter.Para
isam[i] = WithCredentialsMetadataAndAdminMetadataInJSON(identity)
}

migrationpagination.PaginationHeader(w, urlx.AppendPaths(h.r.Config().SelfAdminURL(r.Context()), RouteCollection), total+int64(itemsPerPage), page, itemsPerPage)
migrationpagination.PaginationHeader(w, urlx.AppendPaths(h.r.Config().SelfAdminURL(r.Context()), RouteCollection), total, page, itemsPerPage)
h.r.Writer().Write(w, r, isam)
}

Expand Down
45 changes: 4 additions & 41 deletions identity/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/ory/x/snapshotx"

"github.com/bxcodec/faker/v3"
"github.com/peterhellberg/link"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
Expand Down Expand Up @@ -1005,49 +1004,13 @@ func TestHandler(t *testing.T) {
})

t.Run("case=should list all identities", func(t *testing.T) {
expected, err := reg.IdentityPool().ListIdentities(ctx, identity.ListIdentityParameters{PerPage: 1000})
require.NoError(t, err)
expectedIDs := make([]string, len(expected))
for k, v := range expected {
expectedIDs[k] = v.ID.String()
}

for name, ts := range map[string]*httptest.Server{"public": publicTS, "admin": adminTS} {
t.Run("endpoint="+name, func(t *testing.T) {
res := get(t, ts, "/identities", http.StatusOK)
assert.Falsef(t, res.Get("0.credentials").Exists(), "credentials config should be omitted: %s", res.Raw)
assert.Truef(t, res.Get("0.metadata_public").Exists(), "metadata_public config should be included: %s", res.Raw)
assert.Truef(t, res.Get("0.metadata_admin").Exists(), "metadata_admin config should be included: %s", res.Raw)
assert.Truef(t, res.Get(`#(traits.bar=="baz").traits.bar`).Exists(), "some identity should have the traits {bar: baz}: %s", res.Raw)

assert.EqualValuesf(t, len(expectedIDs), int(res.Get("#").Num), "%s", res.Raw)
res.Get("#.id").ForEach(func(key, value gjson.Result) bool {
return assert.Contains(t, expectedIDs, value.String(), "%s", res.Raw)
})

actualIDs := make([]string, 0, len(expectedIDs))
for reqURL := ts.URL + "/identities?per_page=5&page=1"; ; {
res, err := ts.Client().Get(reqURL)
require.NoError(t, err)
body, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.NoError(t, res.Body.Close())

require.EqualValues(t, http.StatusOK, res.StatusCode, "%s", body)
var ids []identity.Identity
require.NoError(t, json.Unmarshal(body, &ids))
for _, id := range ids {
actualIDs = append(actualIDs, id.ID.String())
}

links := link.ParseHeader(res.Header)
next, ok := links["next"]
if !ok {
break
}
reqURL = next.URI
}
assert.ElementsMatch(t, expectedIDs, actualIDs)
assert.False(t, res.Get("0.credentials").Exists(), "credentials config should be omitted: %s", res.Raw)
assert.True(t, res.Get("0.metadata_public").Exists(), "metadata_public config should be included: %s", res.Raw)
assert.True(t, res.Get("0.metadata_admin").Exists(), "metadata_admin config should be included: %s", res.Raw)
assert.EqualValues(t, "baz", res.Get(`#(traits.bar=="baz").traits.bar`).String(), "%s", res.Raw)
})
}
})
Expand Down

0 comments on commit 73b5f13

Please sign in to comment.