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.

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package httplib
  4. import (
  5. "testing"
  6. "code.gitea.io/gitea/modules/setting"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestIsRiskyRedirectURL(t *testing.T) {
  10. setting.AppURL = "http://localhost:3000/"
  11. tests := []struct {
  12. input string
  13. want bool
  14. }{
  15. {"", false},
  16. {"foo", false},
  17. {"/", false},
  18. {"/foo?k=%20#abc", false},
  19. {"//", true},
  20. {"\\\\", true},
  21. {"/\\", true},
  22. {"\\/", true},
  23. {"mail:a@b.com", true},
  24. {"https://test.com", true},
  25. {setting.AppURL + "/foo", false},
  26. }
  27. for _, tt := range tests {
  28. t.Run(tt.input, func(t *testing.T) {
  29. assert.Equal(t, tt.want, IsRiskyRedirectURL(tt.input))
  30. })
  31. }
  32. }