@@ -53,6 +53,76 @@ func TestDecodeFirstPart(t *testing.T) {
53
53
}
54
54
}
55
55
56
+ func TestReadPluginName (t * testing.T ) {
57
+ // example data from
58
+ // https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse41
59
+ mysqlNativePassword := []byte {
60
+ 0x54 , 0x00 , 0x00 , 0x01 , 0x8d , 0xa6 , 0x0f , 0x00 , 0x00 , 0x00 , 0x00 ,
61
+ 0x01 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
62
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
63
+ 0x00 , 0x00 , 0x00 , 0x70 , 0x61 , 0x6d , 0x00 , 0x14 , 0xab , 0x09 , 0xee ,
64
+ 0xf6 , 0xbc , 0xb1 , 0x32 , 0x3e , 0x61 , 0x14 , 0x38 , 0x65 , 0xc0 , 0x99 ,
65
+ 0x1d , 0x95 , 0x7d , 0x75 , 0xd4 , 0x47 , 0x74 , 0x65 , 0x73 , 0x74 , 0x00 ,
66
+ 0x6d , 0x79 , 0x73 , 0x71 , 0x6c , 0x5f , 0x6e , 0x61 , 0x74 , 0x69 , 0x76 ,
67
+ 0x65 , 0x5f , 0x70 , 0x61 , 0x73 , 0x73 , 0x77 , 0x6f , 0x72 , 0x64 , 0x00 ,
68
+ }
69
+
70
+ // altered example data so it has different auth plugin
71
+ otherPlugin := []byte {
72
+ 0x54 , 0x00 , 0x00 , 0x01 , 0x8d , 0xa6 , 0x0f , 0x00 , 0x00 , 0x00 , 0x00 ,
73
+ 0x01 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
74
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
75
+ 0x00 , 0x00 , 0x00 , 0x70 , 0x61 , 0x6d , 0x00 , 0x14 , 0xab , 0x09 , 0xee ,
76
+ 0xf6 , 0xbc , 0xb1 , 0x32 , 0x3e , 0x61 , 0x14 , 0x38 , 0x65 , 0xc0 , 0x99 ,
77
+ 0x1d , 0x95 , 0x7d , 0x75 , 0xd4 , 0x47 , 0x74 , 0x65 , 0x73 , 0x74 , 0x00 ,
78
+ 0x66 , 0x6f , 0x6f , 0x62 , 0x61 , 0x72 , 0x00 ,
79
+ }
80
+
81
+ t .Run ("mysql_native_password from plugin name" , func (t * testing.T ) {
82
+ c := & Conn {}
83
+ c .SetCapability (mysql .CLIENT_PLUGIN_AUTH )
84
+ pos := 66
85
+
86
+ pos = c .readPluginName (mysqlNativePassword , pos )
87
+ if pos != 88 {
88
+ t .Fatalf ("unexpected pos, got %d" , pos )
89
+ }
90
+
91
+ if c .authPluginName != "mysql_native_password" {
92
+ t .Fatalf ("unexpected plugin name, got %s" , c .authPluginName )
93
+ }
94
+ })
95
+
96
+ t .Run ("other plugin" , func (t * testing.T ) {
97
+ c := & Conn {}
98
+ c .SetCapability (mysql .CLIENT_PLUGIN_AUTH )
99
+ pos := 66
100
+
101
+ pos = c .readPluginName (otherPlugin , pos )
102
+ if pos != 73 {
103
+ t .Fatalf ("unexpected pos, got %d" , pos )
104
+ }
105
+
106
+ if c .authPluginName != "foobar" {
107
+ t .Fatalf ("unexpected plugin name, got %s" , c .authPluginName )
108
+ }
109
+ })
110
+
111
+ t .Run ("mysql_native_password as default" , func (t * testing.T ) {
112
+ c := & Conn {}
113
+ pos := 123 // can be anything
114
+
115
+ pos = c .readPluginName (mysqlNativePassword , pos )
116
+ if pos != 123 {
117
+ t .Fatalf ("unexpected pos, got %d" , pos )
118
+ }
119
+
120
+ if c .authPluginName != mysql .AUTH_NATIVE_PASSWORD {
121
+ t .Fatalf ("unexpected plugin name, got %s" , c .authPluginName )
122
+ }
123
+ })
124
+ }
125
+
56
126
func TestReadAttributes (t * testing.T ) {
57
127
var err error
58
128
// example data from
0 commit comments