From 3f64d73ea9e80f2b52ca1b524b6734fb04176869 Mon Sep 17 00:00:00 2001 From: fatedier Date: Mon, 22 Jan 2018 14:16:46 +0800 Subject: [PATCH] ci: add subdomain test case --- tests/conf/auto_test_frpc.ini | 12 ++++++++++++ tests/conf/auto_test_frps.ini | 1 + tests/func_test.go | 14 ++++++++++++++ tests/http_server.go | 13 +++++++++++++ 4 files changed, 40 insertions(+) diff --git a/tests/conf/auto_test_frpc.ini b/tests/conf/auto_test_frpc.ini index 231f4d9..777f8de 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 1bc3a82..229ffa8 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 39494b3..0d10685 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 6564d1d..269435b 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)