(t *testing.T)
| 531 | } |
| 532 | |
| 533 | func TestAuthFastSHA256PasswordEmpty(t *testing.T) { |
| 534 | conn, mc := newRWMockConn(1) |
| 535 | mc.cfg.User = "root" |
| 536 | mc.cfg.Passwd = "" |
| 537 | |
| 538 | authData := []byte{6, 81, 96, 114, 14, 42, 50, 30, 76, 47, 1, 95, 126, 81, |
| 539 | 62, 94, 83, 80, 52, 85} |
| 540 | plugin := "sha256_password" |
| 541 | |
| 542 | // Send Client Authentication Packet |
| 543 | authResp, err := mc.auth(authData, plugin) |
| 544 | if err != nil { |
| 545 | t.Fatal(err) |
| 546 | } |
| 547 | err = mc.writeHandshakeResponsePacket(authResp, plugin) |
| 548 | if err != nil { |
| 549 | t.Fatal(err) |
| 550 | } |
| 551 | |
| 552 | // check written auth response |
| 553 | authRespStart := 4 + 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1 |
| 554 | authRespEnd := authRespStart + 1 + len(authResp) |
| 555 | writtenAuthRespLen := conn.written[authRespStart] |
| 556 | writtenAuthResp := conn.written[authRespStart+1 : authRespEnd] |
| 557 | expectedAuthResp := []byte{0} |
| 558 | if writtenAuthRespLen != 1 || !bytes.Equal(writtenAuthResp, expectedAuthResp) { |
| 559 | t.Fatalf("unexpected written auth response (%d bytes): %v", writtenAuthRespLen, writtenAuthResp) |
| 560 | } |
| 561 | conn.written = nil |
| 562 | |
| 563 | // auth response (pub key response) |
| 564 | conn.data = append([]byte{byte(1 + len(testPubKey)), 1, 0, 2, 1}, testPubKey...) |
| 565 | conn.queuedReplies = [][]byte{ |
| 566 | // OK |
| 567 | {7, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0}, |
| 568 | } |
| 569 | conn.maxReads = 2 |
| 570 | |
| 571 | // Handle response to auth packet |
| 572 | if err := mc.handleAuthResult(authData, plugin); err != nil { |
| 573 | t.Errorf("got error: %v", err) |
| 574 | } |
| 575 | |
| 576 | if !bytes.HasPrefix(conn.written, []byte{0, 1, 0, 3}) { |
| 577 | t.Errorf("unexpected written data: %v", conn.written) |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | func TestAuthFastSHA256PasswordRSA(t *testing.T) { |
| 582 | conn, mc := newRWMockConn(1) |
nothing calls this directly
no test coverage detected