(t *testing.T)
| 343 | } |
| 344 | |
| 345 | func TestAuthFastCleartextPassword(t *testing.T) { |
| 346 | conn, mc := newRWMockConn(1) |
| 347 | mc.cfg.User = "root" |
| 348 | mc.cfg.Passwd = "secret" |
| 349 | mc.cfg.AllowCleartextPasswords = true |
| 350 | |
| 351 | authData := []byte{70, 114, 92, 94, 1, 38, 11, 116, 63, 114, 23, 101, 126, |
| 352 | 103, 26, 95, 81, 17, 24, 21} |
| 353 | plugin := "mysql_clear_password" |
| 354 | |
| 355 | // Send Client Authentication Packet |
| 356 | authResp, err := mc.auth(authData, plugin) |
| 357 | if err != nil { |
| 358 | t.Fatal(err) |
| 359 | } |
| 360 | err = mc.writeHandshakeResponsePacket(authResp, plugin) |
| 361 | if err != nil { |
| 362 | t.Fatal(err) |
| 363 | } |
| 364 | |
| 365 | // check written auth response |
| 366 | authRespStart := 4 + 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1 |
| 367 | authRespEnd := authRespStart + 1 + len(authResp) |
| 368 | writtenAuthRespLen := conn.written[authRespStart] |
| 369 | writtenAuthResp := conn.written[authRespStart+1 : authRespEnd] |
| 370 | expectedAuthResp := []byte{115, 101, 99, 114, 101, 116, 0} |
| 371 | if writtenAuthRespLen != 7 || !bytes.Equal(writtenAuthResp, expectedAuthResp) { |
| 372 | t.Fatalf("unexpected written auth response (%d bytes): %v", writtenAuthRespLen, writtenAuthResp) |
| 373 | } |
| 374 | conn.written = nil |
| 375 | |
| 376 | // auth response |
| 377 | conn.data = []byte{ |
| 378 | 7, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, // OK |
| 379 | } |
| 380 | conn.maxReads = 1 |
| 381 | |
| 382 | // Handle response to auth packet |
| 383 | if err := mc.handleAuthResult(authData, plugin); err != nil { |
| 384 | t.Errorf("got error: %v", err) |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | func TestAuthFastCleartextPasswordEmpty(t *testing.T) { |
| 389 | conn, mc := newRWMockConn(1) |
nothing calls this directly
no test coverage detected