diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 62d2d18621..4a1d1785eb 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -778,7 +778,6 @@ func Routes() *web.Route { m.Group("/repository-id/{repository-id}", func() { m.Get("", activitypub.Repository) m.Post("/inbox", - // TODO: bind ativities here bind(forgefed.ForgeLike{}), // TODO: activitypub.ReqHTTPSignature(), activitypub.RepositoryInbox) diff --git a/routers/utils/utils.go b/routers/utils/utils.go index 7fddb5a498..3035073d5c 100644 --- a/routers/utils/utils.go +++ b/routers/utils/utils.go @@ -1,5 +1,4 @@ -// Copyright 2024 The Forgejo Authors. All rights reserved. -// Copyright 2017, 2023 The Gitea Authors. All rights reserved. +// Copyright 2017 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package utils diff --git a/services/context/repository.go b/services/context/repository.go index d69a5f317d..422ac3f58d 100644 --- a/services/context/repository.go +++ b/services/context/repository.go @@ -1,4 +1,4 @@ -// Copyright 2023 The Forgejo Authors. All rights reserved. +// Copyright 2023, 2024 The Forgejo Authors. All rights reserved. // SPDX-License-Identifier: MIT package context @@ -12,14 +12,13 @@ import ( // RepositoryIDAssignmentAPI returns a middleware to handle context-repo assignment for api routes func RepositoryIDAssignmentAPI() func(ctx *APIContext) { return func(ctx *APIContext) { - // TODO: enough validation for security? repositoryID := ctx.ParamsInt64(":repository-id") var err error repository := new(Repository) repository.Repository, err = repo_model.GetRepositoryByID(ctx, repositoryID) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err) + ctx.Error(http.StatusNotFound, "GetRepositoryByID", err) } ctx.Repo = repository } diff --git a/tests/integration/api_activitypub_repository_test.go b/tests/integration/api_activitypub_repository_test.go index 312ff135b8..f014ed08fb 100644 --- a/tests/integration/api_activitypub_repository_test.go +++ b/tests/integration/api_activitypub_repository_test.go @@ -35,7 +35,22 @@ func TestActivityPubRepository(t *testing.T) { err := repository.UnmarshalJSON(body) assert.NoError(t, err) - assert.Equal(t, "", repository.Name) - assert.Equal(t, fmt.Sprintf("activitypub/repository-id/%v$", repository.GetID().String()), repository.ID) + assert.Regexp(t, fmt.Sprintf("activitypub/repository-id/%v$", repositoryID), repository.GetID().String()) + }) +} + +func TestActivityPubMissingRepository(t *testing.T) { + setting.Federation.Enabled = true + testWebRoutes = routers.NormalRoutes() + defer func() { + setting.Federation.Enabled = false + testWebRoutes = routers.NormalRoutes() + }() + + onGiteaRun(t, func(*testing.T, *url.URL) { + repositoryID := 9999999 + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/activitypub/repository-id/%v", repositoryID)) + resp := MakeRequest(t, req, http.StatusNotFound) + assert.Contains(t, resp.Body.String(), "repository does not exist") }) }