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.

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