diff --git a/tests/conf/auto_test_frpc.ini b/tests/conf/auto_test_frpc.ini index 231f4d94..777f8dea 100644 --- a/tests/conf/auto_test_frpc.ini +++ b/tests/conf/auto_test_frpc.ini @@ -103,6 +103,18 @@ use_compression = true http_user = test http_user = test +[subhost01] +type = http +local_ip = 127.0.0.1 +local_port = 10704 +subdomain = test01 + +[subhost02] +type = http +local_ip = 127.0.0.1 +local_port = 10704 +subdomain = test02 + [tcp_port_not_allowed] type = tcp local_ip = 127.0.0.1 diff --git a/tests/conf/auto_test_frps.ini b/tests/conf/auto_test_frps.ini index 1bc3a82e..229ffa84 100644 --- a/tests/conf/auto_test_frps.ini +++ b/tests/conf/auto_test_frps.ini @@ -6,3 +6,4 @@ log_file = ./frps.log log_level = debug privilege_token = 123456 privilege_allow_ports = 10000-20000,20002,30000-40000 +subdomain_host = sub.com diff --git a/tests/func_test.go b/tests/func_test.go index 39494b3b..0d106856 100644 --- a/tests/func_test.go +++ b/tests/func_test.go @@ -171,6 +171,20 @@ func TestHttp(t *testing.T) { if assert.NoError(err) { assert.Equal(401, code) } + + // subhost01 + code, body, err = sendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", TEST_HTTP_FRP_PORT), "test01.sub.com", nil) + if assert.NoError(err) { + assert.Equal(200, code) + assert.Equal("test01.sub.com", body) + } + + // subhost02 + code, body, err = sendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", TEST_HTTP_FRP_PORT), "test02.sub.com", nil) + if assert.NoError(err) { + assert.Equal(200, code) + assert.Equal("test02.sub.com", body) + } } func TestPrivilegeAllowPorts(t *testing.T) { diff --git a/tests/http_server.go b/tests/http_server.go index 6564d1dd..269435b2 100644 --- a/tests/http_server.go +++ b/tests/http_server.go @@ -3,6 +3,7 @@ package tests import ( "fmt" "net/http" + "regexp" "strings" ) @@ -12,6 +13,18 @@ func StartHttpServer() { } func request(w http.ResponseWriter, r *http.Request) { + match, err := regexp.Match(`.*\.sub\.com`, []byte(r.Host)) + if err != nil { + w.WriteHeader(500) + return + } + + if match { + w.WriteHeader(200) + w.Write([]byte(r.Host)) + return + } + if strings.Contains(r.Host, "127.0.0.1") || strings.Contains(r.Host, "test2.frp.com") || strings.Contains(r.Host, "test5.frp.com") { w.WriteHeader(200)