Skip to content

Commit 8c82535

Browse files
committed
Revert "Revert "re-implement TestRegression801""
This reverts commit 198f0bf.
1 parent 4a07d42 commit 8c82535

File tree

1 file changed

+30
-33
lines changed

1 file changed

+30
-33
lines changed

packets_test.go

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package mysql
1010

1111
import (
12+
"bytes"
1213
"context"
1314
"io"
1415
"net"
@@ -272,36 +273,32 @@ func TestReadPacketFail(t *testing.T) {
272273
})
273274
}
274275

275-
// // https://github.com/go-sql-driver/mysql/pull/801
276-
// // not-NUL terminated plugin_name in init packet
277-
// func TestRegression801(t *testing.T) {
278-
// conn := new(mockConn)
279-
// mc := &mysqlConn{
280-
// buf: newBuffer(conn),
281-
// cfg: new(Config),
282-
// sequence: 42,
283-
// closech: make(chan struct{}),
284-
// }
285-
286-
// conn.data = []byte{72, 0, 0, 42, 10, 53, 46, 53, 46, 56, 0, 165, 0, 0, 0,
287-
// 60, 70, 63, 58, 68, 104, 34, 97, 0, 223, 247, 33, 2, 0, 15, 128, 21, 0,
288-
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 98, 120, 114, 47, 85, 75, 109, 99, 51, 77,
289-
// 50, 64, 0, 109, 121, 115, 113, 108, 95, 110, 97, 116, 105, 118, 101, 95,
290-
// 112, 97, 115, 115, 119, 111, 114, 100}
291-
// conn.maxReads = 1
292-
293-
// authData, pluginName, err := mc.readHandshakePacket()
294-
// if err != nil {
295-
// t.Fatalf("got error: %v", err)
296-
// }
297-
298-
// if pluginName != "mysql_native_password" {
299-
// t.Errorf("expected plugin name 'mysql_native_password', got '%s'", pluginName)
300-
// }
301-
302-
// expectedAuthData := []byte{60, 70, 63, 58, 68, 104, 34, 97, 98, 120, 114,
303-
// 47, 85, 75, 109, 99, 51, 77, 50, 64}
304-
// if !bytes.Equal(authData, expectedAuthData) {
305-
// t.Errorf("expected authData '%v', got '%v'", expectedAuthData, authData)
306-
// }
307-
// }
276+
// https://github.com/go-sql-driver/mysql/pull/801
277+
// not-NUL terminated plugin_name in init packet
278+
func TestRegression801(t *testing.T) {
279+
conn, mc := newRWMockConn(t, 42)
280+
281+
go func() {
282+
conn.Write([]byte{72, 0, 0, 42, 10, 53, 46, 53, 46, 56, 0, 165, 0, 0, 0,
283+
60, 70, 63, 58, 68, 104, 34, 97, 0, 223, 247, 33, 2, 0, 15, 128, 21, 0,
284+
0, 0, 0, 0, 0, 0, 0, 0, 0, 98, 120, 114, 47, 85, 75, 109, 99, 51, 77,
285+
50, 64, 0, 109, 121, 115, 113, 108, 95, 110, 97, 116, 105, 118, 101, 95,
286+
112, 97, 115, 115, 119, 111, 114, 100})
287+
conn.Close()
288+
}()
289+
290+
authData, pluginName, err := mc.readHandshakePacket(context.Background())
291+
if err != nil {
292+
t.Fatalf("got error: %v", err)
293+
}
294+
295+
if pluginName != "mysql_native_password" {
296+
t.Errorf("expected plugin name 'mysql_native_password', got '%s'", pluginName)
297+
}
298+
299+
expectedAuthData := []byte{60, 70, 63, 58, 68, 104, 34, 97, 98, 120, 114,
300+
47, 85, 75, 109, 99, 51, 77, 50, 64}
301+
if !bytes.Equal(authData, expectedAuthData) {
302+
t.Errorf("expected authData '%v', got '%v'", expectedAuthData, authData)
303+
}
304+
}

0 commit comments

Comments
 (0)