mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-13 22:40:24 +00:00
- Make use of `test.MockVariableValue` to override variables for the duration of the test. - Don't needlessly call `onGiteaRun`, its only needed when a HTTP server needs to be called by the code. - When `onGiteaRun` is used, make use of the passed parameters, such as the passed `*testing.T` variable and `*url.URL` (this also avoids needing to serve the routers in the test code again). - Use `(*url.URL).JoinPath` to craft new URLs. - Don't override `setting.AppURL` & `setting.Database.LogSQL` when its does not affect the test. - Add empty fixture files for `FederatedUser` & `FederationHost` so they are truncated and do not persist between tests.
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/test"
|
|
"code.gitea.io/gitea/routers"
|
|
"code.gitea.io/gitea/tests"
|
|
|
|
ap "github.com/go-ap/activitypub"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestActivityPubActor(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.Federation.Enabled, true)()
|
|
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
req := NewRequest(t, "GET", "/api/v1/activitypub/actor")
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
assert.Contains(t, resp.Body.String(), "@context")
|
|
|
|
var actor ap.Actor
|
|
err := actor.UnmarshalJSON(resp.Body.Bytes())
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, ap.ApplicationType, actor.Type)
|
|
assert.Equal(t, setting.Domain, actor.PreferredUsername.String())
|
|
keyID := actor.GetID().String()
|
|
assert.Regexp(t, "activitypub/actor$", keyID)
|
|
assert.Regexp(t, "activitypub/actor/outbox$", actor.Outbox.GetID().String())
|
|
assert.Regexp(t, "activitypub/actor/inbox$", actor.Inbox.GetID().String())
|
|
|
|
pubKey := actor.PublicKey
|
|
assert.NotNil(t, pubKey)
|
|
publicKeyID := keyID + "#main-key"
|
|
assert.Equal(t, pubKey.ID.String(), publicKeyID)
|
|
|
|
pubKeyPem := pubKey.PublicKeyPem
|
|
assert.NotNil(t, pubKeyPem)
|
|
assert.Regexp(t, "^-----BEGIN PUBLIC KEY-----", pubKeyPem)
|
|
}
|