From 607422237719e2a4b3c0ea38884a89134655ef9d Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 11 Jun 2022 21:15:45 -0500 Subject: [PATCH] Code cleanup --- integrations/api_activitypub_person_test.go | 2 -- routers/api/v1/activitypub/reqsignature.go | 6 +++--- routers/api/v1/api.go | 6 ++++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 024e024066..0bfe6d2a95 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -32,8 +32,6 @@ func TestActivityPubPerson(t *testing.T) { resp := MakeRequest(t, req, http.StatusOK) body := resp.Body.Bytes() assert.Contains(t, string(body), "@context") - var m map[string]interface{} - DecodeJSON(t, resp, &m) var person ap.Person err := person.UnmarshalJSON(body) diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 6c4d289c48..5a15a5d5aa 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -28,7 +28,7 @@ func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p person := ap.PersonNew(ap.IRI(keyID.String())) err = person.UnmarshalJSON(b) if err != nil { - err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %T", b) + err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %v", err) return } pkey := person.PublicKey @@ -50,7 +50,7 @@ func fetch(iri *url.URL) (b []byte, err error) { req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", activitypub.ActivityStreamsContentType) req.Header("Accept-Charset", "utf-8") - req.Header("Date", fmt.Sprintf("%s GMT", time.Now().UTC().Format(time.RFC1123))) + req.Header("Date", fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.RFC1123))) resp, err := req.Response() if err != nil { return @@ -89,7 +89,7 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er } // 3. Verify the other actor's key algo := httpsig.Algorithm(setting.Federation.Algorithms[0]) - authenticated = nil == v.Verify(pKey, algo) + authenticated = v.Verify(pKey, algo) == nil return } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index e1d13cd2dd..fb1b0453e2 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -645,8 +645,10 @@ func Routes() *web.Route { if setting.Federation.Enabled { m.Get("/nodeinfo", misc.NodeInfo) m.Group("/activitypub", func() { - m.Get("/user/{username}", activitypub.Person) - m.Post("/user/{username}/inbox", activitypub.ReqSignature(), activitypub.PersonInbox) + m.Group("/user/{username}", func() { + m.Get("", activitypub.Person) + m.Post("/inbox", activitypub.ReqSignature(), activitypub.PersonInbox) + }) }) } m.Get("/signing-key.gpg", misc.SigningKey)