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.

camo_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package markup
  4. import (
  5. "testing"
  6. "code.gitea.io/gitea/modules/setting"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestCamoHandleLink(t *testing.T) {
  10. setting.AppURL = "https://gitea.com"
  11. // Test media proxy
  12. setting.Camo.Enabled = true
  13. setting.Camo.ServerURL = "https://image.proxy"
  14. setting.Camo.HMACKey = "geheim"
  15. assert.Equal(t,
  16. "https://gitea.com/img.jpg",
  17. camoHandleLink("https://gitea.com/img.jpg"))
  18. assert.Equal(t,
  19. "https://testimages.org/img.jpg",
  20. camoHandleLink("https://testimages.org/img.jpg"))
  21. assert.Equal(t,
  22. "https://image.proxy/eivin43gJwGVIjR9MiYYtFIk0mw/aHR0cDovL3Rlc3RpbWFnZXMub3JnL2ltZy5qcGc",
  23. camoHandleLink("http://testimages.org/img.jpg"))
  24. setting.Camo.Allways = true
  25. assert.Equal(t,
  26. "https://gitea.com/img.jpg",
  27. camoHandleLink("https://gitea.com/img.jpg"))
  28. assert.Equal(t,
  29. "https://image.proxy/tkdlvmqpbIr7SjONfHNgEU622y0/aHR0cHM6Ly90ZXN0aW1hZ2VzLm9yZy9pbWcuanBn",
  30. camoHandleLink("https://testimages.org/img.jpg"))
  31. assert.Equal(t,
  32. "https://image.proxy/eivin43gJwGVIjR9MiYYtFIk0mw/aHR0cDovL3Rlc3RpbWFnZXMub3JnL2ltZy5qcGc",
  33. camoHandleLink("http://testimages.org/img.jpg"))
  34. // Restore previous settings
  35. setting.Camo.Enabled = false
  36. }