ci: add subdomain test case

This commit is contained in:
fatedier 2018-01-22 14:16:46 +08:00
parent a77c7e8625
commit 3f64d73ea9
4 changed files with 40 additions and 0 deletions

View File

@ -103,6 +103,18 @@ use_compression = true
http_user = test http_user = test
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] [tcp_port_not_allowed]
type = tcp type = tcp
local_ip = 127.0.0.1 local_ip = 127.0.0.1

View File

@ -6,3 +6,4 @@ log_file = ./frps.log
log_level = debug log_level = debug
privilege_token = 123456 privilege_token = 123456
privilege_allow_ports = 10000-20000,20002,30000-40000 privilege_allow_ports = 10000-20000,20002,30000-40000
subdomain_host = sub.com

View File

@ -171,6 +171,20 @@ func TestHttp(t *testing.T) {
if assert.NoError(err) { if assert.NoError(err) {
assert.Equal(401, code) 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) { func TestPrivilegeAllowPorts(t *testing.T) {

View File

@ -3,6 +3,7 @@ package tests
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"regexp"
"strings" "strings"
) )
@ -12,6 +13,18 @@ func StartHttpServer() {
} }
func request(w http.ResponseWriter, r *http.Request) { 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") || if strings.Contains(r.Host, "127.0.0.1") || strings.Contains(r.Host, "test2.frp.com") ||
strings.Contains(r.Host, "test5.frp.com") { strings.Contains(r.Host, "test5.frp.com") {
w.WriteHeader(200) w.WriteHeader(200)