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.4KB

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