mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
fix by golint (#1822)
This commit is contained in:
@@ -38,7 +38,7 @@ local_port = 10701
|
||||
remote_port = 20801
|
||||
`
|
||||
|
||||
func TestTcpWithTokenAuthentication(t *testing.T) {
|
||||
func TestTCPWithTokenAuthentication(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
frpsCfgPath, err := config.GenerateConfigFile(consts.FRPS_NORMAL_CONFIG, FRPS_TOKEN_TCP_CONF)
|
||||
if assert.NoError(err) {
|
||||
@@ -66,7 +66,7 @@ func TestTcpWithTokenAuthentication(t *testing.T) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp
|
||||
res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCmdTcp(t *testing.T) {
|
||||
func TestCmdTCP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var err error
|
||||
@@ -29,12 +29,12 @@ func TestCmdTcp(t *testing.T) {
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
|
||||
func TestCmdUdp(t *testing.T) {
|
||||
func TestCmdUDP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var err error
|
||||
@@ -53,12 +53,12 @@ func TestCmdUdp(t *testing.T) {
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
res, err := util.SendUdpMsg("127.0.0.1:20802", consts.TEST_UDP_ECHO_STR)
|
||||
res, err := util.SendUDPMsg("127.0.0.1:20802", consts.TEST_UDP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_UDP_ECHO_STR, res)
|
||||
}
|
||||
|
||||
func TestCmdHttp(t *testing.T) {
|
||||
func TestCmdHTTP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var err error
|
||||
@@ -77,7 +77,7 @@ func TestCmdHttp(t *testing.T) {
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
code, body, _, err := util.SendHttpMsg("GET", "http://127.0.0.1:20001", "", nil, "")
|
||||
code, body, _, err := util.SendHTTPMsg("GET", "http://127.0.0.1:20001", "", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal(consts.TEST_HTTP_NORMAL_STR, body)
|
||||
|
||||
@@ -102,7 +102,7 @@ func TestHealthCheck(t *testing.T) {
|
||||
var healthMu sync.RWMutex
|
||||
svc1Health := true
|
||||
svc2Health := true
|
||||
httpSvc1 := mock.NewHttpServer(15003, func(w http.ResponseWriter, r *http.Request) {
|
||||
httpSvc1 := mock.NewHTTPServer(15003, func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.Contains(r.URL.Path, "health") {
|
||||
healthMu.RLock()
|
||||
defer healthMu.RUnlock()
|
||||
@@ -120,7 +120,7 @@ func TestHealthCheck(t *testing.T) {
|
||||
defer httpSvc1.Stop()
|
||||
}
|
||||
|
||||
httpSvc2 := mock.NewHttpServer(15004, func(w http.ResponseWriter, r *http.Request) {
|
||||
httpSvc2 := mock.NewHTTPServer(15004, func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.Contains(r.URL.Path, "health") {
|
||||
healthMu.RLock()
|
||||
defer healthMu.RUnlock()
|
||||
@@ -138,7 +138,7 @@ func TestHealthCheck(t *testing.T) {
|
||||
defer httpSvc2.Stop()
|
||||
}
|
||||
|
||||
httpSvc3 := mock.NewHttpServer(15005, func(w http.ResponseWriter, r *http.Request) {
|
||||
httpSvc3 := mock.NewHTTPServer(15005, func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("http3"))
|
||||
})
|
||||
err = httpSvc3.Start()
|
||||
@@ -146,7 +146,7 @@ func TestHealthCheck(t *testing.T) {
|
||||
defer httpSvc3.Stop()
|
||||
}
|
||||
|
||||
httpSvc4 := mock.NewHttpServer(15006, func(w http.ResponseWriter, r *http.Request) {
|
||||
httpSvc4 := mock.NewHTTPServer(15006, func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("http4"))
|
||||
})
|
||||
err = httpSvc4.Start()
|
||||
@@ -185,11 +185,11 @@ func TestHealthCheck(t *testing.T) {
|
||||
// ****** healcheck type tcp ******
|
||||
// echo1 and echo2 is ok
|
||||
result := make([]string, 0)
|
||||
res, err := util.SendTcpMsg("127.0.0.1:15000", "echo")
|
||||
res, err := util.SendTCPMsg("127.0.0.1:15000", "echo")
|
||||
assert.NoError(err)
|
||||
result = append(result, res)
|
||||
|
||||
res, err = util.SendTcpMsg("127.0.0.1:15000", "echo")
|
||||
res, err = util.SendTCPMsg("127.0.0.1:15000", "echo")
|
||||
assert.NoError(err)
|
||||
result = append(result, res)
|
||||
|
||||
@@ -201,11 +201,11 @@ func TestHealthCheck(t *testing.T) {
|
||||
time.Sleep(1200 * time.Millisecond)
|
||||
|
||||
result = make([]string, 0)
|
||||
res, err = util.SendTcpMsg("127.0.0.1:15000", "echo")
|
||||
res, err = util.SendTCPMsg("127.0.0.1:15000", "echo")
|
||||
assert.NoError(err)
|
||||
result = append(result, res)
|
||||
|
||||
res, err = util.SendTcpMsg("127.0.0.1:15000", "echo")
|
||||
res, err = util.SendTCPMsg("127.0.0.1:15000", "echo")
|
||||
assert.NoError(err)
|
||||
result = append(result, res)
|
||||
|
||||
@@ -221,11 +221,11 @@ func TestHealthCheck(t *testing.T) {
|
||||
time.Sleep(1200 * time.Millisecond)
|
||||
|
||||
result = make([]string, 0)
|
||||
res, err = util.SendTcpMsg("127.0.0.1:15000", "echo")
|
||||
res, err = util.SendTCPMsg("127.0.0.1:15000", "echo")
|
||||
assert.NoError(err)
|
||||
result = append(result, res)
|
||||
|
||||
res, err = util.SendTcpMsg("127.0.0.1:15000", "echo")
|
||||
res, err = util.SendTCPMsg("127.0.0.1:15000", "echo")
|
||||
assert.NoError(err)
|
||||
result = append(result, res)
|
||||
|
||||
@@ -234,12 +234,12 @@ func TestHealthCheck(t *testing.T) {
|
||||
|
||||
// ****** healcheck type http ******
|
||||
// http1 and http2 is ok
|
||||
code, body, _, err := util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test1.com", nil, "")
|
||||
code, body, _, err := util.SendHTTPMsg("GET", "http://127.0.0.1:14000/xxx", "test1.com", nil, "")
|
||||
assert.NoError(err)
|
||||
assert.Equal(200, code)
|
||||
assert.Equal("http1", body)
|
||||
|
||||
code, body, _, err = util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test2.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", "http://127.0.0.1:14000/xxx", "test2.com", nil, "")
|
||||
assert.NoError(err)
|
||||
assert.Equal(200, code)
|
||||
assert.Equal("http2", body)
|
||||
@@ -250,12 +250,12 @@ func TestHealthCheck(t *testing.T) {
|
||||
healthMu.Unlock()
|
||||
time.Sleep(1200 * time.Millisecond)
|
||||
|
||||
code, body, _, err = util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test1.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", "http://127.0.0.1:14000/xxx", "test1.com", nil, "")
|
||||
assert.NoError(err)
|
||||
assert.Equal(200, code)
|
||||
assert.Equal("http1", body)
|
||||
|
||||
code, _, _, err = util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test2.com", nil, "")
|
||||
code, _, _, err = util.SendHTTPMsg("GET", "http://127.0.0.1:14000/xxx", "test2.com", nil, "")
|
||||
assert.NoError(err)
|
||||
assert.Equal(404, code)
|
||||
|
||||
@@ -265,12 +265,12 @@ func TestHealthCheck(t *testing.T) {
|
||||
healthMu.Unlock()
|
||||
time.Sleep(1200 * time.Millisecond)
|
||||
|
||||
code, body, _, err = util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test1.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", "http://127.0.0.1:14000/xxx", "test1.com", nil, "")
|
||||
assert.NoError(err)
|
||||
assert.Equal(200, code)
|
||||
assert.Equal("http1", body)
|
||||
|
||||
code, body, _, err = util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test2.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", "http://127.0.0.1:14000/xxx", "test2.com", nil, "")
|
||||
assert.NoError(err)
|
||||
assert.Equal(200, code)
|
||||
assert.Equal("http2", body)
|
||||
@@ -278,12 +278,12 @@ func TestHealthCheck(t *testing.T) {
|
||||
// ****** load balancing type http ******
|
||||
result = make([]string, 0)
|
||||
|
||||
code, body, _, err = util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test.balancing.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", "http://127.0.0.1:14000/xxx", "test.balancing.com", nil, "")
|
||||
assert.NoError(err)
|
||||
assert.Equal(200, code)
|
||||
result = append(result, body)
|
||||
|
||||
code, body, _, err = util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test.balancing.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", "http://127.0.0.1:14000/xxx", "test.balancing.com", nil, "")
|
||||
assert.NoError(err)
|
||||
assert.Equal(200, code)
|
||||
result = append(result, body)
|
||||
|
||||
@@ -33,9 +33,9 @@ func TestMain(m *testing.M) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
go mock.StartUdpEchoServer(consts.TEST_UDP_PORT)
|
||||
go mock.StartUDPEchoServer(consts.TEST_UDP_PORT)
|
||||
go mock.StartUnixDomainServer(consts.TEST_UNIX_DOMAIN_ADDR)
|
||||
go mock.StartHttpServer(consts.TEST_HTTP_PORT)
|
||||
go mock.StartHTTPServer(consts.TEST_HTTP_PORT)
|
||||
|
||||
p1 := util.NewProcess(consts.FRPS_BIN_PATH, []string{"-c", "./auto_test_frps.ini"})
|
||||
if err = p1.Start(); err != nil {
|
||||
@@ -61,32 +61,32 @@ func TestMain(m *testing.M) {
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
func TestTcp(t *testing.T) {
|
||||
func TestTCP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// Normal
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", consts.TEST_TCP_FRP_PORT)
|
||||
res, err := util.SendTcpMsg(addr, consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg(addr, consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
|
||||
// Encrytion and compression
|
||||
addr = fmt.Sprintf("127.0.0.1:%d", consts.TEST_TCP_EC_FRP_PORT)
|
||||
res, err = util.SendTcpMsg(addr, consts.TEST_TCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg(addr, consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
|
||||
func TestUdp(t *testing.T) {
|
||||
func TestUDP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// Normal
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", consts.TEST_UDP_FRP_PORT)
|
||||
res, err := util.SendUdpMsg(addr, consts.TEST_UDP_ECHO_STR)
|
||||
res, err := util.SendUDPMsg(addr, consts.TEST_UDP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_UDP_ECHO_STR, res)
|
||||
|
||||
// Encrytion and compression
|
||||
addr = fmt.Sprintf("127.0.0.1:%d", consts.TEST_UDP_EC_FRP_PORT)
|
||||
res, err = util.SendUdpMsg(addr, consts.TEST_UDP_ECHO_STR)
|
||||
res, err = util.SendUDPMsg(addr, consts.TEST_UDP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_UDP_ECHO_STR, res)
|
||||
}
|
||||
@@ -95,97 +95,97 @@ func TestUnixDomain(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// Normal
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", consts.TEST_UNIX_DOMAIN_FRP_PORT)
|
||||
res, err := util.SendTcpMsg(addr, consts.TEST_UNIX_DOMAIN_STR)
|
||||
res, err := util.SendTCPMsg(addr, consts.TEST_UNIX_DOMAIN_STR)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(consts.TEST_UNIX_DOMAIN_STR, res)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStcp(t *testing.T) {
|
||||
func TestSTCP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// Normal
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", consts.TEST_STCP_FRP_PORT)
|
||||
res, err := util.SendTcpMsg(addr, consts.TEST_STCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg(addr, consts.TEST_STCP_ECHO_STR)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(consts.TEST_STCP_ECHO_STR, res)
|
||||
}
|
||||
|
||||
// Encrytion and compression
|
||||
addr = fmt.Sprintf("127.0.0.1:%d", consts.TEST_STCP_EC_FRP_PORT)
|
||||
res, err = util.SendTcpMsg(addr, consts.TEST_STCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg(addr, consts.TEST_STCP_ECHO_STR)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(consts.TEST_STCP_ECHO_STR, res)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSudp(t *testing.T) {
|
||||
func TestSUDP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// Normal
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", consts.TEST_SUDP_FRP_PORT)
|
||||
res, err := util.SendUdpMsg(addr, consts.TEST_SUDP_ECHO_STR)
|
||||
res, err := util.SendUDPMsg(addr, consts.TEST_SUDP_ECHO_STR)
|
||||
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_SUDP_ECHO_STR, res)
|
||||
}
|
||||
|
||||
func TestHttp(t *testing.T) {
|
||||
func TestHTTP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// web01
|
||||
code, body, _, err := util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "", nil, "")
|
||||
code, body, _, err := util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal(consts.TEST_HTTP_NORMAL_STR, body)
|
||||
}
|
||||
|
||||
// web02
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test2.frp.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test2.frp.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal(consts.TEST_HTTP_NORMAL_STR, body)
|
||||
}
|
||||
|
||||
// error host header
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "errorhost.frp.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "errorhost.frp.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(404, code)
|
||||
}
|
||||
|
||||
// web03
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test3.frp.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test3.frp.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal(consts.TEST_HTTP_NORMAL_STR, body)
|
||||
}
|
||||
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d/foo", consts.TEST_HTTP_FRP_PORT), "test3.frp.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d/foo", consts.TEST_HTTP_FRP_PORT), "test3.frp.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal(consts.TEST_HTTP_FOO_STR, body)
|
||||
}
|
||||
|
||||
// web04
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d/bar", consts.TEST_HTTP_FRP_PORT), "test3.frp.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d/bar", consts.TEST_HTTP_FRP_PORT), "test3.frp.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal(consts.TEST_HTTP_BAR_STR, body)
|
||||
}
|
||||
|
||||
// web05
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test5.frp.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test5.frp.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(401, code)
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
headers["Authorization"] = util.BasicAuth("test", "test")
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test5.frp.com", headers, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test5.frp.com", headers, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(401, code)
|
||||
}
|
||||
|
||||
// web06
|
||||
var header http.Header
|
||||
code, body, header, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test6.frp.com", nil, "")
|
||||
code, body, header, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test6.frp.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal(consts.TEST_HTTP_NORMAL_STR, body)
|
||||
@@ -194,40 +194,40 @@ func TestHttp(t *testing.T) {
|
||||
|
||||
// wildcard_http
|
||||
// test.frp1.com match *.frp1.com
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test.frp1.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test.frp1.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal(consts.TEST_HTTP_NORMAL_STR, body)
|
||||
}
|
||||
|
||||
// new.test.frp1.com also match *.frp1.com
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "new.test.frp1.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "new.test.frp1.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal(consts.TEST_HTTP_NORMAL_STR, body)
|
||||
}
|
||||
|
||||
// subhost01
|
||||
code, body, _, err = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test01.sub.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.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 = util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test02.sub.com", nil, "")
|
||||
code, body, _, err = util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT), "test02.sub.com", nil, "")
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
assert.Equal("test02.sub.com", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTcpMux(t *testing.T) {
|
||||
func TestTCPMux(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
conn, err := gnet.DialTcpByProxy(fmt.Sprintf("http://%s:%d", "127.0.0.1", consts.TEST_TCP_MUX_FRP_PORT), "tunnel1")
|
||||
if assert.NoError(err) {
|
||||
res, err := util.SendTcpMsgByConn(conn, consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsgByConn(conn, consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
@@ -252,66 +252,66 @@ func TestWebSocket(t *testing.T) {
|
||||
func TestAllowPorts(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// Port not allowed
|
||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortNotAllowed)
|
||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTCPPortNotAllowed)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(proxy.ProxyStatusStartErr, status.Status)
|
||||
assert.Equal(proxy.ProxyPhaseStartErr, status.Status)
|
||||
assert.True(strings.Contains(status.Err, ports.ErrPortNotAllowed.Error()))
|
||||
}
|
||||
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUdpPortNotAllowed)
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUDPPortNotAllowed)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(proxy.ProxyStatusStartErr, status.Status)
|
||||
assert.Equal(proxy.ProxyPhaseStartErr, status.Status)
|
||||
assert.True(strings.Contains(status.Err, ports.ErrPortNotAllowed.Error()))
|
||||
}
|
||||
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortUnavailable)
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTCPPortUnavailable)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(proxy.ProxyStatusStartErr, status.Status)
|
||||
assert.Equal(proxy.ProxyPhaseStartErr, status.Status)
|
||||
assert.True(strings.Contains(status.Err, ports.ErrPortUnAvailable.Error()))
|
||||
}
|
||||
|
||||
// Port normal
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortNormal)
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTCPPortNormal)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(proxy.ProxyStatusRunning, status.Status)
|
||||
assert.Equal(proxy.ProxyPhaseRunning, status.Status)
|
||||
}
|
||||
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUdpPortNormal)
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUDPPortNormal)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(proxy.ProxyStatusRunning, status.Status)
|
||||
assert.Equal(proxy.ProxyPhaseRunning, status.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandomPort(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// tcp
|
||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpRandomPort)
|
||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTCPRandomPort)
|
||||
if assert.NoError(err) {
|
||||
addr := status.RemoteAddr
|
||||
res, err := util.SendTcpMsg(addr, consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg(addr, consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
|
||||
// udp
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUdpRandomPort)
|
||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUDPRandomPort)
|
||||
if assert.NoError(err) {
|
||||
addr := status.RemoteAddr
|
||||
res, err := util.SendUdpMsg(addr, consts.TEST_UDP_ECHO_STR)
|
||||
res, err := util.SendUDPMsg(addr, consts.TEST_UDP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_UDP_ECHO_STR, res)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginHttpProxy(t *testing.T) {
|
||||
func TestPluginHTTPProxy(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyHttpProxy)
|
||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyHTTPProxy)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(proxy.ProxyStatusRunning, status.Status)
|
||||
assert.Equal(proxy.ProxyPhaseRunning, status.Status)
|
||||
|
||||
// http proxy
|
||||
addr := status.RemoteAddr
|
||||
code, body, _, err := util.SendHttpMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT),
|
||||
code, body, _, err := util.SendHTTPMsg("GET", fmt.Sprintf("http://127.0.0.1:%d", consts.TEST_HTTP_FRP_PORT),
|
||||
"", nil, "http://"+addr)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(200, code)
|
||||
@@ -321,7 +321,7 @@ func TestPluginHttpProxy(t *testing.T) {
|
||||
// connect method
|
||||
conn, err := gnet.DialTcpByProxy("http://"+addr, fmt.Sprintf("127.0.0.1:%d", consts.TEST_TCP_FRP_PORT))
|
||||
if assert.NoError(err) {
|
||||
res, err := util.SendTcpMsgByConn(conn, consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsgByConn(conn, consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
@@ -332,10 +332,10 @@ func TestRangePortsMapping(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
name := fmt.Sprintf("%s_%d", consts.ProxyRangeTcpPrefix, i)
|
||||
name := fmt.Sprintf("%s_%d", consts.ProxyRangeTCPPrefix, i)
|
||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, name)
|
||||
if assert.NoError(err) {
|
||||
assert.Equal(proxy.ProxyStatusRunning, status.Status)
|
||||
assert.Equal(proxy.ProxyPhaseRunning, status.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -350,7 +350,7 @@ func TestGroup(t *testing.T) {
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", consts.TEST_TCP2_FRP_PORT)
|
||||
|
||||
for i := 0; i < 6; i++ {
|
||||
res, err := util.SendTcpMsg(addr, consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg(addr, consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
switch res {
|
||||
case consts.TEST_TCP_ECHO_STR:
|
||||
|
||||
@@ -66,7 +66,7 @@ func TestReconnect(t *testing.T) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp
|
||||
res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestReconnect(t *testing.T) {
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
// test tcp, expect failed
|
||||
_, err = util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
_, err = util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.Error(err)
|
||||
|
||||
// restart frpc
|
||||
@@ -87,7 +87,7 @@ func TestReconnect(t *testing.T) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp
|
||||
res, err = util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
|
||||
@@ -96,7 +96,7 @@ func TestReconnect(t *testing.T) {
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
// test tcp, expect failed
|
||||
_, err = util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
_, err = util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.Error(err)
|
||||
|
||||
// restart frps
|
||||
@@ -109,7 +109,7 @@ func TestReconnect(t *testing.T) {
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// test tcp
|
||||
res, err = util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
|
||||
@@ -105,17 +105,17 @@ func TestReload(t *testing.T) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp1
|
||||
res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
|
||||
// test tcp2
|
||||
res, err = util.SendTcpMsg("127.0.0.1:20802", consts.TEST_TCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg("127.0.0.1:20802", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
|
||||
// test tcp3
|
||||
res, err = util.SendTcpMsg("127.0.0.1:20803", consts.TEST_TCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg("127.0.0.1:20803", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
|
||||
@@ -131,20 +131,20 @@ func TestReload(t *testing.T) {
|
||||
time.Sleep(time.Second)
|
||||
|
||||
// test tcp1
|
||||
res, err = util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
|
||||
// test origin tcp2, expect failed
|
||||
res, err = util.SendTcpMsg("127.0.0.1:20802", consts.TEST_TCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg("127.0.0.1:20802", consts.TEST_TCP_ECHO_STR)
|
||||
assert.Error(err)
|
||||
|
||||
// test new origin tcp2 with different port
|
||||
res, err = util.SendTcpMsg("127.0.0.1:20902", consts.TEST_TCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg("127.0.0.1:20902", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
|
||||
// test tcp3, expect failed
|
||||
res, err = util.SendTcpMsg("127.0.0.1:20803", consts.TEST_TCP_ECHO_STR)
|
||||
res, err = util.SendTCPMsg("127.0.0.1:20803", consts.TEST_TCP_ECHO_STR)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func TestConfTemplate(t *testing.T) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp1
|
||||
res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ local_port = 10701
|
||||
remote_port = 20801
|
||||
`
|
||||
|
||||
func TestTlsOverTCP(t *testing.T) {
|
||||
func TestTLSOverTCP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
frpsCfgPath, err := config.GenerateConfigFile(consts.FRPS_NORMAL_CONFIG, FRPS_TLS_TCP_CONF)
|
||||
if assert.NoError(err) {
|
||||
@@ -65,7 +65,7 @@ func TestTlsOverTCP(t *testing.T) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp
|
||||
res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func TestTLSOverKCP(t *testing.T) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp
|
||||
res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func TestTLSOverWebsocket(t *testing.T) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp
|
||||
res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
}
|
||||
@@ -229,16 +229,16 @@ local_port = 10701
|
||||
remote_port = 20802
|
||||
`
|
||||
|
||||
func TestTlsOnlyOverTCP(t *testing.T) {
|
||||
func TestTLSOnlyOverTCP(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
frpsCfgPath, err := config.GenerateConfigFile(consts.FRPS_NORMAL_CONFIG, FRPS_TLS_ONLY_TCP_CONF)
|
||||
if assert.NoError(err) {
|
||||
defer os.Remove(frpsCfgPath)
|
||||
}
|
||||
|
||||
frpcWithTlsCfgPath, err := config.GenerateConfigFile(consts.FRPC_NORMAL_CONFIG, FRPC_TLS_ONLY_TCP_CONF)
|
||||
frpcWithTLSCfgPath, err := config.GenerateConfigFile(consts.FRPC_NORMAL_CONFIG, FRPC_TLS_ONLY_TCP_CONF)
|
||||
if assert.NoError(err) {
|
||||
defer os.Remove(frpcWithTlsCfgPath)
|
||||
defer os.Remove(frpcWithTLSCfgPath)
|
||||
}
|
||||
|
||||
frpsProcess := util.NewProcess(consts.FRPS_BIN_PATH, []string{"-c", frpsCfgPath})
|
||||
@@ -249,32 +249,32 @@ func TestTlsOnlyOverTCP(t *testing.T) {
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
frpcProcessWithTls := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcWithTlsCfgPath})
|
||||
err = frpcProcessWithTls.Start()
|
||||
frpcProcessWithTLS := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcWithTLSCfgPath})
|
||||
err = frpcProcessWithTLS.Start()
|
||||
if assert.NoError(err) {
|
||||
defer frpcProcessWithTls.Stop()
|
||||
defer frpcProcessWithTLS.Stop()
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp over tls
|
||||
res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
// test tcp over TLS
|
||||
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
|
||||
assert.NoError(err)
|
||||
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
|
||||
frpcProcessWithTls.Stop()
|
||||
frpcProcessWithTLS.Stop()
|
||||
|
||||
frpcWithoutTlsCfgPath, err := config.GenerateConfigFile(consts.FRPC_NORMAL_CONFIG, FRPC_TLS_ONLY_NO_TLS_TCP_CONF)
|
||||
frpcWithoutTLSCfgPath, err := config.GenerateConfigFile(consts.FRPC_NORMAL_CONFIG, FRPC_TLS_ONLY_NO_TLS_TCP_CONF)
|
||||
if assert.NoError(err) {
|
||||
defer os.Remove(frpcWithTlsCfgPath)
|
||||
defer os.Remove(frpcWithTLSCfgPath)
|
||||
}
|
||||
|
||||
frpcProcessWithoutTls := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcWithoutTlsCfgPath})
|
||||
err = frpcProcessWithoutTls.Start()
|
||||
frpcProcessWithoutTLS := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcWithoutTLSCfgPath})
|
||||
err = frpcProcessWithoutTLS.Start()
|
||||
if assert.NoError(err) {
|
||||
defer frpcProcessWithoutTls.Stop()
|
||||
defer frpcProcessWithoutTLS.Stop()
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// test tcp without tls
|
||||
_, err = util.SendTcpMsg("127.0.0.1:20802", consts.TEST_TCP_ECHO_STR)
|
||||
// test tcp without TLS
|
||||
_, err = util.SendTCPMsg("127.0.0.1:20802", consts.TEST_TCP_ECHO_STR)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
@@ -49,16 +49,16 @@ var (
|
||||
TEST_SUDP_FRP_PORT int = 10816
|
||||
TEST_SUDP_ECHO_STR string = "sudp type:" + TEST_STR
|
||||
|
||||
ProxyTcpPortNotAllowed string = "tcp_port_not_allowed"
|
||||
ProxyTcpPortUnavailable string = "tcp_port_unavailable"
|
||||
ProxyTcpPortNormal string = "tcp_port_normal"
|
||||
ProxyTcpRandomPort string = "tcp_random_port"
|
||||
ProxyUdpPortNotAllowed string = "udp_port_not_allowed"
|
||||
ProxyUdpPortNormal string = "udp_port_normal"
|
||||
ProxyUdpRandomPort string = "udp_random_port"
|
||||
ProxyHttpProxy string = "http_proxy"
|
||||
ProxyTCPPortNotAllowed string = "tcp_port_not_allowed"
|
||||
ProxyTCPPortUnavailable string = "tcp_port_unavailable"
|
||||
ProxyTCPPortNormal string = "tcp_port_normal"
|
||||
ProxyTCPRandomPort string = "tcp_random_port"
|
||||
ProxyUDPPortNotAllowed string = "udp_port_not_allowed"
|
||||
ProxyUDPPortNormal string = "udp_port_normal"
|
||||
ProxyUDPRandomPort string = "udp_random_port"
|
||||
ProxyHTTPProxy string = "http_proxy"
|
||||
|
||||
ProxyRangeTcpPrefix string = "range_tcp"
|
||||
ProxyRangeTCPPrefix string = "range_tcp"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -54,7 +54,7 @@ func (es *EchoServer) Stop() {
|
||||
es.l.Close()
|
||||
}
|
||||
|
||||
func StartUdpEchoServer(port int) {
|
||||
func StartUDPEchoServer(port int) {
|
||||
l, err := frpNet.ListenUDP("127.0.0.1", port)
|
||||
if err != nil {
|
||||
fmt.Printf("udp echo server listen error: %v\n", err)
|
||||
|
||||
@@ -13,21 +13,21 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type HttpServer struct {
|
||||
type HTTPServer struct {
|
||||
l net.Listener
|
||||
|
||||
port int
|
||||
handler http.HandlerFunc
|
||||
}
|
||||
|
||||
func NewHttpServer(port int, handler http.HandlerFunc) *HttpServer {
|
||||
return &HttpServer{
|
||||
func NewHTTPServer(port int, handler http.HandlerFunc) *HTTPServer {
|
||||
return &HTTPServer{
|
||||
port: port,
|
||||
handler: handler,
|
||||
}
|
||||
}
|
||||
|
||||
func (hs *HttpServer) Start() error {
|
||||
func (hs *HTTPServer) Start() error {
|
||||
l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", hs.port))
|
||||
if err != nil {
|
||||
fmt.Printf("http server listen error: %v\n", err)
|
||||
@@ -39,14 +39,14 @@ func (hs *HttpServer) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hs *HttpServer) Stop() {
|
||||
func (hs *HTTPServer) Stop() {
|
||||
hs.l.Close()
|
||||
}
|
||||
|
||||
var upgrader = websocket.Upgrader{}
|
||||
|
||||
func StartHttpServer(port int) {
|
||||
http.HandleFunc("/", handleHttp)
|
||||
func StartHTTPServer(port int) {
|
||||
http.HandleFunc("/", handleHTTP)
|
||||
http.HandleFunc("/ws", handleWebSocket)
|
||||
http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", port), nil)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func handleWebSocket(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func handleHttp(w http.ResponseWriter, r *http.Request) {
|
||||
func handleHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get("X-From-Where") == "frp" {
|
||||
w.Header().Set("X-Header-Set", "true")
|
||||
}
|
||||
|
||||
@@ -41,37 +41,37 @@ func GetProxyStatus(statusAddr string, user string, passwd string, name string)
|
||||
if err != nil {
|
||||
return status, fmt.Errorf("unmarshal http response error: %s", strings.TrimSpace(string(body)))
|
||||
}
|
||||
for _, s := range allStatus.Tcp {
|
||||
for _, s := range allStatus.TCP {
|
||||
if s.Name == name {
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
for _, s := range allStatus.Udp {
|
||||
for _, s := range allStatus.UDP {
|
||||
if s.Name == name {
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
for _, s := range allStatus.Http {
|
||||
for _, s := range allStatus.HTTP {
|
||||
if s.Name == name {
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
for _, s := range allStatus.Https {
|
||||
for _, s := range allStatus.HTTPS {
|
||||
if s.Name == name {
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
for _, s := range allStatus.Stcp {
|
||||
for _, s := range allStatus.STCP {
|
||||
if s.Name == name {
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
for _, s := range allStatus.Xtcp {
|
||||
for _, s := range allStatus.XTCP {
|
||||
if s.Name == name {
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
for _, s := range allStatus.Sudp {
|
||||
for _, s := range allStatus.SUDP {
|
||||
if s.Name == name {
|
||||
return &s, nil
|
||||
}
|
||||
@@ -101,17 +101,17 @@ func ReloadConf(reloadAddr string, user string, passwd string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendTcpMsg(addr string, msg string) (res string, err error) {
|
||||
func SendTCPMsg(addr string, msg string) (res string, err error) {
|
||||
c, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("connect to tcp server error: %v", err)
|
||||
return
|
||||
}
|
||||
defer c.Close()
|
||||
return SendTcpMsgByConn(c, msg)
|
||||
return SendTCPMsgByConn(c, msg)
|
||||
}
|
||||
|
||||
func SendTcpMsgByConn(c net.Conn, msg string) (res string, err error) {
|
||||
func SendTCPMsgByConn(c net.Conn, msg string) (res string, err error) {
|
||||
timer := time.Now().Add(5 * time.Second)
|
||||
c.SetDeadline(timer)
|
||||
c.Write([]byte(msg))
|
||||
@@ -125,7 +125,7 @@ func SendTcpMsgByConn(c net.Conn, msg string) (res string, err error) {
|
||||
return string(buf[:n]), nil
|
||||
}
|
||||
|
||||
func SendUdpMsg(addr string, msg string) (res string, err error) {
|
||||
func SendUDPMsg(addr string, msg string) (res string, err error) {
|
||||
udpAddr, errRet := net.ResolveUDPAddr("udp", addr)
|
||||
if errRet != nil {
|
||||
err = fmt.Errorf("resolve udp addr error: %v", err)
|
||||
@@ -153,7 +153,7 @@ func SendUdpMsg(addr string, msg string) (res string, err error) {
|
||||
return string(buf[:n]), nil
|
||||
}
|
||||
|
||||
func SendHttpMsg(method, urlStr string, host string, headers map[string]string, proxy string) (code int, body string, header http.Header, err error) {
|
||||
func SendHTTPMsg(method, urlStr string, host string, headers map[string]string, proxy string) (code int, body string, header http.Header, err error) {
|
||||
req, errRet := http.NewRequest(method, urlStr, nil)
|
||||
if errRet != nil {
|
||||
err = errRet
|
||||
|
||||
Reference in New Issue
Block a user