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.

org_project_test.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "net/http"
  6. "slices"
  7. "testing"
  8. unit_model "code.gitea.io/gitea/models/unit"
  9. "code.gitea.io/gitea/modules/test"
  10. "code.gitea.io/gitea/tests"
  11. )
  12. func TestOrgProjectAccess(t *testing.T) {
  13. defer tests.PrepareTestEnv(t)()
  14. defer test.MockVariableValue(&unit_model.DisabledRepoUnits, append(slices.Clone(unit_model.DisabledRepoUnits), unit_model.TypeProjects))()
  15. // repo project, 404
  16. req := NewRequest(t, "GET", "/user2/repo1/projects")
  17. MakeRequest(t, req, http.StatusNotFound)
  18. // user project, 200
  19. req = NewRequest(t, "GET", "/user2/-/projects")
  20. MakeRequest(t, req, http.StatusOK)
  21. // org project, 200
  22. req = NewRequest(t, "GET", "/org3/-/projects")
  23. MakeRequest(t, req, http.StatusOK)
  24. // change the org's visibility to private
  25. session := loginUser(t, "user2")
  26. req = NewRequestWithValues(t, "POST", "/org/org3/settings", map[string]string{
  27. "_csrf": GetCSRF(t, session, "/org3/-/projects"),
  28. "name": "org3",
  29. "visibility": "2",
  30. })
  31. session.MakeRequest(t, req, http.StatusSeeOther)
  32. // user4 can still access the org's project because its team(team1) has the permission
  33. session = loginUser(t, "user4")
  34. req = NewRequest(t, "GET", "/org3/-/projects")
  35. session.MakeRequest(t, req, http.StatusOK)
  36. // disable team1's project unit
  37. session = loginUser(t, "user2")
  38. req = NewRequestWithValues(t, "POST", "/org/org3/teams/team1/edit", map[string]string{
  39. "_csrf": GetCSRF(t, session, "/org3/-/projects"),
  40. "team_name": "team1",
  41. "repo_access": "specific",
  42. "permission": "read",
  43. "unit_8": "0",
  44. })
  45. session.MakeRequest(t, req, http.StatusSeeOther)
  46. // user4 can no longer access the org's project
  47. session = loginUser(t, "user4")
  48. req = NewRequest(t, "GET", "/org3/-/projects")
  49. session.MakeRequest(t, req, http.StatusNotFound)
  50. }