|
@@ -11,6 +11,7 @@ import (
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/langgenius/dify-plugin-daemon/internal/utils/network"
|
|
|
+ "github.com/langgenius/dify-plugin-daemon/pkg/entities/endpoint_entities"
|
|
|
)
|
|
|
|
|
|
type SimulationCheckServer struct {
|
|
@@ -180,3 +181,41 @@ func TestRedirectTraffic(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestRedirectTrafficWithQueryParams(t *testing.T) {
|
|
|
+ request, err := http.NewRequest("GET", "http://localhost:8080/plugin/invoke/tool?a=1&b=2", nil)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ request.Header.Set(endpoint_entities.HeaderXOriginalHost, "localhost:8080")
|
|
|
+
|
|
|
+ ip := address{
|
|
|
+ Ip: "127.0.0.1",
|
|
|
+ Port: 8080,
|
|
|
+ }
|
|
|
+
|
|
|
+ redirectedRequest := constructRedirectUrl(ip, request)
|
|
|
+ if redirectedRequest != "http://127.0.0.1:8080/plugin/invoke/tool?a=1&b=2" {
|
|
|
+ t.Fatal("redirected request is not correct")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestRedirectTrafficWithOutQueryParams(t *testing.T) {
|
|
|
+ request, err := http.NewRequest("GET", "http://localhost:8080/plugin/invoke/tool", nil)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ request.Header.Set(endpoint_entities.HeaderXOriginalHost, "localhost:8080")
|
|
|
+
|
|
|
+ ip := address{
|
|
|
+ Ip: "127.0.0.1",
|
|
|
+ Port: 8080,
|
|
|
+ }
|
|
|
+
|
|
|
+ redirectedRequest := constructRedirectUrl(ip, request)
|
|
|
+ if redirectedRequest != "http://127.0.0.1:8080/plugin/invoke/tool" {
|
|
|
+ t.Fatal("redirected request is not correct")
|
|
|
+ }
|
|
|
+}
|