From d6abb363f6a7efea20c503e108c77dc67ccd8ff6 Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Fri, 14 Jun 2024 15:22:37 +0000 Subject: [PATCH] FIX: use proper time format (activitypub/client) (#4132) use proper http time format than replacing with GMT in time.RFC1123 =) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4132 Reviewed-by: Earl Warren Co-authored-by: Shiny Nematoda Co-committed-by: Shiny Nematoda --- modules/activitypub/client.go | 4 +--- modules/activitypub/client_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index d47990430d..38ccc58eb5 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -31,10 +31,8 @@ const ( httpsigExpirationTime = 60 ) -// Gets the current time as an RFC 2616 formatted string -// RFC 2616 requires RFC 1123 dates but with GMT instead of UTC func CurrentTime() string { - return strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT") + return time.Now().UTC().Format(http.TimeFormat) } func containsRequiredHTTPHeaders(method string, headers []string) error { diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go index 2ef16fcdf5..7f84634941 100644 --- a/modules/activitypub/client_test.go +++ b/modules/activitypub/client_test.go @@ -11,6 +11,7 @@ import ( "net/http/httptest" "regexp" "testing" + "time" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" @@ -23,6 +24,13 @@ import ( _ "github.com/mattn/go-sqlite3" ) +func TestCurrentTime(t *testing.T) { + date := CurrentTime() + _, err := time.Parse(http.TimeFormat, date) + assert.NoError(t, err) + assert.Equal(t, date[len(date)-3:], "GMT") +} + /* ToDo: Set Up tests for http get requests Set up an expected response for GET on api with user-id = 1: