From d20e54d7533c7ac7a654af49b5a9b2925644c2bb Mon Sep 17 00:00:00 2001 From: Bob Stasyszyn Date: Fri, 26 Nov 2021 17:08:11 -0500 Subject: [PATCH] chore: Added a sort order parameter to activities handler Paging with descending sort order currently does not work with MongoDB (issue #893) so sorting of activities is temporarily (maybe permanently) set to ascending. Signed-off-by: Bob Stasyszyn --- cmd/orb-server/startcmd/start.go | 12 ++-- .../resthandler/activityhandler.go | 34 +++++------ .../resthandler/activityhandler_test.go | 58 +++++++++---------- .../resthandler/referencehandler.go | 4 +- pkg/activitypub/resthandler/resthandler.go | 4 +- .../resthandler/resthandler_test.go | 18 +++--- .../resthandler/serviceshandler.go | 4 +- 7 files changed, 68 insertions(+), 66 deletions(-) diff --git a/cmd/orb-server/startcmd/start.go b/cmd/orb-server/startcmd/start.go index a192ab586..f2856d91f 100644 --- a/cmd/orb-server/startcmd/start.go +++ b/cmd/orb-server/startcmd/start.go @@ -865,15 +865,15 @@ func startOrbServices(parameters *orbParameters) error { aphandler.NewPublicKeys(apEndpointCfg, apStore, publicKey), aphandler.NewFollowers(apEndpointCfg, apStore, apSigVerifier), aphandler.NewFollowing(apEndpointCfg, apStore, apSigVerifier), - aphandler.NewOutbox(apEndpointCfg, apStore, apSigVerifier), - aphandler.NewInbox(apEndpointCfg, apStore, apSigVerifier), + aphandler.NewOutbox(apEndpointCfg, apStore, apSigVerifier, activitypubspi.SortAscending), + aphandler.NewInbox(apEndpointCfg, apStore, apSigVerifier, activitypubspi.SortAscending), aphandler.NewWitnesses(apEndpointCfg, apStore, apSigVerifier), aphandler.NewWitnessing(apEndpointCfg, apStore, apSigVerifier), - aphandler.NewLiked(apEndpointCfg, apStore, apSigVerifier), - aphandler.NewLikes(apEndpointCfg, apStore, apSigVerifier), - aphandler.NewShares(apEndpointCfg, apStore, apSigVerifier), + aphandler.NewLiked(apEndpointCfg, apStore, apSigVerifier, activitypubspi.SortAscending), + aphandler.NewLikes(apEndpointCfg, apStore, apSigVerifier, activitypubspi.SortAscending), + aphandler.NewShares(apEndpointCfg, apStore, apSigVerifier, activitypubspi.SortAscending), aphandler.NewPostOutbox(apEndpointCfg, activityPubService.Outbox(), apStore, apSigVerifier), - aphandler.NewActivity(apEndpointCfg, apStore, apSigVerifier), + aphandler.NewActivity(apEndpointCfg, apStore, apSigVerifier, activitypubspi.SortAscending), webcas.New(apEndpointCfg, apStore, apSigVerifier, coreCASClient), auth.NewHandlerWrapper(authCfg, policyhandler.New(configStore)), auth.NewHandlerWrapper(authCfg, nodeinfo.NewHandler(nodeinfo.V2_0, nodeInfoService, nodeInfoLogger)), diff --git a/pkg/activitypub/resthandler/activityhandler.go b/pkg/activitypub/resthandler/activityhandler.go index 7b6aa7e82..b91e42cef 100644 --- a/pkg/activitypub/resthandler/activityhandler.go +++ b/pkg/activitypub/resthandler/activityhandler.go @@ -19,16 +19,16 @@ import ( ) // NewActivity returns a new 'activities/{id}' REST handler that retrieves a single activity by ID. -func NewActivity(cfg *Config, activityStore spi.Store, verifier signatureVerifier) *Activity { +func NewActivity(cfg *Config, activityStore spi.Store, verifier signatureVerifier, sortOrder spi.SortOrder) *Activity { h := &Activity{} - h.handler = newHandler(ActivitiesPath, cfg, activityStore, h.handle, verifier) + h.handler = newHandler(ActivitiesPath, cfg, activityStore, h.handle, verifier, sortOrder) return h } // NewOutbox returns a new 'outbox' REST handler that retrieves a service's outbox. -func NewOutbox(cfg *Config, activityStore spi.Store, verifier signatureVerifier) *ReadOutbox { +func NewOutbox(cfg *Config, activityStore spi.Store, verifier signatureVerifier, sortOrder spi.SortOrder) *ReadOutbox { h := &ReadOutbox{ Activities: &Activities{ getID: getID("outbox"), @@ -36,34 +36,34 @@ func NewOutbox(cfg *Config, activityStore spi.Store, verifier signatureVerifier) }, } - h.Activities.handler = newHandler(OutboxPath, cfg, activityStore, h.handleOutbox, verifier) + h.Activities.handler = newHandler(OutboxPath, cfg, activityStore, h.handleOutbox, verifier, sortOrder) return h } // NewInbox returns a new 'inbox' REST handler that retrieves a service's inbox. -func NewInbox(cfg *Config, activityStore spi.Store, verifier signatureVerifier) *Activities { +func NewInbox(cfg *Config, activityStore spi.Store, verifier signatureVerifier, sortOrder spi.SortOrder) *Activities { return NewActivities(InboxPath, spi.Inbox, cfg, activityStore, - getObjectIRI(cfg.ObjectIRI), getID("inbox"), verifier) + getObjectIRI(cfg.ObjectIRI), getID("inbox"), verifier, sortOrder) } // NewShares returns a new 'shares' REST handler that retrieves an object's 'Announce' activities. -func NewShares(cfg *Config, activityStore spi.Store, verifier signatureVerifier) *Activities { +func NewShares(cfg *Config, activityStore spi.Store, verifier signatureVerifier, sortOrder spi.SortOrder) *Activities { return NewActivities(SharesPath, spi.Share, cfg, activityStore, - getObjectIRIFromIDParam, getIDFromParam(cfg.ObjectIRI, SharesPath), verifier) + getObjectIRIFromIDParam, getIDFromParam(cfg.ObjectIRI, SharesPath), verifier, sortOrder) } // NewLikes returns a new 'likes' REST handler that retrieves an object's 'Like' activities. -func NewLikes(cfg *Config, activityStore spi.Store, verifier signatureVerifier) *Activities { +func NewLikes(cfg *Config, activityStore spi.Store, verifier signatureVerifier, sortOrder spi.SortOrder) *Activities { return NewActivities(LikesPath, spi.Like, cfg, activityStore, - getObjectIRIFromIDParam, getIDFromParam(cfg.ObjectIRI, LikesPath), verifier) + getObjectIRIFromIDParam, getIDFromParam(cfg.ObjectIRI, LikesPath), verifier, sortOrder) } // NewLiked returns a new 'liked' REST handler that retrieves a service's 'Like' activities, i.e. the Like // activities that were posted by the given service. -func NewLiked(cfg *Config, activityStore spi.Store, verifier signatureVerifier) *Activities { +func NewLiked(cfg *Config, activityStore spi.Store, verifier signatureVerifier, sortOrder spi.SortOrder) *Activities { return NewActivities(LikedPath, spi.Liked, cfg, activityStore, - getObjectIRI(cfg.ObjectIRI), getID("liked"), verifier) + getObjectIRI(cfg.ObjectIRI), getID("liked"), verifier, sortOrder) } type getIDFunc func(objectIRI *url.URL, req *http.Request) (*url.URL, error) @@ -81,14 +81,14 @@ type Activities struct { // NewActivities returns a new activities REST handler. func NewActivities(path string, refType spi.ReferenceType, cfg *Config, activityStore spi.Store, - getObjectIRI getObjectIRIFunc, getID getIDFunc, verifier signatureVerifier) *Activities { + getObjectIRI getObjectIRIFunc, getID getIDFunc, verifier signatureVerifier, sortOrder spi.SortOrder) *Activities { h := &Activities{ refType: refType, getID: getID, getObjectIRI: getObjectIRI, } - h.handler = newHandler(path, cfg, activityStore, h.handle, verifier) + h.handler = newHandler(path, cfg, activityStore, h.handle, verifier, sortOrder) return h } @@ -169,12 +169,12 @@ func (h *Activities) handleActivitiesPage(rw http.ResponseWriter, req *http.Requ page, err = h.getPage(objectIRI, id, refType, spi.WithPageSize(h.PageSize), spi.WithPageNum(pageNum), - spi.WithSortOrder(spi.SortDescending), + spi.WithSortOrder(h.sortOrder), ) } else { page, err = h.getPage(objectIRI, id, refType, spi.WithPageSize(h.PageSize), - spi.WithSortOrder(spi.SortDescending), + spi.WithSortOrder(h.sortOrder), ) } @@ -228,7 +228,7 @@ func (h *Activities) getActivities(objectIRI, id *url.URL, return nil, fmt.Errorf("failed to get total items from reference query: %w", err) } - lastURL, err := h.getPageURL(id, getLastPageNum(totalItems, h.PageSize, spi.SortDescending)) + lastURL, err := h.getPageURL(id, getLastPageNum(totalItems, h.PageSize, h.sortOrder)) if err != nil { return nil, err } diff --git a/pkg/activitypub/resthandler/activityhandler_test.go b/pkg/activitypub/resthandler/activityhandler_test.go index 2a9ec1018..691307dff 100644 --- a/pkg/activitypub/resthandler/activityhandler_test.go +++ b/pkg/activitypub/resthandler/activityhandler_test.go @@ -42,7 +42,7 @@ func TestNewOutbox(t *testing.T) { PageSize: 4, } - h := NewOutbox(cfg, memstore.New(""), &mocks.SignatureVerifier{}) + h := NewOutbox(cfg, memstore.New(""), &mocks.SignatureVerifier{}, spi.SortDescending) require.NotNil(t, h) require.Equal(t, "/services/orb/outbox", h.Path()) require.Equal(t, http.MethodGet, h.Method()) @@ -66,7 +66,7 @@ func TestNewInbox(t *testing.T) { PageSize: 4, } - h := NewInbox(cfg, memstore.New(""), &mocks.SignatureVerifier{}) + h := NewInbox(cfg, memstore.New(""), &mocks.SignatureVerifier{}, spi.SortDescending) require.NotNil(t, h) require.Equal(t, "/services/orb/inbox", h.Path()) require.Equal(t, http.MethodGet, h.Method()) @@ -91,7 +91,7 @@ func TestNewShares(t *testing.T) { ObjectIRI: serviceIRI, } - h := NewShares(cfg, memstore.New(""), &mocks.SignatureVerifier{}) + h := NewShares(cfg, memstore.New(""), &mocks.SignatureVerifier{}, spi.SortDescending) require.NotNil(t, h) require.Equal(t, "/services/orb/shares", h.Path()) require.Equal(t, http.MethodGet, h.Method()) @@ -132,7 +132,7 @@ func TestNewLikes(t *testing.T) { ObjectIRI: serviceIRI, } - h := NewLikes(cfg, memstore.New(""), &mocks.SignatureVerifier{}) + h := NewLikes(cfg, memstore.New(""), &mocks.SignatureVerifier{}, spi.SortDescending) require.NotNil(t, h) require.Equal(t, "/services/orb/likes", h.Path()) require.Equal(t, http.MethodGet, h.Method()) @@ -203,7 +203,7 @@ func TestActivities_Handler(t *testing.T) { verifier.VerifyRequestReturns(true, service2IRI, nil) t.Run("Success", func(t *testing.T) { - h := NewInbox(cfg, activityStore, verifier) + h := NewInbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -229,7 +229,7 @@ func TestActivities_Handler(t *testing.T) { s := &mocks.ActivityStore{} s.QueryReferencesReturns(nil, errExpected) - h := NewInbox(cfg, s, verifier) + h := NewInbox(cfg, s, verifier, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -243,7 +243,7 @@ func TestActivities_Handler(t *testing.T) { }) t.Run("Marshal error", func(t *testing.T) { - h := NewInbox(cfg, activityStore, verifier) + h := NewInbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) errExpected := fmt.Errorf("injected marshal error") @@ -263,7 +263,7 @@ func TestActivities_Handler(t *testing.T) { }) t.Run("GetObjectIRI error", func(t *testing.T) { - h := NewInbox(cfg, activityStore, verifier) + h := NewInbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) t.Run("Internal error", func(t *testing.T) { @@ -302,7 +302,7 @@ func TestActivities_Handler(t *testing.T) { }) t.Run("GetID error", func(t *testing.T) { - h := NewInbox(cfg, activityStore, verifier) + h := NewInbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) errExpected := fmt.Errorf("injected error") @@ -327,7 +327,7 @@ func TestActivities_Handler(t *testing.T) { verifier := &mocks.SignatureVerifier{} verifier.VerifyRequestReturns(false, nil, errExpected) - h := NewInbox(cfg, activityStore, verifier) + h := NewInbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -344,7 +344,7 @@ func TestActivities_Handler(t *testing.T) { verifier := &mocks.SignatureVerifier{} verifier.VerifyRequestReturns(false, nil, nil) - h := NewInbox(cfg, activityStore, verifier) + h := NewInbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -404,7 +404,7 @@ func TestActivities_PageHandler(t *testing.T) { PageSize: 4, } - h := NewOutbox(cfg, s, verifier) + h := NewOutbox(cfg, s, verifier, spi.SortDescending) require.NotNil(t, h) restorePaging := setPaging(h.handler, "true", "0") @@ -426,7 +426,7 @@ func TestActivities_PageHandler(t *testing.T) { PageSize: 4, } - h := NewOutbox(cfg, activityStore, verifier) + h := NewOutbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) restorePaging := setPaging(h.handler, "true", "0") @@ -493,7 +493,7 @@ func TestReadOutbox_Handler(t *testing.T) { verifier := &mocks.SignatureVerifier{} verifier.VerifyRequestReturns(true, service2IRI, nil) - h := NewOutbox(cfg, activityStore, verifier) + h := NewOutbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -517,7 +517,7 @@ func TestReadOutbox_Handler(t *testing.T) { verifier := &mocks.SignatureVerifier{} verifier.VerifyRequestReturns(false, nil, nil) - h := NewOutbox(cfg, activityStore, verifier) + h := NewOutbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -541,7 +541,7 @@ func TestReadOutbox_Handler(t *testing.T) { verifier := &mocks.SignatureVerifier{} verifier.VerifyRequestReturns(false, nil, errors.New("injected auth error")) - h := NewOutbox(cfg, activityStore, verifier) + h := NewOutbox(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -583,7 +583,7 @@ func TestShares_Handler(t *testing.T) { verifier.VerifyRequestReturns(true, srvcIRI, nil) t.Run("Success", func(t *testing.T) { - h := NewShares(cfg, activityStore, verifier) + h := NewShares(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) restore := setIDParam(id) @@ -635,7 +635,7 @@ func TestShares_PageHandler(t *testing.T) { verifier.VerifyRequestReturns(true, srvcIRI, nil) t.Run("First page -> Success", func(t *testing.T) { - h := NewShares(cfg, activityStore, verifier) + h := NewShares(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) restorePaging := setPaging(h.handler, "true", "") @@ -662,7 +662,7 @@ func TestShares_PageHandler(t *testing.T) { }) t.Run("By page -> Success", func(t *testing.T) { - h := NewShares(cfg, activityStore, verifier) + h := NewShares(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) restorePaging := setPaging(h.handler, "true", "1") @@ -710,7 +710,7 @@ func TestLiked_Handler(t *testing.T) { verifier := &mocks.SignatureVerifier{} verifier.VerifyRequestReturns(true, serviceIRI, nil) - h := NewLiked(cfg, activityStore, verifier) + h := NewLiked(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) t.Run("Main page -> Success", func(t *testing.T) { @@ -723,7 +723,7 @@ func TestLiked_Handler(t *testing.T) { } func TestNewActivity(t *testing.T) { - h := NewActivity(&Config{BasePath: basePath}, memstore.New(""), &mocks.SignatureVerifier{}) + h := NewActivity(&Config{BasePath: basePath}, memstore.New(""), &mocks.SignatureVerifier{}, spi.SortDescending) require.NotNil(t, h) require.Equal(t, basePath+ActivitiesPath, h.Path()) require.Equal(t, http.MethodGet, h.Method()) @@ -751,7 +751,7 @@ func TestActivity_Handler(t *testing.T) { verifier := &mocks.SignatureVerifier{} verifier.VerifyRequestReturns(true, nil, nil) - h := NewActivity(cfg, activityStore, verifier) + h := NewActivity(cfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -775,7 +775,7 @@ func TestActivity_Handler(t *testing.T) { }) t.Run("No activity ID -> BadRequest", func(t *testing.T) { - h := NewActivity(cfg, activityStore, &mocks.SignatureVerifier{}) + h := NewActivity(cfg, activityStore, &mocks.SignatureVerifier{}, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -789,7 +789,7 @@ func TestActivity_Handler(t *testing.T) { }) t.Run("Activity ID not found -> NotFound", func(t *testing.T) { - h := NewActivity(cfg, activityStore, &mocks.SignatureVerifier{}) + h := NewActivity(cfg, activityStore, &mocks.SignatureVerifier{}, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -809,7 +809,7 @@ func TestActivity_Handler(t *testing.T) { as := &mocks.ActivityStore{} as.GetActivityReturns(nil, errors.New("injected store error")) - h := NewActivity(cfg, as, &mocks.SignatureVerifier{}) + h := NewActivity(cfg, as, &mocks.SignatureVerifier{}, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -826,7 +826,7 @@ func TestActivity_Handler(t *testing.T) { }) t.Run("Marshal error", func(t *testing.T) { - h := NewActivity(cfg, activityStore, &mocks.SignatureVerifier{}) + h := NewActivity(cfg, activityStore, &mocks.SignatureVerifier{}, spi.SortDescending) require.NotNil(t, h) errExpected := fmt.Errorf("injected marshal error") @@ -869,7 +869,7 @@ func TestActivity_Handler(t *testing.T) { }, } - h := NewActivity(cnfg, activityStore, verifier) + h := NewActivity(cnfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) t.Run("Non-public activity -> unauthorized", func(t *testing.T) { @@ -913,7 +913,7 @@ func TestActivity_Handler(t *testing.T) { verifier := &mocks.SignatureVerifier{} verifier.VerifyRequestReturns(false, nil, errExpected) - h := NewActivity(cnfg, activityStore, verifier) + h := NewActivity(cnfg, activityStore, verifier, spi.SortDescending) require.NotNil(t, h) rw := httptest.NewRecorder() @@ -979,7 +979,7 @@ func handleActivitiesRequest(t *testing.T, serviceIRI *url.URL, as spi.Store, pa verifier := &mocks.SignatureVerifier{} verifier.VerifyRequestReturns(true, serviceIRI, nil) - h := NewInbox(cfg, as, verifier) + h := NewInbox(cfg, as, verifier, spi.SortDescending) require.NotNil(t, h) restorePaging := setPaging(h.handler, page, pageNum) diff --git a/pkg/activitypub/resthandler/referencehandler.go b/pkg/activitypub/resthandler/referencehandler.go index a8e10e24c..f0e7f2c77 100644 --- a/pkg/activitypub/resthandler/referencehandler.go +++ b/pkg/activitypub/resthandler/referencehandler.go @@ -52,7 +52,6 @@ type Reference struct { *handler refType spi.ReferenceType - sortOrder spi.SortOrder createCollection createCollectionFunc createCollectionPage createCollectionFunc getID getIDFunc @@ -65,14 +64,13 @@ func NewReference(path string, refType spi.ReferenceType, sortOrder spi.SortOrde verifier signatureVerifier) *Reference { h := &Reference{ refType: refType, - sortOrder: sortOrder, createCollection: createCollection(ordered), createCollectionPage: createCollectionPage(ordered), getID: getID, getObjectIRI: getObjectIRI, } - h.handler = newHandler(path, cfg, activityStore, h.handle, verifier) + h.handler = newHandler(path, cfg, activityStore, h.handle, verifier, sortOrder) return h } diff --git a/pkg/activitypub/resthandler/resthandler.go b/pkg/activitypub/resthandler/resthandler.go index f91fcaed8..6d51879a0 100644 --- a/pkg/activitypub/resthandler/resthandler.go +++ b/pkg/activitypub/resthandler/resthandler.go @@ -86,10 +86,11 @@ type handler struct { handler common.HTTPRequestHandler marshal func(v interface{}) ([]byte, error) getParams func(req *http.Request) map[string][]string + sortOrder spi.SortOrder } func newHandler(endpoint string, cfg *Config, s spi.Store, rh common.HTTPRequestHandler, - verifier signatureVerifier, params ...string) *handler { + verifier signatureVerifier, sortOrder spi.SortOrder, params ...string) *handler { h := &handler{ Config: cfg, params: paramsBuilder(params).build(), @@ -98,6 +99,7 @@ func newHandler(endpoint string, cfg *Config, s spi.Store, rh common.HTTPRequest getParams: func(req *http.Request) map[string][]string { return req.URL.Query() }, + sortOrder: sortOrder, } h.AuthHandler = NewAuthHandler(cfg, endpoint, http.MethodGet, s, verifier, nil) diff --git a/pkg/activitypub/resthandler/resthandler_test.go b/pkg/activitypub/resthandler/resthandler_test.go index 5e503101e..121f40025 100644 --- a/pkg/activitypub/resthandler/resthandler_test.go +++ b/pkg/activitypub/resthandler/resthandler_test.go @@ -29,7 +29,7 @@ func TestNewHandler(t *testing.T) { } h := newHandler("", cfg, memstore.New(""), - func(writer http.ResponseWriter, request *http.Request) {}, &mocks.SignatureVerifier{}, + func(writer http.ResponseWriter, request *http.Request) {}, &mocks.SignatureVerifier{}, spi.SortDescending, pageNumParam, pageParam, ) @@ -72,7 +72,8 @@ func TestGetCurrentPrevNext(t *testing.T) { PageSize: 4, } - h := newHandler("", cfg, memstore.New(""), nil, &mocks.SignatureVerifier{}) + h := newHandler("", cfg, memstore.New(""), nil, &mocks.SignatureVerifier{}, + spi.SortDescending) t.Run("Sort ascending", func(t *testing.T) { t.Run("No page-num", func(t *testing.T) { @@ -164,7 +165,8 @@ func TestGetIDPrevNextURL(t *testing.T) { PageSize: 4, } - h := newHandler("", cfg, memstore.New(""), nil, &mocks.SignatureVerifier{}) + h := newHandler("", cfg, memstore.New(""), nil, &mocks.SignatureVerifier{}, + spi.SortDescending) id := testutil.MustParseURL(fmt.Sprintf("%s%s", cfg.ObjectIRI, "")) @@ -277,7 +279,7 @@ func TestAuthorizeActor(t *testing.T) { t.Run("Success", func(t *testing.T) { activityStore := memstore.New("") - h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}) + h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}, spi.SortDescending) require.NoError(t, activityStore.AddReference(spi.Follower, serviceIRI, service2IRI)) @@ -292,7 +294,7 @@ func TestAuthorizeActor(t *testing.T) { activityStore := &mocks.ActivityStore{} activityStore.QueryReferencesReturnsOnCall(0, nil, errExpected) - h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}) + h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}, spi.SortDescending) ok, err := h.authorizeActor(service2IRI) require.Error(t, err) @@ -305,7 +307,7 @@ func TestAuthorizeActor(t *testing.T) { t.Run("Success", func(t *testing.T) { activityStore := memstore.New("") - h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}) + h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}, spi.SortDescending) require.NoError(t, activityStore.AddReference(spi.Witness, serviceIRI, service2IRI)) @@ -322,7 +324,7 @@ func TestAuthorizeActor(t *testing.T) { activityStore.QueryReferencesReturnsOnCall(0, memstore.NewReferenceIterator(nil, 0), nil) activityStore.QueryReferencesReturnsOnCall(1, nil, errExpected) - h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}) + h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}, spi.SortDescending) ok, err := h.authorizeActor(service2IRI) require.Error(t, err) @@ -334,7 +336,7 @@ func TestAuthorizeActor(t *testing.T) { t.Run("Neither follower nor witness -> unauthorized", func(t *testing.T) { activityStore := memstore.New("") - h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}) + h := newHandler("", cfg, activityStore, nil, &mocks.SignatureVerifier{}, spi.SortDescending) ok, err := h.authorizeActor(service2IRI) require.NoError(t, err) diff --git a/pkg/activitypub/resthandler/serviceshandler.go b/pkg/activitypub/resthandler/serviceshandler.go index e78e913e9..491c22952 100644 --- a/pkg/activitypub/resthandler/serviceshandler.go +++ b/pkg/activitypub/resthandler/serviceshandler.go @@ -31,7 +31,7 @@ func NewServices(cfg *Config, activityStore spi.Store, publicKey *vocab.PublicKe publicKey: publicKey, } - h.handler = newHandler("", cfg, activityStore, h.handle, nil) + h.handler = newHandler("", cfg, activityStore, h.handle, nil, spi.SortAscending) return h } @@ -42,7 +42,7 @@ func NewPublicKeys(cfg *Config, activityStore spi.Store, publicKey *vocab.Public publicKey: publicKey, } - h.handler = newHandler(PublicKeysPath, cfg, activityStore, h.handlePublicKey, nil) + h.handler = newHandler(PublicKeysPath, cfg, activityStore, h.handlePublicKey, nil, spi.SortAscending) return h }