mirror of https://github.com/cbeuw/Cloak
Integration tests
This commit is contained in:
parent
0f66fec28e
commit
2bf7df0eb0
|
|
@ -57,6 +57,7 @@ func dispatchConnection(conn net.Conn, sta *State) {
|
||||||
_, err = webConn.Write(data)
|
_, err = webConn.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to send first packet to redirection server", err)
|
log.Error("Failed to send first packet to redirection server", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
go io.Copy(webConn, conn)
|
go io.Copy(webConn, conn)
|
||||||
go io.Copy(conn, webConn)
|
go io.Copy(conn, webConn)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"github.com/cbeuw/Cloak/internal/common"
|
"github.com/cbeuw/Cloak/internal/common"
|
||||||
mux "github.com/cbeuw/Cloak/internal/multiplex"
|
mux "github.com/cbeuw/Cloak/internal/multiplex"
|
||||||
"github.com/cbeuw/Cloak/internal/server"
|
"github.com/cbeuw/Cloak/internal/server"
|
||||||
"github.com/cbeuw/Cloak/internal/server/usermanager"
|
|
||||||
"github.com/cbeuw/connutil"
|
"github.com/cbeuw/connutil"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
@ -57,27 +56,31 @@ func basicClientConfigs(state common.WorldState) (client.LocalConnConfig, client
|
||||||
LocalHost: "127.0.0.1",
|
LocalHost: "127.0.0.1",
|
||||||
LocalPort: "9999",
|
LocalPort: "9999",
|
||||||
}
|
}
|
||||||
lcl, rmt, auth, _ := clientConfig.SplitConfigs(state)
|
lcl, rmt, auth, err := clientConfig.SplitConfigs(state)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
return lcl, rmt, auth
|
return lcl, rmt, auth
|
||||||
}
|
}
|
||||||
|
|
||||||
func basicServerState(ws common.WorldState, db *os.File) *server.State {
|
func basicServerState(ws common.WorldState, db *os.File) *server.State {
|
||||||
manager, _ := usermanager.MakeLocalManager(db.Name())
|
var serverConfig = server.RawConfig{
|
||||||
var pv [32]byte
|
ProxyBook: map[string][]string{"test": {"tcp", "fake.com:9999"}},
|
||||||
copy(pv[:], privateKey)
|
BindAddr: []string{"fake.com:9999"},
|
||||||
serverState := &server.State{
|
BypassUID: [][]byte{bypassUID[:]},
|
||||||
ProxyBook: map[string]net.Addr{"test": &net.TCPAddr{}},
|
RedirAddr: "fake.com:9999",
|
||||||
UsedRandom: map[[32]byte]int64{},
|
PrivateKey: privateKey,
|
||||||
Timeout: 0,
|
AdminUID: nil,
|
||||||
BypassUID: map[[16]byte]struct{}{bypassUID: {}},
|
DatabasePath: db.Name(),
|
||||||
RedirHost: &net.TCPAddr{},
|
StreamTimeout: 300,
|
||||||
RedirPort: "9999",
|
KeepAlive: 15,
|
||||||
Panel: server.MakeUserPanel(manager),
|
CncMode: false,
|
||||||
LocalAPIRouter: nil,
|
|
||||||
StaticPv: &pv,
|
|
||||||
WorldState: ws,
|
|
||||||
}
|
}
|
||||||
return serverState
|
state, err := server.InitState(serverConfig, ws)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
func establishSession(lcc client.LocalConnConfig, rcc client.RemoteConnConfig, ai client.AuthInfo, serverState *server.State) (common.Dialer, net.Listener, common.Dialer, net.Listener, error) {
|
func establishSession(lcc client.LocalConnConfig, rcc client.RemoteConnConfig, ai client.AuthInfo, serverState *server.State) (common.Dialer, net.Listener, common.Dialer, net.Listener, error) {
|
||||||
|
|
@ -103,11 +106,11 @@ func establishSession(lcc client.LocalConnConfig, rcc client.RemoteConnConfig, a
|
||||||
}
|
}
|
||||||
|
|
||||||
func runEchoTest(t *testing.T, conns []net.Conn) {
|
func runEchoTest(t *testing.T, conns []net.Conn) {
|
||||||
const testDataLen = 16384
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, conn := range conns {
|
for _, conn := range conns {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(conn net.Conn) {
|
go func(conn net.Conn) {
|
||||||
|
testDataLen := rand.Intn(65536)
|
||||||
testData := make([]byte, testDataLen)
|
testData := make([]byte, testDataLen)
|
||||||
rand.Read(testData)
|
rand.Read(testData)
|
||||||
|
|
||||||
|
|
@ -134,7 +137,7 @@ func runEchoTest(t *testing.T, conns []net.Conn) {
|
||||||
func TestTCP(t *testing.T) {
|
func TestTCP(t *testing.T) {
|
||||||
var tmpDB, _ = ioutil.TempFile("", "ck_user_info")
|
var tmpDB, _ = ioutil.TempFile("", "ck_user_info")
|
||||||
defer os.Remove(tmpDB.Name())
|
defer os.Remove(tmpDB.Name())
|
||||||
log.SetOutput(ioutil.Discard)
|
log.SetLevel(log.FatalLevel)
|
||||||
|
|
||||||
worldState := common.WorldOfTime(time.Unix(10, 0))
|
worldState := common.WorldOfTime(time.Unix(10, 0))
|
||||||
lcc, rcc, ai := basicClientConfigs(worldState)
|
lcc, rcc, ai := basicClientConfigs(worldState)
|
||||||
|
|
@ -172,3 +175,38 @@ func TestTCP(t *testing.T) {
|
||||||
runEchoTest(t, conns[:])
|
runEchoTest(t, conns[:])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClosingStreamsFromProxy(t *testing.T) {
|
||||||
|
var tmpDB, _ = ioutil.TempFile("", "ck_user_info")
|
||||||
|
defer os.Remove(tmpDB.Name())
|
||||||
|
log.SetLevel(log.FatalLevel)
|
||||||
|
worldState := common.WorldOfTime(time.Unix(10, 0))
|
||||||
|
lcc, rcc, ai := basicClientConfigs(worldState)
|
||||||
|
sta := basicServerState(worldState, tmpDB)
|
||||||
|
pxyClientD, pxyServerL, _, _, err := establishSession(lcc, rcc, ai, sta)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// closing stream on server side
|
||||||
|
clientConn, _ := pxyClientD.Dial("", "")
|
||||||
|
clientConn.Write(make([]byte, 16))
|
||||||
|
serverConn, _ := pxyServerL.Accept()
|
||||||
|
serverConn.Close()
|
||||||
|
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
if _, err := clientConn.Read(make([]byte, 16)); err == nil {
|
||||||
|
t.Errorf("closing stream on server side is not reflected to the client: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// closing stream on client side
|
||||||
|
clientConn, _ = pxyClientD.Dial("", "")
|
||||||
|
clientConn.Write(make([]byte, 16))
|
||||||
|
serverConn, _ = pxyServerL.Accept()
|
||||||
|
clientConn.Close()
|
||||||
|
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
if _, err := serverConn.Read(make([]byte, 16)); err == nil {
|
||||||
|
t.Errorf("closing stream on client side is not reflected to the server: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1 @@
|
||||||
package test
|
package test
|
||||||
|
|
||||||
func blah() {}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue