// Copyright 2021 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package integration import ( "net/http" "net/url" "os" "path/filepath" "strings" "testing" auth_model "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git/gitcmd" "code.gitea.io/gitea/tests" "github.com/PuerkitoBio/goquery" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestRepoWikiPages(t *testing.T) { defer tests.PrepareTestEnv(t)() req := NewRequest(t, "GET", "/user2/repo1/wiki/?action=_pages") resp := MakeRequest(t, req, http.StatusOK) doc := NewHTMLParser(t, resp.Body) expectedPagePaths := []string{ "Home", "Page-With-Image", "Page-With-Spaced-Name", "Unescaped-File", } doc.Find("tr").Each(func(i int, s *goquery.Selection) { firstAnchor := s.Find("a").First() href, _ := firstAnchor.Attr("href") pagePath := strings.TrimPrefix(href, "/user2/repo1/wiki/") assert.Equal(t, expectedPagePaths[i], pagePath) }) } func testRepoWikiCloneHTTP(t *testing.T, u *url.URL) { // When proc-receive support is enabled globally, the HTTP receive-pack pre-check // must still require write access for wiki repositories. Exercise this with a // normal wiki push because the regression is about the pre-check, not agit refs. require.True(t, git.DefaultFeatures().SupportProcReceive) // modern git should all support proc-receive wikiURL := *u wikiURL.Path = "/user2/repo1.wiki.git" dstLocalPath := t.TempDir() // reader can clone wikiURL.User = url.UserPassword("user20", userPassword) require.NoError(t, git.Clone(t.Context(), wikiURL.String(), dstLocalPath, git.CloneRepoOptions{})) _, _, runErr := gitcmd.NewCommand("fast-import").WithDir(dstLocalPath).WithStdinBytes([]byte(`commit refs/heads/master committer unauthorized-user 1714310400 +0000 data <