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.

61 lines
1.9 KiB

  1. // Copyright 2020 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. "testing"
  8. "code.gitea.io/gitea/modules/setting"
  9. api "code.gitea.io/gitea/modules/structs"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestAPIExposedSettings(t *testing.T) {
  13. defer prepareTestEnv(t)()
  14. ui := new(api.GeneralUISettings)
  15. req := NewRequest(t, "GET", "/api/v1/settings/ui")
  16. resp := MakeRequest(t, req, http.StatusOK)
  17. DecodeJSON(t, resp, &ui)
  18. assert.Len(t, ui.AllowedReactions, len(setting.UI.Reactions))
  19. assert.ElementsMatch(t, setting.UI.Reactions, ui.AllowedReactions)
  20. apiSettings := new(api.GeneralAPISettings)
  21. req = NewRequest(t, "GET", "/api/v1/settings/api")
  22. resp = MakeRequest(t, req, http.StatusOK)
  23. DecodeJSON(t, resp, &apiSettings)
  24. assert.EqualValues(t, &api.GeneralAPISettings{
  25. MaxResponseItems: setting.API.MaxResponseItems,
  26. DefaultPagingNum: setting.API.DefaultPagingNum,
  27. DefaultGitTreesPerPage: setting.API.DefaultGitTreesPerPage,
  28. DefaultMaxBlobSize: setting.API.DefaultMaxBlobSize,
  29. }, apiSettings)
  30. repo := new(api.GeneralRepoSettings)
  31. req = NewRequest(t, "GET", "/api/v1/settings/repository")
  32. resp = MakeRequest(t, req, http.StatusOK)
  33. DecodeJSON(t, resp, &repo)
  34. assert.EqualValues(t, &api.GeneralRepoSettings{
  35. MirrorsDisabled: setting.Repository.DisableMirrors,
  36. HTTPGitDisabled: setting.Repository.DisableHTTPGit,
  37. }, repo)
  38. attachment := new(api.GeneralAttachmentSettings)
  39. req = NewRequest(t, "GET", "/api/v1/settings/attachment")
  40. resp = MakeRequest(t, req, http.StatusOK)
  41. DecodeJSON(t, resp, &attachment)
  42. assert.EqualValues(t, &api.GeneralAttachmentSettings{
  43. Enabled: setting.Attachment.Enabled,
  44. AllowedTypes: setting.Attachment.AllowedTypes,
  45. MaxFiles: setting.Attachment.MaxFiles,
  46. MaxSize: setting.Attachment.MaxSize,
  47. }, attachment)
  48. }