MCPcopy
hub / github.com/go-sql-driver/mysql / TestAuthFastNativePassword

Function TestAuthFastNativePassword

auth_test.go:448–489  ·  auth_test.go::TestAuthFastNativePassword
(t *testing.T)

Source from the content-addressed store, hash-verified

446}
447
448func TestAuthFastNativePassword(t *testing.T) {
449 conn, mc := newRWMockConn(1)
450 mc.cfg.User = "root"
451 mc.cfg.Passwd = "secret"
452
453 authData := []byte{70, 114, 92, 94, 1, 38, 11, 116, 63, 114, 23, 101, 126,
454 103, 26, 95, 81, 17, 24, 21}
455 plugin := "mysql_native_password"
456
457 // Send Client Authentication Packet
458 authResp, err := mc.auth(authData, plugin)
459 if err != nil {
460 t.Fatal(err)
461 }
462 err = mc.writeHandshakeResponsePacket(authResp, plugin)
463 if err != nil {
464 t.Fatal(err)
465 }
466
467 // check written auth response
468 authRespStart := 4 + 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1
469 authRespEnd := authRespStart + 1 + len(authResp)
470 writtenAuthRespLen := conn.written[authRespStart]
471 writtenAuthResp := conn.written[authRespStart+1 : authRespEnd]
472 expectedAuthResp := []byte{53, 177, 140, 159, 251, 189, 127, 53, 109, 252,
473 172, 50, 211, 192, 240, 164, 26, 48, 207, 45}
474 if writtenAuthRespLen != 20 || !bytes.Equal(writtenAuthResp, expectedAuthResp) {
475 t.Fatalf("unexpected written auth response (%d bytes): %v", writtenAuthRespLen, writtenAuthResp)
476 }
477 conn.written = nil
478
479 // auth response
480 conn.data = []byte{
481 7, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, // OK
482 }
483 conn.maxReads = 1
484
485 // Handle response to auth packet
486 if err := mc.handleAuthResult(authData, plugin); err != nil {
487 t.Errorf("got error: %v", err)
488 }
489}
490
491func TestAuthFastNativePasswordEmpty(t *testing.T) {
492 conn, mc := newRWMockConn(1)

Callers

nothing calls this directly

Calls 4

newRWMockConnFunction · 0.85
authMethod · 0.80
handleAuthResultMethod · 0.80

Tested by

no test coverage detected