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.

git_smart_http_test.go 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2021 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. "io"
  7. "net/http"
  8. "net/url"
  9. "testing"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestGitSmartHTTP(t *testing.T) {
  13. onGiteaRun(t, testGitSmartHTTP)
  14. }
  15. func testGitSmartHTTP(t *testing.T, u *url.URL) {
  16. kases := []struct {
  17. p string
  18. code int
  19. }{
  20. {
  21. p: "user2/repo1/info/refs",
  22. code: http.StatusOK,
  23. },
  24. {
  25. p: "user2/repo1/HEAD",
  26. code: http.StatusOK,
  27. },
  28. {
  29. p: "user2/repo1/objects/info/alternates",
  30. code: http.StatusNotFound,
  31. },
  32. {
  33. p: "user2/repo1/objects/info/http-alternates",
  34. code: http.StatusNotFound,
  35. },
  36. {
  37. p: "user2/repo1/../../custom/conf/app.ini",
  38. code: http.StatusNotFound,
  39. },
  40. {
  41. p: "user2/repo1/objects/info/../../../../custom/conf/app.ini",
  42. code: http.StatusNotFound,
  43. },
  44. {
  45. p: `user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini`,
  46. code: http.StatusBadRequest,
  47. },
  48. }
  49. for _, kase := range kases {
  50. t.Run(kase.p, func(t *testing.T) {
  51. p := u.String() + kase.p
  52. req, err := http.NewRequest("GET", p, nil)
  53. assert.NoError(t, err)
  54. req.SetBasicAuth("user2", userPassword)
  55. resp, err := http.DefaultClient.Do(req)
  56. assert.NoError(t, err)
  57. defer resp.Body.Close()
  58. assert.EqualValues(t, kase.code, resp.StatusCode)
  59. _, err = io.ReadAll(resp.Body)
  60. assert.NoError(t, err)
  61. })
  62. }
  63. }