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

Function TestAuthFastCleartextPassword

auth_test.go:345–386  ·  auth_test.go::TestAuthFastCleartextPassword
(t *testing.T)

Source from the content-addressed store, hash-verified

343}
344
345func 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
388func TestAuthFastCleartextPasswordEmpty(t *testing.T) {
389 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