gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "net/http"
  6. "testing"
  7. "code.gitea.io/gitea/modules/setting"
  8. api "code.gitea.io/gitea/modules/structs"
  9. "code.gitea.io/gitea/tests"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestAPIExposedSettings(t *testing.T) {
  13. defer tests.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.Equal(t, &api.GeneralAPISettings{
  25. MaxResponseItems: setting.API.MaxResponseItems,
  26. DefaultPagingNum: setting.API.DefaultPagingNum,
  27. DefaultGitTreesPerPage: setting.API.DefaultGitTreesPerPage,
  28. DefaultMaxBlobSize: setting.API.DefaultMaxBlobSize,
  29. DefaultMaxResponseSize: setting.API.DefaultMaxResponseSize,
  30. }, apiSettings)
  31. repo := new(api.GeneralRepoSettings)
  32. req = NewRequest(t, "GET", "/api/v1/settings/repository")
  33. resp = MakeRequest(t, req, http.StatusOK)
  34. DecodeJSON(t, resp, &repo)
  35. assert.Equal(t, &api.GeneralRepoSettings{
  36. MirrorsDisabled: !setting.Mirror.Enabled,
  37. HTTPGitDisabled: setting.Repository.DisableHTTPGit,
  38. MigrationsDisabled: setting.Repository.DisableMigrations,
  39. TimeTrackingDisabled: false,
  40. LFSDisabled: !setting.LFS.StartServer,
  41. }, repo)
  42. attachment := new(api.GeneralAttachmentSettings)
  43. req = NewRequest(t, "GET", "/api/v1/settings/attachment")
  44. resp = MakeRequest(t, req, http.StatusOK)
  45. DecodeJSON(t, resp, &attachment)
  46. assert.Equal(t, &api.GeneralAttachmentSettings{
  47. Enabled: setting.Attachment.Enabled,
  48. AllowedTypes: setting.Attachment.AllowedTypes,
  49. MaxFiles: setting.Attachment.MaxFiles,
  50. MaxSize: setting.Attachment.MaxSize,
  51. }, attachment)
  52. }