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.

deliver_test.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2019 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 webhook
  5. import (
  6. "net/http"
  7. "net/url"
  8. "testing"
  9. "code.gitea.io/gitea/modules/setting"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestWebhookProxy(t *testing.T) {
  13. setting.Webhook.ProxyURL = "http://localhost:8080"
  14. setting.Webhook.ProxyURLFixed, _ = url.Parse(setting.Webhook.ProxyURL)
  15. setting.Webhook.ProxyHosts = []string{"*.discordapp.com", "discordapp.com"}
  16. var kases = map[string]string{
  17. "https://discordapp.com/api/webhooks/xxxxxxxxx/xxxxxxxxxxxxxxxxxxx": "http://localhost:8080",
  18. "http://s.discordapp.com/assets/xxxxxx": "http://localhost:8080",
  19. "http://github.com/a/b": "",
  20. }
  21. for reqURL, proxyURL := range kases {
  22. req, err := http.NewRequest("POST", reqURL, nil)
  23. assert.NoError(t, err)
  24. u, err := webhookProxy()(req)
  25. assert.NoError(t, err)
  26. if proxyURL == "" {
  27. assert.Nil(t, u)
  28. } else {
  29. assert.EqualValues(t, proxyURL, u.String())
  30. }
  31. }
  32. }