From 1b35bd2911faf3cb2a5ccad599db90d4dcd2e945 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sun, 14 Jan 2024 13:03:51 +0100 Subject: [PATCH] lint fix --- models/forgefed/actor_test.go | 2 +- models/forgefed/nodeinfo_test.go | 8 ++++---- modules/activitypub/client.go | 2 +- routers/api/v1/activitypub/repository.go | 5 +++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/models/forgefed/actor_test.go b/models/forgefed/actor_test.go index 3b73a6e6b8..0b34b816a9 100644 --- a/models/forgefed/actor_test.go +++ b/models/forgefed/actor_test.go @@ -166,7 +166,7 @@ func Test_PersonMarshalJSON(t *testing.T) { sut.PreferredUsername = ap.NaturalLanguageValuesNew() sut.PreferredUsername.Set("en", ap.Content("MaxMuster")) result, _ := sut.MarshalJSON() - if "{\"type\":\"Person\",\"preferredUsername\":\"MaxMuster\"}" != string(result) { + if string(result) != "{\"type\":\"Person\",\"preferredUsername\":\"MaxMuster\"}" { t.Errorf("MarshalJSON() was = %q", result) } } diff --git a/models/forgefed/nodeinfo_test.go b/models/forgefed/nodeinfo_test.go index 09e8f3fbae..be31ace1cc 100644 --- a/models/forgefed/nodeinfo_test.go +++ b/models/forgefed/nodeinfo_test.go @@ -63,26 +63,26 @@ func Test_NodeInfoWellKnownValidate(t *testing.T) { } func Test_NewNodeInfoWellKnown(t *testing.T) { - sut, err := NewNodeInfoWellKnown([]byte(`{"links":[{"href":"https://federated-repo.prod.meissa.de/api/v1/nodeinfo","rel":"http://nodeinfo.diaspora.software/ns/schema/2.1"}]}`)) + sut, _ := NewNodeInfoWellKnown([]byte(`{"links":[{"href":"https://federated-repo.prod.meissa.de/api/v1/nodeinfo","rel":"http://nodeinfo.diaspora.software/ns/schema/2.1"}]}`)) expected := NodeInfoWellKnown{Href: "https://federated-repo.prod.meissa.de/api/v1/nodeinfo"} if sut != expected { t.Errorf("expected was: %v but was: %v", expected, sut) } - sut, err = NewNodeInfoWellKnown([]byte(`invalid`)) + _, err := NewNodeInfoWellKnown([]byte(`invalid`)) if err == nil { t.Errorf("error was expected here") } } func Test_NewNodeInfo(t *testing.T) { - sut, err := NewNodeInfo([]byte(`{"version":"2.1","software":{"name":"gitea","version":"1.20.0+dev-2539-g5840cc6d3","repository":"https://github.com/go-gitea/gitea.git","homepage":"https://gitea.io/"},"protocols":["activitypub"],"services":{"inbound":[],"outbound":["rss2.0"]},"openRegistrations":true,"usage":{"users":{"total":13,"activeHalfyear":1,"activeMonth":1}},"metadata":{}}`)) + sut, _ := NewNodeInfo([]byte(`{"version":"2.1","software":{"name":"gitea","version":"1.20.0+dev-2539-g5840cc6d3","repository":"https://github.com/go-gitea/gitea.git","homepage":"https://gitea.io/"},"protocols":["activitypub"],"services":{"inbound":[],"outbound":["rss2.0"]},"openRegistrations":true,"usage":{"users":{"total":13,"activeHalfyear":1,"activeMonth":1}},"metadata":{}}`)) expected := NodeInfo{Source: "gitea"} if sut != expected { t.Errorf("expected was: %v but was: %v", expected, sut) } - sut, err = NewNodeInfo([]byte(`invalid`)) + _, err := NewNodeInfo([]byte(`invalid`)) if err == nil { t.Errorf("error was expected here") } diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index df9c72fe5f..23475ab065 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -87,7 +87,7 @@ func NewClient(ctx context.Context, user *user_model.User, pubID string) (c *Cli Transport: &http.Transport{ Proxy: proxy.Proxy(), }, - Timeout: time.Duration(5 * time.Second), + Timeout: 5 * time.Second, }, algs: setting.HttpsigAlgs, digestAlg: httpsig.DigestAlgorithm(setting.Federation.DigestAlgorithm), diff --git a/routers/api/v1/activitypub/repository.go b/routers/api/v1/activitypub/repository.go index ee5b398a8f..0935f4bec4 100644 --- a/routers/api/v1/activitypub/repository.go +++ b/routers/api/v1/activitypub/repository.go @@ -91,6 +91,11 @@ func RepositoryInbox(ctx *context.APIContext) { // parse actorID (person) actorURI := activity.Actor.GetID().String() rawActorID, err := forgefed.NewActorID(actorURI) + if err != nil { + ctx.Error(http.StatusInternalServerError, + "RepositoryInbox: Validating ActorID", err) + return + } federationInfo, err := forgefed.FindFederationInfoByHostFqdn(ctx, rawActorID.Host) if err != nil { ctx.Error(http.StatusInternalServerError,