diff --git a/CHANGELOG.md b/CHANGELOG.md index 90401ad261..d611eba811 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ For details about compatibility between different releases, see the **Commitment - Potential leak of end devices of other (owned) applications in the top end devices panel in the application overview of the Console. - Fix reversed Join Server dev nonce metrics. -- Default page limit on IS List RPCs if not provided in the request. +- Enforce default page limit on IS List RPCs if a value is not provided in the request. ### Security diff --git a/pkg/identityserver/bunstore/store_test.go b/pkg/identityserver/bunstore/store_test.go index 160f5b7ac3..1caa3fd8a0 100644 --- a/pkg/identityserver/bunstore/store_test.go +++ b/pkg/identityserver/bunstore/store_test.go @@ -72,6 +72,7 @@ func TestApplicationStore(t *testing.T) { st := storetest.New(t, newTestStore) st.TestApplicationStoreCRUD(t) st.TestApplicationStorePagination(t) + st.TestAPIKeyStorePaginationDefaults(t) } func TestClientStore(t *testing.T) { @@ -80,6 +81,7 @@ func TestClientStore(t *testing.T) { st := storetest.New(t, newTestStore) st.TestClientStoreCRUD(t) st.TestClientStorePagination(t) + st.TestClientStorePaginationDefaults(t) } func TestEndDeviceStore(t *testing.T) { @@ -108,6 +110,7 @@ func TestOrganizationStore(t *testing.T) { st := storetest.New(t, newTestStore) st.TestOrganizationStoreCRUD(t) st.TestOrganizationStorePagination(t) + st.TestOrganizationStorePaginationDefaults(t) } func TestUserStore(t *testing.T) { @@ -116,6 +119,7 @@ func TestUserStore(t *testing.T) { st := storetest.New(t, newTestStore) st.TestUserStoreCRUD(t) st.TestUserStorePagination(t) + st.TestUserSessionStorePaginationDefaults(t) } func TestUserSessionStore(t *testing.T) { @@ -124,6 +128,7 @@ func TestUserSessionStore(t *testing.T) { st := storetest.New(t, newTestStore) st.TestUserSessionStore(t) st.TestUserSessionStorePagination(t) + st.TestUserSessionStorePaginationDefaults(t) } func TestUserBookmarkStore(t *testing.T) { @@ -140,6 +145,7 @@ func TestAPIKeyStore(t *testing.T) { st := storetest.New(t, newTestStore) st.TestAPIKeyStoreCRUD(t) st.TestAPIKeyStorePagination(t) + st.TestAPIKeyStorePaginationDefaults(t) } func TestMembershipStore(t *testing.T) { @@ -148,6 +154,7 @@ func TestMembershipStore(t *testing.T) { st := storetest.New(t, newTestStore) st.TestMembershipStoreCRUD(t) st.TestMembershipStorePagination(t) + st.TestMembershipStorePaginationDefaults(t) } func TestEmailValidationStore(t *testing.T) { @@ -163,6 +170,7 @@ func TestInvitationStore(t *testing.T) { st := storetest.New(t, newTestStore) st.TestInvitationStore(t) st.TestInvitationStorePagination(t) + st.TestInvitationStorePaginationDefaults(t) } func TestLoginTokenStore(t *testing.T) { @@ -178,6 +186,7 @@ func TestOAuthStore(t *testing.T) { st := storetest.New(t, newTestStore) st.TestOAuthStore(t) st.TestOAuthStorePagination(t) + st.TestOAuthStorePaginationDefaults(t) } func TestEUIStore(t *testing.T) { diff --git a/pkg/identityserver/storetest/api_key_store.go b/pkg/identityserver/storetest/api_key_store.go index cabbfa5375..d9fbb622e1 100644 --- a/pkg/identityserver/storetest/api_key_store.go +++ b/pkg/identityserver/storetest/api_key_store.go @@ -270,10 +270,14 @@ func (st *StoreTest) TestAPIKeyStorePagination(t *T) { // TestAPIKeyStorePaginationDefaults tests the default pagination values. func (st *StoreTest) TestAPIKeyStorePaginationDefaults(t *T) { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 7, + }) + app1 := st.population.NewApplication(nil) var all []*ttnpb.APIKey - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { _, key := st.population.NewAPIKey(app1.GetEntityIdentifiers(), ttnpb.Right_RIGHT_APPLICATION_ALL) key.Name = fmt.Sprintf("Key %d", i) all = append(all, key) @@ -296,10 +300,10 @@ func (st *StoreTest) TestAPIKeyStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(ctx, 0, 1, &total) + paginateCtx := store.WithPagination(ctx, 0, 0, &total) got, err := s.FindAPIKeys(paginateCtx, app1.GetEntityIdentifiers()) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) } diff --git a/pkg/identityserver/storetest/application_store.go b/pkg/identityserver/storetest/application_store.go index 9ab3a8704c..ff77321fa3 100644 --- a/pkg/identityserver/storetest/application_store.go +++ b/pkg/identityserver/storetest/application_store.go @@ -363,9 +363,13 @@ func (st *StoreTest) TestApplicationStorePagination(t *T) { // TestApplicationStorePaginationDefaults tests the default pagination values. func (st *StoreTest) TestApplicationStorePaginationDefaults(t *T) { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 7, + }) + usr1 := st.population.NewUser() - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { st.population.NewApplication(usr1.GetOrganizationOrUserIdentifiers()) } @@ -385,10 +389,10 @@ func (st *StoreTest) TestApplicationStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(ctx, 0, 1, &total) + paginateCtx := store.WithPagination(ctx, 0, 0, &total) got, err := s.FindApplications(paginateCtx, nil, mask) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) } diff --git a/pkg/identityserver/storetest/client_store.go b/pkg/identityserver/storetest/client_store.go index 38e18b1af0..488e789cea 100644 --- a/pkg/identityserver/storetest/client_store.go +++ b/pkg/identityserver/storetest/client_store.go @@ -351,9 +351,13 @@ func (st *StoreTest) TestClientStorePagination(t *T) { // TestClientStorePaginationDefaults tests the default pagination values. func (st *StoreTest) TestClientStorePaginationDefaults(t *T) { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 7, + }) + usr1 := st.population.NewUser() - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { st.population.NewClient(usr1.GetOrganizationOrUserIdentifiers()) } @@ -373,10 +377,10 @@ func (st *StoreTest) TestClientStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(ctx, 0, 1, &total) + paginateCtx := store.WithPagination(ctx, 0, 0, &total) got, err := s.FindClients(paginateCtx, nil, mask) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) } diff --git a/pkg/identityserver/storetest/invitation_store.go b/pkg/identityserver/storetest/invitation_store.go index 35fbdf1734..81fd21ac6e 100644 --- a/pkg/identityserver/storetest/invitation_store.go +++ b/pkg/identityserver/storetest/invitation_store.go @@ -254,6 +254,10 @@ func (st *StoreTest) TestInvitationStorePagination(t *T) { // TestInvitationStorePaginationDefaults tests the default pagination values. func (st *StoreTest) TestInvitationStorePaginationDefaults(t *T) { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 7, + }) + a, ctx := test.New(t) start := time.Now().Truncate(time.Second) @@ -267,7 +271,7 @@ func (st *StoreTest) TestInvitationStorePaginationDefaults(t *T) { } defer s.Close() - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { _, err := s.CreateInvitation(ctx, &ttnpb.Invitation{ Email: fmt.Sprintf("user%d@example.com", i+1), Token: fmt.Sprintf("TOKEN%d", i+1), @@ -282,10 +286,10 @@ func (st *StoreTest) TestInvitationStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(store.WithOrder(ctx, "email"), 0, 1, &total) + paginateCtx := store.WithPagination(store.WithOrder(ctx, "email"), 0, 0, &total) got, err := s.FindInvitations(paginateCtx) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) } diff --git a/pkg/identityserver/storetest/membership_store.go b/pkg/identityserver/storetest/membership_store.go index a4858f926a..bdcd6a149e 100644 --- a/pkg/identityserver/storetest/membership_store.go +++ b/pkg/identityserver/storetest/membership_store.go @@ -392,19 +392,23 @@ func (st *StoreTest) TestMembershipStorePagination(t *T) { // TestMembershipStorePaginationDefaults tests the default pagination values. func (st *StoreTest) TestMembershipStorePaginationDefaults(t *T) { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 7, + }) + var apps []*ttnpb.Application - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { apps = append(apps, st.population.NewApplication(nil)) } var memberIDs []*ttnpb.OrganizationOrUserIdentifiers - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { ids := st.population.NewUser().GetOrganizationOrUserIdentifiers() memberIDs = append(memberIDs, ids) st.population.NewMembership(ids, apps[0].GetEntityIdentifiers(), ttnpb.Right_RIGHT_APPLICATION_ALL) } - for i := 1; i < 102; i++ { + for i := 1; i < 10; i++ { st.population.NewMembership(memberIDs[0], apps[i].GetEntityIdentifiers(), ttnpb.Right_RIGHT_APPLICATION_ALL) } @@ -423,11 +427,11 @@ func (st *StoreTest) TestMembershipStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(ctx, 0, 1, &total) + paginateCtx := store.WithPagination(ctx, 0, 0, &total) got, err := s.FindMembers(paginateCtx, apps[0].GetEntityIdentifiers()) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) @@ -435,11 +439,11 @@ func (st *StoreTest) TestMembershipStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(ctx, 0, 1, &total) + paginateCtx := store.WithPagination(ctx, 0, 0, &total) got, err := s.FindMemberships(paginateCtx, memberIDs[0], "application", false) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) } diff --git a/pkg/identityserver/storetest/oauth_store.go b/pkg/identityserver/storetest/oauth_store.go index 18b7c1991b..db5b1b942d 100644 --- a/pkg/identityserver/storetest/oauth_store.go +++ b/pkg/identityserver/storetest/oauth_store.go @@ -454,12 +454,16 @@ func (st *StoreTest) TestOAuthStorePagination(t *T) { // TestOAuthStorePaginationDefaults tests the default pagination values. func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 7, + }) + a, ctx := test.New(t) usr1 := st.population.NewUser() var clients []*ttnpb.Client - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { clients = append(clients, st.population.NewClient(usr1.GetOrganizationOrUserIdentifiers())) } @@ -473,7 +477,7 @@ func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { } defer s.Close() - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { _, err := s.Authorize(ctx, &ttnpb.OAuthClientAuthorization{ UserIds: usr1.GetIds(), ClientIds: clients[i].GetIds(), @@ -485,7 +489,7 @@ func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { time.Sleep(test.Delay) } - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { _, err := s.CreateAccessToken(ctx, &ttnpb.OAuthAccessToken{ UserIds: usr1.GetIds(), ClientIds: clients[0].GetIds(), @@ -502,11 +506,11 @@ func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 1, &total) + paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 0, &total) got, err := s.ListAuthorizations(paginateCtx, usr1.GetIds()) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) @@ -514,11 +518,11 @@ func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 1, &total) + paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 0, &total) got, err := s.ListAccessTokens(paginateCtx, usr1.GetIds(), clients[0].GetIds()) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) } diff --git a/pkg/identityserver/storetest/organization_store.go b/pkg/identityserver/storetest/organization_store.go index 1cb0ee4cb0..d6d86814c0 100644 --- a/pkg/identityserver/storetest/organization_store.go +++ b/pkg/identityserver/storetest/organization_store.go @@ -353,9 +353,13 @@ func (st *StoreTest) TestOrganizationStorePagination(t *T) { // TestOrganizationStorePaginationDefaults tests the default pagination values. func (st *StoreTest) TestOrganizationStorePaginationDefaults(t *T) { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 7, + }) + usr1 := st.population.NewUser() - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { st.population.NewOrganization(usr1.GetOrganizationOrUserIdentifiers()) } @@ -375,11 +379,11 @@ func (st *StoreTest) TestOrganizationStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(ctx, 0, 1, &total) + paginateCtx := store.WithPagination(ctx, 0, 0, &total) got, err := s.FindOrganizations(paginateCtx, nil, mask) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) } diff --git a/pkg/identityserver/storetest/user_session_store.go b/pkg/identityserver/storetest/user_session_store.go index b682202535..31ce81eb76 100644 --- a/pkg/identityserver/storetest/user_session_store.go +++ b/pkg/identityserver/storetest/user_session_store.go @@ -232,6 +232,10 @@ func (st *StoreTest) TestUserSessionStorePagination(t *T) { // TestUserSessionStorePaginationDefaults tests the default pagination values. func (st *StoreTest) TestUserSessionStorePaginationDefaults(t *T) { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 7, + }) + a, ctx := test.New(t) usr1 := st.population.NewUser() @@ -246,7 +250,7 @@ func (st *StoreTest) TestUserSessionStorePaginationDefaults(t *T) { } defer s.Close() - for i := 0; i < 102; i++ { + for i := 0; i < 10; i++ { _, err := s.CreateSession(ctx, &ttnpb.UserSession{ UserIds: usr1.GetIds(), SessionId: fmt.Sprintf("SESS%d", i+1), @@ -262,11 +266,11 @@ func (st *StoreTest) TestUserSessionStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 1, &total) + paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 0, &total) got, err := s.FindSessions(paginateCtx, usr1.GetIds()) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) } diff --git a/pkg/identityserver/storetest/user_store.go b/pkg/identityserver/storetest/user_store.go index 55c8f0be91..34ee6feab3 100644 --- a/pkg/identityserver/storetest/user_store.go +++ b/pkg/identityserver/storetest/user_store.go @@ -475,7 +475,11 @@ func (st *StoreTest) TestUserStorePagination(t *T) { // TestUserStorePaginationDefaults tests the default pagination values. func (st *StoreTest) TestUserStorePaginationDefaults(t *T) { - for i := 0; i < 102; i++ { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 7, + }) + + for i := 0; i < 10; i++ { st.population.NewUser() } @@ -495,11 +499,11 @@ func (st *StoreTest) TestUserStorePaginationDefaults(t *T) { a, ctx := test.New(t) var total uint64 - paginateCtx := store.WithPagination(ctx, 0, 1, &total) + paginateCtx := store.WithPagination(ctx, 0, 0, &total) got, err := s.FindUsers(paginateCtx, nil, mask) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { - a.So(got, should.HaveLength, 100) + a.So(got, should.HaveLength, 7) } }) }