mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-14 23:10:25 +00:00
This is hopefully the final part of PR #4767, rebased and squashed. More thorough federation tests are at https://code.forgejo.org/forgejo/end-to-end/pulls/1276 but the mock has been extended to hopefully cover a good chunk as well. Co-authored-by: Gergely Nagy <forgejo@gergo.csillger.hu> Co-authored-by: Michael Jerger <michael.jerger@meissa-gmbh.de> Co-authored-by: zam <mirco.zachmann@meissa.de> Co-authored-by: Panagiotis "Ivory" Vasilopoulos <git@n0toose.net> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10380 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: famfo <famfo@famfo.xyz> Co-committed-by: famfo <famfo@famfo.xyz>
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
// Copyright 2026 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"forgejo.org/modules/setting"
|
|
"forgejo.org/modules/test"
|
|
"forgejo.org/routers"
|
|
"forgejo.org/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"golang.org/x/net/html"
|
|
)
|
|
|
|
func getLinks(t *testing.T, url string) []*html.Node {
|
|
req := NewRequest(t, "GET", url)
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
links := htmlDoc.doc.Find("link[type=\"application/activity+json\"]").Nodes
|
|
|
|
return links
|
|
}
|
|
|
|
func TestFederationBaseHead(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
|
|
|
t.Run("Federation disabled", func(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.Federation.Enabled, false)()
|
|
|
|
links := getLinks(t, "/user1")
|
|
assert.Empty(t, links)
|
|
})
|
|
|
|
t.Run("Federation enabled", func(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.Federation.Enabled, true)()
|
|
|
|
links := getLinks(t, "/user1")
|
|
assert.Len(t, links, 1)
|
|
})
|
|
|
|
t.Run("Organization", func(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.Federation.Enabled, true)()
|
|
|
|
links := getLinks(t, "/org3")
|
|
assert.Empty(t, links)
|
|
})
|
|
}
|