dpcore_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package dpcore_test
  2. import (
  3. "testing"
  4. "imuslab.com/zoraxy/mod/dynamicproxy/dpcore"
  5. )
  6. func TestReplaceLocationHost(t *testing.T) {
  7. urlString := "http://private.com/test/newtarget/"
  8. rrr := &dpcore.ResponseRewriteRuleSet{
  9. OriginalHost: "test.example.com",
  10. ProxyDomain: "private.com/test",
  11. UseTLS: true,
  12. }
  13. useTLS := true
  14. expectedResult := "https://test.example.com/newtarget/"
  15. result, err := dpcore.ReplaceLocationHost(urlString, rrr, useTLS)
  16. if err != nil {
  17. t.Errorf("Error occurred: %v", err)
  18. }
  19. if result != expectedResult {
  20. t.Errorf("Expected: %s, but got: %s", expectedResult, result)
  21. }
  22. }
  23. func TestReplaceLocationHostRelative(t *testing.T) {
  24. urlString := "api/"
  25. rrr := &dpcore.ResponseRewriteRuleSet{
  26. OriginalHost: "test.example.com",
  27. ProxyDomain: "private.com/test",
  28. UseTLS: true,
  29. }
  30. useTLS := true
  31. expectedResult := "https://test.example.com/api/"
  32. result, err := dpcore.ReplaceLocationHost(urlString, rrr, useTLS)
  33. if err != nil {
  34. t.Errorf("Error occurred: %v", err)
  35. }
  36. if result != expectedResult {
  37. t.Errorf("Expected: %s, but got: %s", expectedResult, result)
  38. }
  39. }