(t *testing.T)
| 579 | } |
| 580 | |
| 581 | func TestAuthFastSHA256PasswordRSA(t *testing.T) { |
| 582 | conn, mc := newRWMockConn(1) |
| 583 | mc.cfg.User = "root" |
| 584 | mc.cfg.Passwd = "secret" |
| 585 | |
| 586 | authData := []byte{6, 81, 96, 114, 14, 42, 50, 30, 76, 47, 1, 95, 126, 81, |
| 587 | 62, 94, 83, 80, 52, 85} |
| 588 | plugin := "sha256_password" |
| 589 | |
| 590 | // Send Client Authentication Packet |
| 591 | authResp, err := mc.auth(authData, plugin) |
| 592 | if err != nil { |
| 593 | t.Fatal(err) |
| 594 | } |
| 595 | err = mc.writeHandshakeResponsePacket(authResp, plugin) |
| 596 | if err != nil { |
| 597 | t.Fatal(err) |
| 598 | } |
| 599 | |
| 600 | // check written auth response |
| 601 | authRespStart := 4 + 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1 |
| 602 | authRespEnd := authRespStart + 1 + len(authResp) |
| 603 | writtenAuthRespLen := conn.written[authRespStart] |
| 604 | writtenAuthResp := conn.written[authRespStart+1 : authRespEnd] |
| 605 | expectedAuthResp := []byte{1} |
| 606 | if writtenAuthRespLen != 1 || !bytes.Equal(writtenAuthResp, expectedAuthResp) { |
| 607 | t.Fatalf("unexpected written auth response (%d bytes): %v", writtenAuthRespLen, writtenAuthResp) |
| 608 | } |
| 609 | conn.written = nil |
| 610 | |
| 611 | // auth response (pub key response) |
| 612 | conn.data = append([]byte{byte(1 + len(testPubKey)), 1, 0, 2, 1}, testPubKey...) |
| 613 | conn.queuedReplies = [][]byte{ |
| 614 | // OK |
| 615 | {7, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0}, |
| 616 | } |
| 617 | conn.maxReads = 2 |
| 618 | |
| 619 | // Handle response to auth packet |
| 620 | if err := mc.handleAuthResult(authData, plugin); err != nil { |
| 621 | t.Errorf("got error: %v", err) |
| 622 | } |
| 623 | |
| 624 | if !bytes.HasPrefix(conn.written, []byte{0, 1, 0, 3}) { |
| 625 | t.Errorf("unexpected written data: %v", conn.written) |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | func TestAuthFastSHA256PasswordRSAWithKey(t *testing.T) { |
| 630 | conn, mc := newRWMockConn(1) |
nothing calls this directly
no test coverage detected