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.

76 lines
2.1 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. "code.gitea.io/gitea/modules/setting"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestViewRepo(t *testing.T) {
  13. prepareTestEnv(t)
  14. req := NewRequest(t, "GET", "/user2/repo1")
  15. MakeRequest(t, req, http.StatusOK)
  16. req = NewRequest(t, "GET", "/user3/repo3")
  17. MakeRequest(t, req, http.StatusNotFound)
  18. session := loginUser(t, "user1")
  19. session.MakeRequest(t, req, http.StatusNotFound)
  20. }
  21. func TestViewRepo2(t *testing.T) {
  22. prepareTestEnv(t)
  23. req := NewRequest(t, "GET", "/user3/repo3")
  24. session := loginUser(t, "user2")
  25. session.MakeRequest(t, req, http.StatusOK)
  26. }
  27. func TestViewRepo3(t *testing.T) {
  28. prepareTestEnv(t)
  29. req := NewRequest(t, "GET", "/user3/repo3")
  30. session := loginUser(t, "user4")
  31. session.MakeRequest(t, req, http.StatusOK)
  32. }
  33. func TestViewRepo1CloneLinkAnonymous(t *testing.T) {
  34. prepareTestEnv(t)
  35. req := NewRequest(t, "GET", "/user2/repo1")
  36. resp := MakeRequest(t, req, http.StatusOK)
  37. htmlDoc := NewHTMLParser(t, resp.Body)
  38. link, exists := htmlDoc.doc.Find("#repo-clone-https").Attr("data-link")
  39. assert.True(t, exists, "The template has changed")
  40. assert.Equal(t, setting.AppURL+"user2/repo1.git", link)
  41. _, exists = htmlDoc.doc.Find("#repo-clone-ssh").Attr("data-link")
  42. assert.False(t, exists)
  43. }
  44. func TestViewRepo1CloneLinkAuthorized(t *testing.T) {
  45. prepareTestEnv(t)
  46. session := loginUser(t, "user2")
  47. req := NewRequest(t, "GET", "/user2/repo1")
  48. resp := session.MakeRequest(t, req, http.StatusOK)
  49. htmlDoc := NewHTMLParser(t, resp.Body)
  50. link, exists := htmlDoc.doc.Find("#repo-clone-https").Attr("data-link")
  51. assert.True(t, exists, "The template has changed")
  52. assert.Equal(t, setting.AppURL+"user2/repo1.git", link)
  53. link, exists = htmlDoc.doc.Find("#repo-clone-ssh").Attr("data-link")
  54. assert.True(t, exists, "The template has changed")
  55. sshURL := fmt.Sprintf("ssh://%s@%s:%d/user2/repo1.git", setting.RunUser, setting.SSH.Domain, setting.SSH.Port)
  56. assert.Equal(t, sshURL, link)
  57. }