aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/view_home_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/web/repo/view_home_test.go')
-rw-r--r--routers/web/repo/view_home_test.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/routers/web/repo/view_home_test.go b/routers/web/repo/view_home_test.go
index 6264dba71c..dd74ae560b 100644
--- a/routers/web/repo/view_home_test.go
+++ b/routers/web/repo/view_home_test.go
@@ -9,7 +9,6 @@ import (
"code.gitea.io/gitea/models/unittest"
git_module "code.gitea.io/gitea/modules/git"
- "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/contexttest"
"github.com/stretchr/testify/assert"
@@ -19,14 +18,20 @@ func TestViewHomeSubmoduleRedirect(t *testing.T) {
unittest.PrepareTestEnv(t)
ctx, _ := contexttest.MockContext(t, "/user2/repo1/src/branch/master/test-submodule")
- submodule := &git_module.SubModule{Path: "test-submodule", URL: setting.AppURL + "user2/repo-other.git"}
+ submodule := git_module.NewCommitSubmoduleFile("/user2/repo1", "test-submodule", "../repo-other", "any-ref-id")
handleRepoViewSubmodule(ctx, submodule)
assert.Equal(t, http.StatusSeeOther, ctx.Resp.WrittenStatus())
- assert.Equal(t, "/user2/repo-other", ctx.Resp.Header().Get("Location"))
+ assert.Equal(t, "/user2/repo-other/tree/any-ref-id", ctx.Resp.Header().Get("Location"))
ctx, _ = contexttest.MockContext(t, "/user2/repo1/src/branch/master/test-submodule")
- submodule = &git_module.SubModule{Path: "test-submodule", URL: "https://other/user2/repo-other.git"}
+ submodule = git_module.NewCommitSubmoduleFile("/user2/repo1", "test-submodule", "https://other/user2/repo-other.git", "any-ref-id")
handleRepoViewSubmodule(ctx, submodule)
// do not auto-redirect for external URLs, to avoid open redirect or phishing
assert.Equal(t, http.StatusNotFound, ctx.Resp.WrittenStatus())
+
+ ctx, respWriter := contexttest.MockContext(t, "/user2/repo1/src/branch/master/test-submodule?only_content=true")
+ submodule = git_module.NewCommitSubmoduleFile("/user2/repo1", "test-submodule", "../repo-other", "any-ref-id")
+ handleRepoViewSubmodule(ctx, submodule)
+ assert.Equal(t, http.StatusOK, ctx.Resp.WrittenStatus())
+ assert.Equal(t, `<a href="/user2/repo-other/tree/any-ref-id">/user2/repo-other/tree/any-ref-id</a>`, respWriter.Body.String())
}