@@ -1064,6 +1064,22 @@ func TestAuthSwitchOldPasswordNotAllowed(t *testing.T) {
1064
1064
}
1065
1065
}
1066
1066
1067
+ // Same to TestAuthSwitchOldPasswordNotAllowed, but use OldAuthSwitch request.
1068
+ func TestOldAuthSwitchNotAllowed (t * testing.T ) {
1069
+ conn , mc := newRWMockConn (2 )
1070
+
1071
+ // OldAuthSwitch request
1072
+ conn .data = []byte {1 , 0 , 0 , 2 , 0xfe }
1073
+ conn .maxReads = 1
1074
+ authData := []byte {95 , 84 , 103 , 43 , 61 , 49 , 123 , 61 , 91 , 50 , 40 , 113 , 35 ,
1075
+ 84 , 96 , 101 , 92 , 123 , 121 , 107 }
1076
+ plugin := "mysql_native_password"
1077
+ err := mc .handleAuthResult (authData , plugin )
1078
+ if err != ErrOldPassword {
1079
+ t .Errorf ("expected ErrOldPassword, got %v" , err )
1080
+ }
1081
+ }
1082
+
1067
1083
func TestAuthSwitchOldPassword (t * testing.T ) {
1068
1084
conn , mc := newRWMockConn (2 )
1069
1085
mc .cfg .AllowOldPasswords = true
@@ -1092,6 +1108,32 @@ func TestAuthSwitchOldPassword(t *testing.T) {
1092
1108
}
1093
1109
}
1094
1110
1111
+ // Same to TestAuthSwitchOldPassword, but use OldAuthSwitch request.
1112
+ func TestOldAuthSwitch (t * testing.T ) {
1113
+ conn , mc := newRWMockConn (2 )
1114
+ mc .cfg .AllowOldPasswords = true
1115
+ mc .cfg .Passwd = "secret"
1116
+
1117
+ // OldAuthSwitch request
1118
+ conn .data = []byte {1 , 0 , 0 , 2 , 0xfe }
1119
+
1120
+ // auth response
1121
+ conn .queuedReplies = [][]byte {{8 , 0 , 0 , 4 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 }}
1122
+ conn .maxReads = 2
1123
+
1124
+ authData := []byte {95 , 84 , 103 , 43 , 61 , 49 , 123 , 61 , 91 , 50 , 40 , 113 , 35 ,
1125
+ 84 , 96 , 101 , 92 , 123 , 121 , 107 }
1126
+ plugin := "mysql_native_password"
1127
+
1128
+ if err := mc .handleAuthResult (authData , plugin ); err != nil {
1129
+ t .Errorf ("got error: %v" , err )
1130
+ }
1131
+
1132
+ expectedReply := []byte {9 , 0 , 0 , 3 , 86 , 83 , 83 , 79 , 74 , 78 , 65 , 66 , 0 }
1133
+ if ! bytes .Equal (conn .written , expectedReply ) {
1134
+ t .Errorf ("got unexpected data: %v" , conn .written )
1135
+ }
1136
+ }
1095
1137
func TestAuthSwitchOldPasswordEmpty (t * testing.T ) {
1096
1138
conn , mc := newRWMockConn (2 )
1097
1139
mc .cfg .AllowOldPasswords = true
@@ -1120,6 +1162,33 @@ func TestAuthSwitchOldPasswordEmpty(t *testing.T) {
1120
1162
}
1121
1163
}
1122
1164
1165
+ // Same to TestAuthSwitchOldPasswordEmpty, but use OldAuthSwitch request.
1166
+ func TestOldAuthSwitchPasswordEmpty (t * testing.T ) {
1167
+ conn , mc := newRWMockConn (2 )
1168
+ mc .cfg .AllowOldPasswords = true
1169
+ mc .cfg .Passwd = ""
1170
+
1171
+ // OldAuthSwitch request.
1172
+ conn .data = []byte {1 , 0 , 0 , 2 , 0xfe }
1173
+
1174
+ // auth response
1175
+ conn .queuedReplies = [][]byte {{8 , 0 , 0 , 4 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 }}
1176
+ conn .maxReads = 2
1177
+
1178
+ authData := []byte {95 , 84 , 103 , 43 , 61 , 49 , 123 , 61 , 91 , 50 , 40 , 113 , 35 ,
1179
+ 84 , 96 , 101 , 92 , 123 , 121 , 107 }
1180
+ plugin := "mysql_native_password"
1181
+
1182
+ if err := mc .handleAuthResult (authData , plugin ); err != nil {
1183
+ t .Errorf ("got error: %v" , err )
1184
+ }
1185
+
1186
+ expectedReply := []byte {1 , 0 , 0 , 3 , 0 }
1187
+ if ! bytes .Equal (conn .written , expectedReply ) {
1188
+ t .Errorf ("got unexpected data: %v" , conn .written )
1189
+ }
1190
+ }
1191
+
1123
1192
func TestAuthSwitchSHA256PasswordEmpty (t * testing.T ) {
1124
1193
conn , mc := newRWMockConn (2 )
1125
1194
mc .cfg .Passwd = ""
0 commit comments