Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
企猫商务
frp
提交
3bb404df
F
frp
项目概览
企猫商务
/
frp
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
frp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3bb404df
编写于
12月 18, 2017
作者:
F
fatedier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more test case
上级
ff4bdec3
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
266 addition
and
55 deletion
+266
-55
conf/frpc_full.ini
conf/frpc_full.ini
+1
-1
tests/clean_test.sh
tests/clean_test.sh
+6
-0
tests/conf/auto_test_frpc.ini
tests/conf/auto_test_frpc.ini
+78
-12
tests/conf/auto_test_frpc_visitor.ini
tests/conf/auto_test_frpc_visitor.ini
+25
-0
tests/conf/auto_test_frps.ini
tests/conf/auto_test_frps.ini
+1
-1
tests/echo_server.go
tests/echo_server.go
+2
-2
tests/func_test.go
tests/func_test.go
+95
-35
tests/http_server.go
tests/http_server.go
+19
-2
tests/run_test.sh
tests/run_test.sh
+1
-0
tests/util.go
tests/util.go
+38
-2
未找到文件。
conf/frpc_full.ini
浏览文件 @
3bb404df
...
...
@@ -88,7 +88,7 @@ http_pwd = admin
# if domain for frps is frps.com, then you can access [web01] proxy by URL http://test.frps.com
subdomain
=
web01
custom_domains
=
web02.yourdomain.com
# locations is only
useful
for http type
# locations is only
available
for http type
locations
=
/,/pic
host_header_rewrite
=
example.com
...
...
tests/clean_test.sh
浏览文件 @
3bb404df
...
...
@@ -10,5 +10,11 @@ if [ -n "${pid}" ]; then
kill
${
pid
}
fi
pid
=
`
ps aux|grep
'./../bin/frpc -c ./conf/auto_test_frpc_visitor.ini'
|grep
-v
grep
|awk
{
'print $2'
}
`
if
[
-n
"
${
pid
}
"
]
;
then
kill
${
pid
}
fi
rm
-f
./frps.log
rm
-f
./frpc.log
rm
-f
./frpc_visitor.log
tests/conf/auto_test_frpc.ini
浏览文件 @
3bb404df
...
...
@@ -6,30 +6,96 @@ log_file = ./frpc.log
log_level
=
debug
privilege_token
=
123456
[
echo
]
[
tcp_normal
]
type
=
tcp
local_ip
=
127.0.0.1
local_port
=
10701
remote_port
=
10711
use_encryption
=
true
use_compression
=
true
remote_port
=
10801
[
web
]
type
=
htt
p
[
tcp_ec
]
type
=
tc
p
local_ip
=
127.0.0.1
local_port
=
10702
local_port
=
10701
remote_port
=
10901
use_encryption
=
true
use_compression
=
true
custom_domains
=
127.0.0.1
[udp]
[udp
_normal
]
type
=
udp
local_ip
=
127.0.0.1
local_port
=
10703
remote_port
=
10712
local_port
=
10702
remote_port
=
10802
[udp_ec]
type
=
udp
local_ip
=
127.0.0.1
local_port
=
10702
remote_port
=
10902
use_encryption
=
true
use_compression
=
true
[unix_domain]
type
=
tcp
remote_port
=
10
704
remote_port
=
10
803
plugin
=
unix_domain_socket
plugin_unix_path
=
/tmp/frp_echo_server.sock
[stcp]
type
=
stcp
sk
=
abcdefg
local_ip
=
127.0.0.1
local_port
=
10701
[stcp_ec]
type
=
stcp
sk
=
abc
local_ip
=
127.0.0.1
local_port
=
10701
use_encryption
=
true
use_compression
=
true
[web01]
type
=
http
local_ip
=
127.0.0.1
local_port
=
10704
custom_domains
=
127.0.0.1
[web02]
type
=
http
local_ip
=
127.0.0.1
local_port
=
10704
custom_domains
=
test2.frp.com
host_header_rewrite
=
test2.frp.com
use_encryption
=
true
use_compression
=
true
[web03]
type
=
http
local_ip
=
127.0.0.1
local_port
=
10704
custom_domains
=
test3.frp.com
use_encryption
=
true
use_compression
=
true
host_header_rewrite
=
test3.frp.com
locations
=
/,/foo
[web04]
type
=
http
local_ip
=
127.0.0.1
local_port
=
10704
custom_domains
=
test3.frp.com
use_encryption
=
true
use_compression
=
true
host_header_rewrite
=
test3.frp.com
locations
=
/bar
[web05]
type
=
http
local_ip
=
127.0.0.1
local_port
=
10704
custom_domains
=
test5.frp.com
host_header_rewrite
=
test5.frp.com
use_encryption
=
true
use_compression
=
true
http_user
=
test
http_user
=
test
tests/conf/auto_test_frpc_visitor.ini
0 → 100644
浏览文件 @
3bb404df
[common]
server_addr
=
0.0.0.0
server_port
=
10700
log_file
=
./frpc_visitor.log
# debug, info, warn, error
log_level
=
debug
privilege_token
=
123456
[stcp_visitor]
type
=
stcp
role
=
visitor
server_name
=
stcp
sk
=
abcdefg
bind_addr
=
127.0.0.1
bind_port
=
10805
[stcp_ec_visitor]
type
=
stcp
role
=
visitor
server_name
=
stcp_ec
sk
=
abc
bind_addr
=
127.0.0.1
bind_port
=
10905
use_encryption
=
true
use_compression
=
true
tests/conf/auto_test_frps.ini
浏览文件 @
3bb404df
[common]
bind_addr
=
0.0.0.0
bind_port
=
10700
vhost_http_port
=
10
710
vhost_http_port
=
10
804
log_file
=
./frps.log
log_level
=
debug
privilege_token
=
123456
tests/echo_server.go
浏览文件 @
3bb404df
...
...
@@ -11,7 +11,7 @@ import (
)
func
StartTcpEchoServer
()
{
l
,
err
:=
frpNet
.
ListenTcp
(
"127.0.0.1"
,
TEST_TCP_
ECHO_
PORT
)
l
,
err
:=
frpNet
.
ListenTcp
(
"127.0.0.1"
,
TEST_TCP_PORT
)
if
err
!=
nil
{
fmt
.
Printf
(
"echo server listen error: %v
\n
"
,
err
)
return
...
...
@@ -29,7 +29,7 @@ func StartTcpEchoServer() {
}
func
StartUdpEchoServer
()
{
l
,
err
:=
frpNet
.
ListenUDP
(
"127.0.0.1"
,
TEST_UDP_
ECHO_
PORT
)
l
,
err
:=
frpNet
.
ListenUDP
(
"127.0.0.1"
,
TEST_UDP_PORT
)
if
err
!=
nil
{
fmt
.
Printf
(
"udp echo server listen error: %v
\n
"
,
err
)
return
...
...
tests/func_test.go
浏览文件 @
3bb404df
package
tests
import
(
"bufio"
"bytes"
"fmt"
"io/ioutil"
"net"
"net/http"
"strings"
"testing"
"time"
frpNet
"github.com/fatedier/frp/utils/net"
"github.com/stretchr/testify/assert"
)
...
...
@@ -22,17 +15,24 @@ var (
TEST_TCP_EC_FRP_PORT
int64
=
10901
TEST_TCP_ECHO_STR
string
=
"tcp type:"
+
TEST_STR
TEST_UDP_PORT
int64
=
10702
TEST_UDP_FRP_PORT
int64
=
10802
TEST_UDP_ECHO_STR
string
=
"udp type:"
+
TEST_STR
TEST_UDP_PORT
int64
=
10702
TEST_UDP_FRP_PORT
int64
=
10802
TEST_UDP_EC_FRP_PORT
int64
=
10902
TEST_UDP_ECHO_STR
string
=
"udp type:"
+
TEST_STR
TEST_UNIX_DOMAIN_ADDR
string
=
"/tmp/frp_echo_server.sock"
TEST_UNIX_DOMAIN_FRP_PORT
int64
=
10803
TEST_UNIX_DOMAIN_STR
string
=
"unix domain type:"
+
TEST_STR
TEST_HTTP_PORT
int64
=
10704
TEST_HTTP_FRP_PORT
int64
=
10804
TEST_HTTP_WEB01_STR
string
=
"http web01:"
+
TEST_STR
TEST_HTTP_PORT
int64
=
10704
TEST_HTTP_FRP_PORT
int64
=
10804
TEST_HTTP_NORMAL_STR
string
=
"http normal string: "
+
TEST_STR
TEST_HTTP_FOO_STR
string
=
"http foo string: "
+
TEST_STR
TEST_HTTP_BAR_STR
string
=
"http bar string: "
+
TEST_STR
TEST_STCP_FRP_PORT
int64
=
10805
TEST_STCP_EC_FRP_PORT
int64
=
10905
TEST_STCP_ECHO_STR
string
=
"stcp type:"
+
TEST_STR
)
func
init
()
{
...
...
@@ -43,7 +43,7 @@ func init() {
time
.
Sleep
(
500
*
time
.
Millisecond
)
}
func
TestTcp
Server
(
t
*
testing
.
T
)
{
func
TestTcp
(
t
*
testing
.
T
)
{
assert
:=
assert
.
New
(
t
)
// Normal
addr
:=
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
TEST_TCP_FRP_PORT
)
...
...
@@ -58,7 +58,7 @@ func TestTcpServer(t *testing.T) {
assert
.
Equal
(
TEST_TCP_ECHO_STR
,
res
)
}
func
TestUdp
EchoServer
(
t
*
testing
.
T
)
{
func
TestUdp
(
t
*
testing
.
T
)
{
assert
:=
assert
.
New
(
t
)
// Normal
addr
:=
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
TEST_UDP_FRP_PORT
)
...
...
@@ -66,32 +66,92 @@ func TestUdpEchoServer(t *testing.T) {
assert
.
NoError
(
err
)
assert
.
Equal
(
TEST_UDP_ECHO_STR
,
res
)
func
TestUnixDomainServer
(
t
*
testing
.
T
)
{
// Encrytion and compression
addr
=
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
TEST_UDP_EC_FRP_PORT
)
res
,
err
=
sendUdpMsg
(
addr
,
TEST_UDP_ECHO_STR
)
assert
.
NoError
(
err
)
assert
.
Equal
(
TEST_UDP_ECHO_STR
,
res
)
}
func
TestUnixDomain
(
t
*
testing
.
T
)
{
assert
:=
assert
.
New
(
t
)
// Normal
addr
:=
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
TEST_UNIX_DOMAIN_FRP_PORT
)
res
,
err
:=
sendTcpMsg
(
addr
,
TEST_UNIX_DOMAIN_STR
)
assert
.
NoError
(
err
)
assert
.
Equal
(
TEST_UNIX_DOMAIN_STR
,
res
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
TEST_UNIX_DOMAIN_STR
,
res
)
}
}
func
TestStcp
(
t
*
testing
.
T
)
{
assert
:=
assert
.
New
(
t
)
// Normal
addr
:=
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
TEST_STCP_FRP_PORT
)
res
,
err
:=
sendTcpMsg
(
addr
,
TEST_STCP_ECHO_STR
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
TEST_STCP_ECHO_STR
,
res
)
}
// Encrytion and compression
addr
=
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
TEST_STCP_EC_FRP_PORT
)
res
,
err
=
sendTcpMsg
(
addr
,
TEST_STCP_ECHO_STR
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
TEST_STCP_ECHO_STR
,
res
)
}
}
func
TestHttpServer
(
t
*
testing
.
T
)
{
client
:=
&
http
.
Client
{}
req
,
_
:=
http
.
NewRequest
(
"GET"
,
fmt
.
Sprintf
(
"http://127.0.0.1:%d"
,
HTTP_PORT
),
nil
)
res
,
err
:=
client
.
Do
(
req
)
if
err
!=
nil
{
t
.
Fatalf
(
"do http request error: %v"
,
err
)
func
TestHttp
(
t
*
testing
.
T
)
{
assert
:=
assert
.
New
(
t
)
// web01
code
,
body
,
err
:=
sendHttpMsg
(
"GET"
,
fmt
.
Sprintf
(
"http://127.0.0.1:%d"
,
TEST_HTTP_FRP_PORT
),
""
,
nil
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
200
,
code
)
assert
.
Equal
(
TEST_HTTP_NORMAL_STR
,
body
)
}
// web02
code
,
body
,
err
=
sendHttpMsg
(
"GET"
,
fmt
.
Sprintf
(
"http://127.0.0.1:%d"
,
TEST_HTTP_FRP_PORT
),
"test2.frp.com"
,
nil
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
200
,
code
)
assert
.
Equal
(
TEST_HTTP_NORMAL_STR
,
body
)
}
// error host header
code
,
body
,
err
=
sendHttpMsg
(
"GET"
,
fmt
.
Sprintf
(
"http://127.0.0.1:%d"
,
TEST_HTTP_FRP_PORT
),
"errorhost.frp.com"
,
nil
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
404
,
code
)
}
// web03
code
,
body
,
err
=
sendHttpMsg
(
"GET"
,
fmt
.
Sprintf
(
"http://127.0.0.1:%d"
,
TEST_HTTP_FRP_PORT
),
"test3.frp.com"
,
nil
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
200
,
code
)
assert
.
Equal
(
TEST_HTTP_NORMAL_STR
,
body
)
}
if
res
.
StatusCode
==
200
{
body
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
if
err
!=
nil
{
t
.
Fatalf
(
"read from http server error: %v"
,
err
)
}
bodystr
:=
string
(
body
)
if
bodystr
!=
HTTP_RES_STR
{
t
.
Fatalf
(
"content from http server error [%s], correct string is [%s]"
,
bodystr
,
HTTP_RES_STR
)
}
}
else
{
t
.
Fatalf
(
"http code from http server error [%d]"
,
res
.
StatusCode
)
code
,
body
,
err
=
sendHttpMsg
(
"GET"
,
fmt
.
Sprintf
(
"http://127.0.0.1:%d/foo"
,
TEST_HTTP_FRP_PORT
),
"test3.frp.com"
,
nil
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
200
,
code
)
assert
.
Equal
(
TEST_HTTP_FOO_STR
,
body
)
}
// web04
code
,
body
,
err
=
sendHttpMsg
(
"GET"
,
fmt
.
Sprintf
(
"http://127.0.0.1:%d/bar"
,
TEST_HTTP_FRP_PORT
),
"test3.frp.com"
,
nil
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
200
,
code
)
assert
.
Equal
(
TEST_HTTP_BAR_STR
,
body
)
}
// web05
code
,
body
,
err
=
sendHttpMsg
(
"GET"
,
fmt
.
Sprintf
(
"http://127.0.0.1:%d"
,
TEST_HTTP_FRP_PORT
),
"test5.frp.com"
,
nil
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
401
,
code
)
}
header
:=
make
(
map
[
string
]
string
)
header
[
"Authorization"
]
=
basicAuth
(
"test"
,
"test"
)
code
,
body
,
err
=
sendHttpMsg
(
"GET"
,
fmt
.
Sprintf
(
"http://127.0.0.1:%d"
,
TEST_HTTP_FRP_PORT
),
"test5.frp.com"
,
header
)
if
assert
.
NoError
(
err
)
{
assert
.
Equal
(
401
,
code
)
}
}
tests/http_server.go
浏览文件 @
3bb404df
...
...
@@ -3,13 +3,30 @@ package tests
import
(
"fmt"
"net/http"
"strings"
)
func
StartHttpServer
()
{
http
.
HandleFunc
(
"/"
,
request
)
http
.
ListenAndServe
(
fmt
.
Sprintf
(
"0.0.0.0:%d"
,
10702
),
nil
)
http
.
ListenAndServe
(
fmt
.
Sprintf
(
"0.0.0.0:%d"
,
TEST_HTTP_PORT
),
nil
)
}
func
request
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Write
([]
byte
(
HTTP_RES_STR
))
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
)
w
.
Write
([]
byte
(
TEST_HTTP_NORMAL_STR
))
}
else
if
strings
.
Contains
(
r
.
Host
,
"test3.frp.com"
)
{
w
.
WriteHeader
(
200
)
if
strings
.
Contains
(
r
.
URL
.
Path
,
"foo"
)
{
w
.
Write
([]
byte
(
TEST_HTTP_FOO_STR
))
}
else
if
strings
.
Contains
(
r
.
URL
.
Path
,
"bar"
)
{
w
.
Write
([]
byte
(
TEST_HTTP_BAR_STR
))
}
else
{
w
.
Write
([]
byte
(
TEST_HTTP_NORMAL_STR
))
}
}
else
{
w
.
WriteHeader
(
404
)
}
return
}
tests/run_test.sh
浏览文件 @
3bb404df
...
...
@@ -3,6 +3,7 @@
./../bin/frps
-c
./conf/auto_test_frps.ini &
sleep
1
./../bin/frpc
-c
./conf/auto_test_frpc.ini &
./../bin/frpc
-c
./conf/auto_test_frpc_visitor.ini &
# wait until proxies are connected
sleep
2
tests/util.go
浏览文件 @
3bb404df
package
test
package
test
s
import
(
"encoding/base64"
"fmt"
"io/ioutil"
"net"
"net/http"
"time"
frpNet
"github.com/fatedier/frp/utils/net"
...
...
@@ -10,11 +13,11 @@ import (
func
sendTcpMsg
(
addr
string
,
msg
string
)
(
res
string
,
err
error
)
{
c
,
err
:=
frpNet
.
ConnectTcpServer
(
addr
)
defer
c
.
Close
()
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"connect to tcp server error: %v"
,
err
)
return
}
defer
c
.
Close
()
timer
:=
time
.
Now
()
.
Add
(
5
*
time
.
Second
)
c
.
SetDeadline
(
timer
)
...
...
@@ -55,3 +58,36 @@ func sendUdpMsg(addr string, msg string) (res string, err error) {
}
return
string
(
buf
[
:
n
]),
nil
}
func
sendHttpMsg
(
method
,
url
string
,
host
string
,
header
map
[
string
]
string
)
(
code
int
,
body
string
,
err
error
)
{
req
,
errRet
:=
http
.
NewRequest
(
method
,
url
,
nil
)
if
errRet
!=
nil
{
err
=
errRet
return
}
if
host
!=
""
{
req
.
Host
=
host
}
for
k
,
v
:=
range
header
{
req
.
Header
.
Set
(
k
,
v
)
}
resp
,
errRet
:=
http
.
DefaultClient
.
Do
(
req
)
if
errRet
!=
nil
{
err
=
errRet
return
}
code
=
resp
.
StatusCode
buf
,
errRet
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
errRet
!=
nil
{
err
=
errRet
return
}
body
=
string
(
buf
)
return
}
func
basicAuth
(
username
,
passwd
string
)
string
{
auth
:=
username
+
":"
+
passwd
return
"Basic "
+
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
auth
))
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录