Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

links_test.go 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "fmt"
  7. "net/http"
  8. "path"
  9. "testing"
  10. "code.gitea.io/gitea/modules/setting"
  11. api "code.gitea.io/sdk/gitea"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestLinksNoLogin(t *testing.T) {
  15. prepareTestEnv(t)
  16. var links = []string{
  17. "/explore/repos",
  18. "/explore/repos?q=test&tab=",
  19. "/explore/users",
  20. "/explore/users?q=test&tab=",
  21. "/explore/organizations",
  22. "/explore/organizations?q=test&tab=",
  23. "/",
  24. "/user/sign_up",
  25. "/user/login",
  26. "/user/forgot_password",
  27. "/api/swagger",
  28. "/api/v1/swagger",
  29. // TODO: follow this page and test every link
  30. "/vendor/librejs.html",
  31. }
  32. for _, link := range links {
  33. req := NewRequest(t, "GET", link)
  34. MakeRequest(t, req, http.StatusOK)
  35. }
  36. }
  37. func TestRedirectsNoLogin(t *testing.T) {
  38. prepareTestEnv(t)
  39. var redirects = map[string]string{
  40. "/user2/repo1/commits/master": "/user2/repo1/commits/branch/master",
  41. "/user2/repo1/src/master": "/user2/repo1/src/branch/master",
  42. }
  43. for link, redirectLink := range redirects {
  44. req := NewRequest(t, "GET", link)
  45. resp := MakeRequest(t, req, http.StatusFound)
  46. assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), RedirectURL(t, resp))
  47. }
  48. }
  49. func testLinksAsUser(userName string, t *testing.T) {
  50. var links = []string{
  51. "/explore/repos",
  52. "/explore/repos?q=test&tab=",
  53. "/explore/users",
  54. "/explore/users?q=test&tab=",
  55. "/explore/organizations",
  56. "/explore/organizations?q=test&tab=",
  57. "/",
  58. "/user/forgot_password",
  59. "/api/swagger",
  60. "/api/v1/swagger",
  61. "/issues",
  62. "/issues?type=your_repositories&repo=0&sort=&state=open",
  63. "/issues?type=assigned&repo=0&sort=&state=open",
  64. "/issues?type=created_by&repo=0&sort=&state=open",
  65. "/issues?type=your_repositories&repo=0&sort=&state=closed",
  66. "/issues?type=assigned&repo=0&sort=&state=closed",
  67. "/issues?type=created_by&repo=0&sort=&state=closed",
  68. "/pulls",
  69. "/pulls?type=your_repositories&repo=0&sort=&state=open",
  70. "/pulls?type=assigned&repo=0&sort=&state=open",
  71. "/pulls?type=created_by&repo=0&sort=&state=open",
  72. "/pulls?type=your_repositories&repo=0&sort=&state=closed",
  73. "/pulls?type=assigned&repo=0&sort=&state=closed",
  74. "/pulls?type=created_by&repo=0&sort=&state=closed",
  75. "/notifications",
  76. "/repo/create",
  77. "/repo/migrate",
  78. "/org/create",
  79. "/user2",
  80. "/user2?tab=stars",
  81. "/user2?tab=activity",
  82. "/user/settings",
  83. "/user/settings/avatar",
  84. "/user/settings/security",
  85. "/user/settings/security/two_factor/enroll",
  86. "/user/settings/email",
  87. "/user/settings/keys",
  88. "/user/settings/applications",
  89. "/user/settings/account_link",
  90. "/user/settings/organization",
  91. "/user/settings/delete",
  92. }
  93. session := loginUser(t, userName)
  94. for _, link := range links {
  95. req := NewRequest(t, "GET", link)
  96. session.MakeRequest(t, req, http.StatusOK)
  97. }
  98. reqAPI := NewRequestf(t, "GET", "/api/v1/users/%s/repos", userName)
  99. respAPI := MakeRequest(t, reqAPI, http.StatusOK)
  100. var apiRepos []api.Repository
  101. DecodeJSON(t, respAPI, &apiRepos)
  102. var repoLinks = []string{
  103. "",
  104. "/issues",
  105. "/pulls",
  106. "/commits/branch/master",
  107. "/graph",
  108. "/settings",
  109. "/settings/collaboration",
  110. "/settings/branches",
  111. "/settings/hooks",
  112. // FIXME: below links should return 200 but 404 ??
  113. //"/settings/hooks/git",
  114. //"/settings/hooks/git/pre-receive",
  115. //"/settings/hooks/git/update",
  116. //"/settings/hooks/git/post-receive",
  117. "/settings/keys",
  118. "/releases",
  119. "/releases/new",
  120. //"/wiki/_pages",
  121. "/wiki/_new",
  122. }
  123. for _, repo := range apiRepos {
  124. for _, link := range repoLinks {
  125. req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s%s", userName, repo.Name, link))
  126. session.MakeRequest(t, req, http.StatusOK)
  127. }
  128. }
  129. }
  130. func TestLinksLogin(t *testing.T) {
  131. prepareTestEnv(t)
  132. testLinksAsUser("user2", t)
  133. }