tor: fix msg order in TestReconnectSucceed
This commit is contained in:
1 file changed
+19
-18
+19
-18
@@ -319,14 +319,20 @@ func TestReconnectSucceed(t *testing.T) {
|
|||||||
// Close the old conn before reconnection.
|
// Close the old conn before reconnection.
|
||||||
require.NoError(t, proxy.serverConn.Close())
|
require.NoError(t, proxy.serverConn.Close())
|
||||||
|
|
||||||
// Accept the connection inside a goroutine. We will also write some
|
// Accept the connection inside a goroutine. When the client makes a
|
||||||
// data so that the reconnection can succeed. We will mock three writes
|
// reconnection, the messages flow is,
|
||||||
// and two reads inside our proxy server,
|
// 1. the client sends the command PROTOCOLINFO to the server.
|
||||||
// - write protocol info
|
// 2. the server responds with its protocol version.
|
||||||
// - read auth info
|
// 3. the client reads the response and sends the command AUTHENTICATE
|
||||||
// - write auth challenge
|
// to the server
|
||||||
// - read auth challenge
|
// 4. the server responds with the authentication info.
|
||||||
// - write OK
|
//
|
||||||
|
// From the server's PoV, We need to mock two reads and two writes
|
||||||
|
// inside the connection,
|
||||||
|
// 1. read the command PROTOCOLINFO sent from the client.
|
||||||
|
// 2. write protocol info so the client can read it.
|
||||||
|
// 3. read the command AUTHENTICATE sent from the client.
|
||||||
|
// 4. write auth challenge so the client can read it.
|
||||||
go func() {
|
go func() {
|
||||||
// Accept the new connection.
|
// Accept the new connection.
|
||||||
server, err := proxy.server.Accept()
|
server, err := proxy.server.Accept()
|
||||||
@@ -335,6 +341,11 @@ func TestReconnectSucceed(t *testing.T) {
|
|||||||
t.Logf("server listening on %v, client listening on %v",
|
t.Logf("server listening on %v, client listening on %v",
|
||||||
server.LocalAddr(), server.RemoteAddr())
|
server.LocalAddr(), server.RemoteAddr())
|
||||||
|
|
||||||
|
// Read the protocol command from the client.
|
||||||
|
buf := make([]byte, 65535)
|
||||||
|
_, err = server.Read(buf)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Write the protocol info.
|
// Write the protocol info.
|
||||||
resp := "250-PROTOCOLINFO 1\n" +
|
resp := "250-PROTOCOLINFO 1\n" +
|
||||||
"250-AUTH METHODS=NULL\n" +
|
"250-AUTH METHODS=NULL\n" +
|
||||||
@@ -343,7 +354,6 @@ func TestReconnectSucceed(t *testing.T) {
|
|||||||
require.NoErrorf(t, err, "failed to write protocol info")
|
require.NoErrorf(t, err, "failed to write protocol info")
|
||||||
|
|
||||||
// Read the auth info from the client.
|
// Read the auth info from the client.
|
||||||
buf := make([]byte, 65535)
|
|
||||||
_, err = server.Read(buf)
|
_, err = server.Read(buf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -351,15 +361,6 @@ func TestReconnectSucceed(t *testing.T) {
|
|||||||
resp = "250 AUTHCHALLENGE SERVERHASH=fake\n"
|
resp = "250 AUTHCHALLENGE SERVERHASH=fake\n"
|
||||||
_, err = server.Write([]byte(resp))
|
_, err = server.Write([]byte(resp))
|
||||||
require.NoErrorf(t, err, "failed to write auth challenge")
|
require.NoErrorf(t, err, "failed to write auth challenge")
|
||||||
|
|
||||||
// Read the auth challenge resp from the client.
|
|
||||||
_, err = server.Read(buf)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Write OK resp.
|
|
||||||
resp = "250 OK\n"
|
|
||||||
_, err = server.Write([]byte(resp))
|
|
||||||
require.NoErrorf(t, err, "failed to write response auth")
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Reconnect should succeed.
|
// Reconnect should succeed.
|
||||||
|
|||||||
Reference in new issue
Block a user