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.

112 lines
3.7 KiB

  1. // Copyright 2019 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. "net/http"
  7. "strings"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestOrgRepos(t *testing.T) {
  12. prepareTestEnv(t)
  13. var (
  14. users = []string{"user1", "user2"}
  15. cases = map[string][]string{
  16. "alphabetically": {"repo21", "repo3", "repo5"},
  17. "reversealphabetically": {"repo5", "repo3", "repo21"},
  18. }
  19. )
  20. for _, user := range users {
  21. t.Run(user, func(t *testing.T) {
  22. session := loginUser(t, user)
  23. for sortBy, repos := range cases {
  24. req := NewRequest(t, "GET", "/user3?sort="+sortBy)
  25. resp := session.MakeRequest(t, req, http.StatusOK)
  26. htmlDoc := NewHTMLParser(t, resp.Body)
  27. sel := htmlDoc.doc.Find("a.name")
  28. assert.EqualValues(t, len(repos), len(sel.Nodes))
  29. for i := 0; i < len(repos); i++ {
  30. assert.EqualValues(t, repos[i], strings.TrimSpace(sel.Eq(i).Text()))
  31. }
  32. }
  33. })
  34. }
  35. }
  36. func TestLimitedOrg(t *testing.T) {
  37. prepareTestEnv(t)
  38. // not logged in user
  39. req := NewRequest(t, "GET", "/limited_org")
  40. MakeRequest(t, req, http.StatusNotFound)
  41. req = NewRequest(t, "GET", "/limited_org/public_repo_on_limited_org")
  42. MakeRequest(t, req, http.StatusNotFound)
  43. req = NewRequest(t, "GET", "/limited_org/private_repo_on_limited_org")
  44. MakeRequest(t, req, http.StatusNotFound)
  45. // login non-org member user
  46. session := loginUser(t, "user2")
  47. req = NewRequest(t, "GET", "/limited_org")
  48. session.MakeRequest(t, req, http.StatusOK)
  49. req = NewRequest(t, "GET", "/limited_org/public_repo_on_limited_org")
  50. session.MakeRequest(t, req, http.StatusOK)
  51. req = NewRequest(t, "GET", "/limited_org/private_repo_on_limited_org")
  52. session.MakeRequest(t, req, http.StatusNotFound)
  53. // site admin
  54. session = loginUser(t, "user1")
  55. req = NewRequest(t, "GET", "/limited_org")
  56. session.MakeRequest(t, req, http.StatusOK)
  57. req = NewRequest(t, "GET", "/limited_org/public_repo_on_limited_org")
  58. session.MakeRequest(t, req, http.StatusOK)
  59. req = NewRequest(t, "GET", "/limited_org/private_repo_on_limited_org")
  60. session.MakeRequest(t, req, http.StatusOK)
  61. }
  62. func TestPrivateOrg(t *testing.T) {
  63. prepareTestEnv(t)
  64. // not logged in user
  65. req := NewRequest(t, "GET", "/privated_org")
  66. MakeRequest(t, req, http.StatusNotFound)
  67. req = NewRequest(t, "GET", "/privated_org/public_repo_on_private_org")
  68. MakeRequest(t, req, http.StatusNotFound)
  69. req = NewRequest(t, "GET", "/privated_org/private_repo_on_private_org")
  70. MakeRequest(t, req, http.StatusNotFound)
  71. // login non-org member user
  72. session := loginUser(t, "user2")
  73. req = NewRequest(t, "GET", "/privated_org")
  74. session.MakeRequest(t, req, http.StatusNotFound)
  75. req = NewRequest(t, "GET", "/privated_org/public_repo_on_private_org")
  76. session.MakeRequest(t, req, http.StatusNotFound)
  77. req = NewRequest(t, "GET", "/privated_org/private_repo_on_private_org")
  78. session.MakeRequest(t, req, http.StatusNotFound)
  79. // non-org member who is collaborator on repo in private org
  80. session = loginUser(t, "user4")
  81. req = NewRequest(t, "GET", "/privated_org")
  82. session.MakeRequest(t, req, http.StatusNotFound)
  83. req = NewRequest(t, "GET", "/privated_org/public_repo_on_private_org") // colab of this repo
  84. session.MakeRequest(t, req, http.StatusOK)
  85. req = NewRequest(t, "GET", "/privated_org/private_repo_on_private_org")
  86. session.MakeRequest(t, req, http.StatusNotFound)
  87. // site admin
  88. session = loginUser(t, "user1")
  89. req = NewRequest(t, "GET", "/privated_org")
  90. session.MakeRequest(t, req, http.StatusOK)
  91. req = NewRequest(t, "GET", "/privated_org/public_repo_on_private_org")
  92. session.MakeRequest(t, req, http.StatusOK)
  93. req = NewRequest(t, "GET", "/privated_org/private_repo_on_private_org")
  94. session.MakeRequest(t, req, http.StatusOK)
  95. }