Browse Source

ci: add subdomain test case

fatedier 7 years ago
parent
commit
3f64d73ea9
4 changed files with 40 additions and 0 deletions
  1. 12 0
      tests/conf/auto_test_frpc.ini
  2. 1 0
      tests/conf/auto_test_frps.ini
  3. 14 0
      tests/func_test.go
  4. 13 0
      tests/http_server.go

+ 12 - 0
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

+ 1 - 0
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

+ 14 - 0
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) {

+ 13 - 0
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)