|
9 | 9 | package mysql
|
10 | 10 |
|
11 | 11 | import (
|
| 12 | + "bytes" |
12 | 13 | "context"
|
13 | 14 | "io"
|
14 | 15 | "net"
|
@@ -272,36 +273,32 @@ func TestReadPacketFail(t *testing.T) {
|
272 | 273 | })
|
273 | 274 | }
|
274 | 275 |
|
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