You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.3 KiB

  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. "testing"
  9. api "code.gitea.io/sdk/gitea"
  10. )
  11. func TestLinksNoLogin(t *testing.T) {
  12. prepareTestEnv(t)
  13. var links = []string{
  14. "/explore/repos",
  15. "/explore/repos?q=test&tab=",
  16. "/explore/users",
  17. "/explore/users?q=test&tab=",
  18. "/explore/organizations",
  19. "/explore/organizations?q=test&tab=",
  20. "/",
  21. "/user/sign_up",
  22. "/user/login",
  23. "/user/forgot_password",
  24. "/api/swagger",
  25. "/api/v1/swagger",
  26. // TODO: follow this page and test every link
  27. "/vendor/librejs.html",
  28. }
  29. for _, link := range links {
  30. req := NewRequest(t, "GET", link)
  31. MakeRequest(t, req, http.StatusOK)
  32. }
  33. }
  34. func testLinksAsUser(userName string, t *testing.T) {
  35. var links = []string{
  36. "/explore/repos",
  37. "/explore/repos?q=test&tab=",
  38. "/explore/users",
  39. "/explore/users?q=test&tab=",
  40. "/explore/organizations",
  41. "/explore/organizations?q=test&tab=",
  42. "/",
  43. "/user/forgot_password",
  44. "/api/swagger",
  45. "/api/v1/swagger",
  46. "/issues",
  47. "/issues?type=your_repositories&repo=0&sort=&state=open",
  48. "/issues?type=assigned&repo=0&sort=&state=open",
  49. "/issues?type=created_by&repo=0&sort=&state=open",
  50. "/issues?type=your_repositories&repo=0&sort=&state=closed",
  51. "/issues?type=assigned&repo=0&sort=&state=closed",
  52. "/issues?type=created_by&repo=0&sort=&state=closed",
  53. "/pulls",
  54. "/pulls?type=your_repositories&repo=0&sort=&state=open",
  55. "/pulls?type=assigned&repo=0&sort=&state=open",
  56. "/pulls?type=created_by&repo=0&sort=&state=open",
  57. "/pulls?type=your_repositories&repo=0&sort=&state=closed",
  58. "/pulls?type=assigned&repo=0&sort=&state=closed",
  59. "/pulls?type=created_by&repo=0&sort=&state=closed",
  60. "/notifications",
  61. "/repo/create",
  62. "/repo/migrate",
  63. "/org/create",
  64. "/user2",
  65. "/user2?tab=stars",
  66. "/user2?tab=activity",
  67. "/user/settings",
  68. "/user/settings/avatar",
  69. "/user/settings/security",
  70. "/user/settings/security/two_factor/enroll",
  71. "/user/settings/email",
  72. "/user/settings/keys",
  73. "/user/settings/applications",
  74. "/user/settings/account_link",
  75. "/user/settings/organization",
  76. "/user/settings/delete",
  77. }
  78. session := loginUser(t, userName)
  79. for _, link := range links {
  80. req := NewRequest(t, "GET", link)
  81. session.MakeRequest(t, req, http.StatusOK)
  82. }
  83. reqAPI := NewRequestf(t, "GET", "/api/v1/users/%s/repos", userName)
  84. respAPI := MakeRequest(t, reqAPI, http.StatusOK)
  85. var apiRepos []api.Repository
  86. DecodeJSON(t, respAPI, &apiRepos)
  87. var repoLinks = []string{
  88. "",
  89. "/issues",
  90. "/pulls",
  91. "/commits/master",
  92. "/graph",
  93. "/settings",
  94. "/settings/collaboration",
  95. "/settings/branches",
  96. "/settings/hooks",
  97. // FIXME: below links should return 200 but 404 ??
  98. //"/settings/hooks/git",
  99. //"/settings/hooks/git/pre-receive",
  100. //"/settings/hooks/git/update",
  101. //"/settings/hooks/git/post-receive",
  102. "/settings/keys",
  103. "/releases",
  104. "/releases/new",
  105. //"/wiki/_pages",
  106. "/wiki/_new",
  107. }
  108. for _, repo := range apiRepos {
  109. for _, link := range repoLinks {
  110. req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s%s", userName, repo.Name, link))
  111. session.MakeRequest(t, req, http.StatusOK)
  112. }
  113. }
  114. }
  115. func TestLinksLogin(t *testing.T) {
  116. prepareTestEnv(t)
  117. testLinksAsUser("user2", t)
  118. }