Skip to content

Commit

Permalink
packets: add regression test for mysqljs#801 (mysqljs#802)
Browse files Browse the repository at this point in the history
Updates mysqljs#801
  • Loading branch information
julienschmidt authored May 23, 2018
1 parent 5afaf12 commit 44c24df
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package mysql

import (
"bytes"
"errors"
"net"
"testing"
Expand Down Expand Up @@ -280,3 +281,37 @@ func TestReadPacketFail(t *testing.T) {
t.Errorf("expected ErrInvalidConn, got %v", err)
}
}

// https://github.com/go-sql-driver/mysql/pull/801
// not-NUL terminated plugin_name in init packet
func TestRegression801(t *testing.T) {
conn := new(mockConn)
mc := &mysqlConn{
buf: newBuffer(conn),
cfg: new(Config),
sequence: 42,
closech: make(chan struct{}),
}

conn.data = []byte{72, 0, 0, 42, 10, 53, 46, 53, 46, 56, 0, 165, 0, 0, 0,
60, 70, 63, 58, 68, 104, 34, 97, 0, 223, 247, 33, 2, 0, 15, 128, 21, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 98, 120, 114, 47, 85, 75, 109, 99, 51, 77,
50, 64, 0, 109, 121, 115, 113, 108, 95, 110, 97, 116, 105, 118, 101, 95,
112, 97, 115, 115, 119, 111, 114, 100}
conn.maxReads = 1

authData, pluginName, err := mc.readInitPacket()
if err != nil {
t.Fatalf("got error: %v", err)
}

if pluginName != "mysql_native_password" {
t.Errorf("expected plugin name 'mysql_native_password', got '%s'", pluginName)
}

expectedAuthData := []byte{60, 70, 63, 58, 68, 104, 34, 97, 98, 120, 114,
47, 85, 75, 109, 99, 51, 77, 50, 64}
if !bytes.Equal(authData, expectedAuthData) {
t.Errorf("expected authData '%v', got '%v'", expectedAuthData, authData)
}
}

0 comments on commit 44c24df

Please sign in to comment.