From 285e72e4e64b2e3360c52f6a99802333a75ec48d Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Mon, 29 Apr 2024 19:51:28 +0200 Subject: [PATCH] found issue during test --- .../api_activitypub_repository_test.go | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/integration/api_activitypub_repository_test.go b/tests/integration/api_activitypub_repository_test.go index f014ed08fb..748c77bef0 100644 --- a/tests/integration/api_activitypub_repository_test.go +++ b/tests/integration/api_activitypub_repository_test.go @@ -6,10 +6,14 @@ package integration import ( "fmt" "net/http" + "net/http/httptest" "net/url" "testing" + "code.gitea.io/gitea/models/db" forgefed_model "code.gitea.io/gitea/models/forgefed" + "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers" @@ -54,3 +58,42 @@ func TestActivityPubMissingRepository(t *testing.T) { assert.Contains(t, resp.Body.String(), "repository does not exist") }) } + +func TestActivityPubRepositoryInbox(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) + + // 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) + }) +}