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

Function TestAuthFastCleartextPasswordEmpty

auth_test.go:388–429  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

386}
387
388func TestAuthFastCleartextPasswordEmpty(t *testing.T) {
389 conn, mc := newRWMockConn(1)
390 mc.cfg.User = "root"
391 mc.cfg.Passwd = ""
392 mc.cfg.AllowCleartextPasswords = true
393
394 authData := []byte{70, 114, 92, 94, 1, 38, 11, 116, 63, 114, 23, 101, 126,
395 103, 26, 95, 81, 17, 24, 21}
396 plugin := "mysql_clear_password"
397
398 // Send Client Authentication Packet
399 authResp, err := mc.auth(authData, plugin)
400 if err != nil {
401 t.Fatal(err)
402 }
403 err = mc.writeHandshakeResponsePacket(authResp, plugin)
404 if err != nil {
405 t.Fatal(err)
406 }
407
408 // check written auth response
409 authRespStart := 4 + 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1
410 authRespEnd := authRespStart + 1 + len(authResp)
411 writtenAuthRespLen := conn.written[authRespStart]
412 writtenAuthResp := conn.written[authRespStart+1 : authRespEnd]
413 expectedAuthResp := []byte{0}
414 if writtenAuthRespLen != 1 || !bytes.Equal(writtenAuthResp, expectedAuthResp) {
415 t.Fatalf("unexpected written auth response (%d bytes): %v", writtenAuthRespLen, writtenAuthResp)
416 }
417 conn.written = nil
418
419 // auth response
420 conn.data = []byte{
421 7, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, // OK
422 }
423 conn.maxReads = 1
424
425 // Handle response to auth packet
426 if err := mc.handleAuthResult(authData, plugin); err != nil {
427 t.Errorf("got error: %v", err)
428 }
429}
430
431func TestAuthFastNativePasswordNotAllowed(t *testing.T) {
432 _, 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