From ded7b60d0c5f0395aebedcab0131c291bc10be46 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Wed, 1 May 2024 15:46:15 +0200 Subject: [PATCH] wix the invalid test --- .../api_activitypub_repository_test.go | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/tests/integration/api_activitypub_repository_test.go b/tests/integration/api_activitypub_repository_test.go index 748c77bef0..60d7e32822 100644 --- a/tests/integration/api_activitypub_repository_test.go +++ b/tests/integration/api_activitypub_repository_test.go @@ -59,7 +59,7 @@ func TestActivityPubMissingRepository(t *testing.T) { }) } -func TestActivityPubRepositoryInbox(t *testing.T) { +func TestActivityPubRepositoryInboxValid(t *testing.T) { setting.Federation.Enabled = true testWebRoutes = routers.NormalRoutes() defer func() { @@ -84,16 +84,42 @@ func TestActivityPubRepositoryInbox(t *testing.T) { repoInboxUrl := fmt.Sprintf("%s/api/v1/activitypub/repository-id/%v/inbox", srv.URL, repositoryID) - // valid activity request succeeds activity := []byte(fmt.Sprintf(`{"type":"Like","startTime":"2024-03-27T00:00:00Z","actor":"%s/api/v1/activitypub/user-id/2","object":"%s/api/v1/activitypub/repository-id/%v"}`, srv.URL, srv.URL, repositoryID)) resp, err := c.Post(activity, repoInboxUrl) assert.NoError(t, err) assert.Equal(t, http.StatusNoContent, resp.StatusCode) - - // invalid activity request succeeds - activity = []byte(fmt.Sprintf(`{"type":"Wrong"}`)) - resp, err = c.Post(activity, repoInboxUrl) - assert.Error(t, err) + }) +} + +func TestActivityPubRepositoryInboxInvalid(t *testing.T) { + setting.Federation.Enabled = true + testWebRoutes = routers.NormalRoutes() + defer func() { + setting.Federation.Enabled = false + testWebRoutes = routers.NormalRoutes() + }() + + srv := httptest.NewServer(testWebRoutes) + defer srv.Close() + + onGiteaRun(t, func(*testing.T, *url.URL) { + appURL := setting.AppURL + setting.AppURL = srv.URL + "/" + defer func() { + setting.Database.LogSQL = false + setting.AppURL = appURL + }() + actionsUser := user.NewActionsUser() + repositoryID := 2 + c, err := activitypub.NewClient(db.DefaultContext, actionsUser, "not used") + assert.NoError(t, err) + repoInboxUrl := fmt.Sprintf("%s/api/v1/activitypub/repository-id/%v/inbox", + srv.URL, repositoryID) + + activity := []byte(fmt.Sprintf(`{"type":"Wrong"}`)) + resp, err := c.Post(activity, repoInboxUrl) + assert.NoError(t, err) + assert.Equal(t, http.StatusNotAcceptable, resp.StatusCode) }) }