@@ -55,8 +55,8 @@ FakeConnection.prototype.handshake = function(options) {
55
55
this . _handshakeOptions = options || { } ;
56
56
57
57
this . _handshakeInitializationPacket = new Packets . HandshakeInitializationPacket ( {
58
- scrambleBuff1 : new Buffer ( 8 ) ,
59
- scrambleBuff2 : new Buffer ( 12 ) ,
58
+ scrambleBuff1 : new Buffer ( '1020304050607080' , 'hex' ) ,
59
+ scrambleBuff2 : new Buffer ( '0102030405060708090A0B0C' , 'hex' ) ,
60
60
serverCapabilities1 : 512 , // only 1 flag, PROTOCOL_41
61
61
protocol41 : true
62
62
} ) ;
@@ -71,6 +71,21 @@ FakeConnection.prototype.deny = function(message, errno) {
71
71
} ) ) ;
72
72
} ;
73
73
74
+ FakeConnection . prototype . _sendAuthResponse = function ( packet , expected ) {
75
+ var got = packet . scrambleBuff ;
76
+
77
+ if ( expected . toString ( 'hex' ) === got . toString ( 'hex' ) ) {
78
+ this . _sendPacket ( new Packets . OkPacket ( ) ) ;
79
+ } else {
80
+ this . _sendPacket ( new Packets . ErrorPacket ( {
81
+ message : 'expected ' + expected . toString ( 'hex' ) + ' got ' + got . toString ( 'hex' ) ,
82
+ errno : 1045 // ER_ACCESS_DENIED_ERROR
83
+ } ) ) ;
84
+ }
85
+
86
+ this . _parser . resetPacketNumber ( ) ;
87
+ } ;
88
+
74
89
FakeConnection . prototype . _sendPacket = function ( packet ) {
75
90
var writer = new PacketWriter ( ) ;
76
91
packet . write ( writer ) ;
@@ -83,7 +98,7 @@ FakeConnection.prototype._handleData = function(buffer) {
83
98
84
99
FakeConnection . prototype . _parsePacket = function ( header ) {
85
100
var Packet = this . _determinePacket ( header ) ;
86
- var packet = new Packet ( ) ;
101
+ var packet = new Packet ( { protocol41 : true } ) ;
87
102
88
103
packet . parse ( this . _parser ) ;
89
104
@@ -93,11 +108,12 @@ FakeConnection.prototype._parsePacket = function(header) {
93
108
94
109
if ( this . _handshakeOptions . oldPassword ) {
95
110
this . _sendPacket ( new Packets . UseOldPasswordPacket ( ) ) ;
111
+ } else if ( this . _handshakeOptions . password === 'passwd' ) {
112
+ var expected = new Buffer ( '3DA0ADA7C9E1BB3A110575DF53306F9D2DE7FD09' , 'hex' ) ;
113
+ this . _sendAuthResponse ( packet , expected ) ;
114
+ } else if ( this . _handshakeOptions . user || this . _handshakeOptions . password ) {
115
+ throw new Error ( 'not implemented' ) ;
96
116
} else {
97
- if ( this . _handshakeOptions . user || this . _handshakeOptions . password ) {
98
- throw new Error ( 'not implemented' ) ;
99
- }
100
-
101
117
this . _sendPacket ( new Packets . OkPacket ( ) ) ;
102
118
this . _parser . resetPacketNumber ( ) ;
103
119
}
@@ -106,19 +122,8 @@ FakeConnection.prototype._parsePacket = function(header) {
106
122
this . _oldPasswordPacket = packet ;
107
123
108
124
var expected = Auth . scramble323 ( this . _handshakeInitializationPacket . scrambleBuff ( ) , this . _handshakeOptions . password ) ;
109
- var got = packet . scrambleBuff ;
110
-
111
- var toString = function ( buffer ) {
112
- return Array . prototype . slice . call ( buffer ) . join ( ',' ) ;
113
- } ;
114
-
115
- if ( toString ( expected ) === toString ( got ) ) {
116
- this . _sendPacket ( new Packets . OkPacket ( ) ) ;
117
- } else {
118
- this . _sendPacket ( new Packets . ErrorPacket ( ) ) ;
119
- }
120
125
121
- this . _parser . resetPacketNumber ( ) ;
126
+ this . _sendAuthResponse ( packet , expected ) ;
122
127
break ;
123
128
case Packets . ComQueryPacket :
124
129
this . emit ( 'query' , packet ) ;
0 commit comments