1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-10-05 19:30:58 +00:00
forgejo/services/federation/repo_like.go

147 lines
4.7 KiB
Go
Raw Normal View History

// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package federation
import (
"context"
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
"errors"
"fmt"
"net/http"
"time"
"forgejo.org/models/forgefed"
"forgejo.org/models/repo"
"forgejo.org/models/user"
"forgejo.org/modules/activitypub"
fm "forgejo.org/modules/forgefed"
"forgejo.org/modules/log"
"forgejo.org/modules/validation"
context_service "forgejo.org/services/context"
)
// ProcessLikeActivity receives a ForgeLike activity and does the following:
// Validation of the activity
// Creation of a (remote) federationHost if not existing
// Creation of a forgefed Person if not existing
// Validation of incoming RepositoryID against Local RepositoryID
// Star the repo if it wasn't already stared
// Do some mitigation against out of order attacks
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
func ProcessLikeActivity(ctx *context_service.APIContext, form any, repositoryID int64) (int, string, error) {
activity := form.(*fm.ForgeLike)
if res, err := validation.IsValid(activity); !res {
return http.StatusNotAcceptable, "Invalid activity", err
}
log.Trace("Activity validated: %#v", activity)
// parse actorID (person)
actorURI := activity.Actor.GetID().String()
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
user, _, federationHost, err := FindOrCreateFederatedUser(ctx.Base, actorURI)
if err != nil {
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
ctx.Error(http.StatusNotAcceptable, "Federated user not found", err)
return http.StatusInternalServerError, "FindOrCreateFederatedUser", err
}
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
if !activity.IsNewer(federationHost.LatestActivity) {
return http.StatusNotAcceptable, "Activity out of order.", errors.New("Activity already processed")
}
// parse objectID (repository)
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
objectID, err := fm.NewRepositoryID(activity.Object.GetID().String(), string(forgefed.ForgejoSourceType))
if err != nil {
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
return http.StatusNotAcceptable, "Invalid objectId", err
}
if objectID.ID != fmt.Sprint(repositoryID) {
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
return http.StatusNotAcceptable, "Invalid objectId", err
}
log.Trace("Object accepted: %#v", objectID)
// execute the activity if the repo was not stared already
alreadyStared := repo.IsStaring(ctx, user.ID, repositoryID)
if !alreadyStared {
err = repo.StarRepo(ctx, user.ID, repositoryID, true)
if err != nil {
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
return http.StatusNotAcceptable, "Error staring", err
}
}
federationHost.LatestActivity = activity.StartTime
err = forgefed.UpdateFederationHost(ctx, federationHost)
if err != nil {
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
return http.StatusNotAcceptable, "Error updating federatedHost", err
}
Revert "fix: assorted ActivityPub code only refactors (#8274)" (#8705) This reverts commit e271c24100c8974e135ebc1d1b3eaa6cd2062b10. It was an experiment to verify that adding a delay to the test make a difference. But it does not so... reverting. @jerger before engaging in a refactor, it is necessary to get to the bottom of this: - Find the root cause of those failures - Fix it in a minimal way Refs https://codeberg.org/forgejo/forgejo/pulls/8274#issuecomment-5987215 --- - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/9 - https://codeberg.org/forgejo/forgejo/actions/runs/92182/jobs/10 ``` --- FAIL: TestFederationHttpSigValidation (11.34s) testlogger.go:411: 2025/07/28 00:23:46 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/forgejo/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/07/28 00:23:52 ...ypub/reqsignature.go:76:func1() [W] verifyHttpSignatures failed: neither "Signature" nor "Authorization" have signature parameters testlogger.go:411: 2025/07/28 00:23:52 ...eb/routing/logger.go:102:func1() [I] router: completed GET http://127.0.0.1:3002/api/v1/activitypub/user-id/2 for test-mock:12345, 400 Bad Request in 5.3ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) testlogger.go:411: 2025/07/28 00:23:52 ...ces/auth/httpsign.go:70:Verify() [W] Failed authentication attempt from 127.0.0.1:43244 testlogger.go:411: 2025/07/28 00:23:55 ...eb/routing/logger.go:68:func1() [W] router: slow GET /api/v1/activitypub/user-id/2 for 127.0.0.1:43244, elapsed 3684.7ms @ activitypub/reqsignature.go:74(activitypub.ReqHTTPUserOrInstanceSignature) --- FAIL: TestFederationHttpSigValidation/SignedRequest (5.01s) api_federation_httpsig_test.go:50: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:50 Error: Received unexpected error: Get "http://127.0.0.1:3002/api/v1/activitypub/user-id/2": context deadline exceeded (Client.Timeout exceeded while awaiting headers) Test: TestFederationHttpSigValidation/SignedRequest --- FAIL: TestFederationHttpSigValidation/ValidateCaches (0.00s) api_federation_httpsig_test.go:64: Error Trace: /workspace/forgejo/forgejo/tests/integration/api_federation_httpsig_test.go:64 Error: Expected value not to be nil. Test: TestFederationHttpSigValidation/ValidateCaches test_utils.go:247: PrepareTestEnv:Process "GET: /api/v1/activitypub/user-id/2" cancelled panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4cc464a] ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8705 Reviewed-by: jerger <jerger@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 10:55:04 +02:00
return 0, "", nil
}
// Create or update a list of FollowingRepo structs
func StoreFollowingRepoList(ctx *context_service.Context, localRepoID int64, followingRepoList []string) (int, string, error) {
followingRepos := make([]*repo.FollowingRepo, 0, len(followingRepoList))
for _, uri := range followingRepoList {
federationHost, err := FindOrCreateFederationHost(ctx.Base, uri)
if err != nil {
return http.StatusInternalServerError, "Wrong FederationHost", err
}
followingRepoID, err := fm.NewRepositoryID(uri, string(federationHost.NodeInfo.SoftwareName))
if err != nil {
return http.StatusNotAcceptable, "Invalid federated repo", err
}
followingRepo, err := repo.NewFollowingRepo(localRepoID, followingRepoID.ID, federationHost.ID, uri)
if err != nil {
return http.StatusNotAcceptable, "Invalid federated repo", err
}
followingRepos = append(followingRepos, &followingRepo)
}
if err := repo.StoreFollowingRepos(ctx, localRepoID, followingRepos); err != nil {
return 0, "", err
}
return 0, "", nil
}
func DeleteFollowingRepos(ctx context.Context, localRepoID int64) error {
return repo.StoreFollowingRepos(ctx, localRepoID, []*repo.FollowingRepo{})
}
func SendLikeActivities(ctx context.Context, doer user.User, repoID int64) error {
followingRepos, err := repo.FindFollowingReposByRepoID(ctx, repoID)
log.Trace("Federated Repos is: %#v", followingRepos)
if err != nil {
return err
}
likeActivityList := make([]fm.ForgeLike, 0)
for _, followingRepo := range followingRepos {
log.Trace("Found following repo: %#v", followingRepo)
target := followingRepo.URI
likeActivity, err := fm.NewForgeLike(doer.APActorID(), target, time.Now())
if err != nil {
return err
}
likeActivityList = append(likeActivityList, likeActivity)
}
apclientFactory, err := activitypub.GetClientFactory(ctx)
if err != nil {
return err
}
apclient, err := apclientFactory.WithKeys(ctx, &doer, doer.APActorID()+"#main-key")
if err != nil {
return err
}
for i, activity := range likeActivityList {
activity.StartTime = activity.StartTime.Add(time.Duration(i) * time.Second)
json, err := activity.MarshalJSON()
if err != nil {
return err
}
_, err = apclient.Post(json, fmt.Sprintf("%v/inbox", activity.Object))
if err != nil {
log.Error("error %v while sending activity: %#v", err, activity)
}
}
return nil
}