@@ -12,7 +12,6 @@ var Packets = common.Packets;
1212var PacketWriter = common . PacketWriter ;
1313var Parser = common . Parser ;
1414var Types = common . Types ;
15- var Auth = require ( common . lib + '/protocol/Auth' ) ;
1615var Errors = common . Errors ;
1716var EventEmitter = require ( 'events' ) . EventEmitter ;
1817var Util = require ( 'util' ) ;
@@ -75,14 +74,14 @@ function FakeConnection(socket) {
7574FakeConnection . prototype . handshake = function ( options ) {
7675 this . _handshakeOptions = options || { } ;
7776
78- var packetOpiotns = common . extend ( {
77+ var packetOptions = common . extend ( {
7978 scrambleBuff1 : Buffer . from ( '1020304050607080' , 'hex' ) ,
8079 scrambleBuff2 : Buffer . from ( '0102030405060708090A0B0C' , 'hex' ) ,
8180 serverCapabilities1 : 512 , // only 1 flag, PROTOCOL_41
8281 protocol41 : true
8382 } , this . _handshakeOptions ) ;
8483
85- this . _handshakeInitializationPacket = new Packets . HandshakeInitializationPacket ( packetOpiotns ) ;
84+ this . _handshakeInitializationPacket = new Packets . HandshakeInitializationPacket ( packetOptions ) ;
8685
8786 this . _sendPacket ( this . _handshakeInitializationPacket ) ;
8887} ;
@@ -285,31 +284,14 @@ FakeConnection.prototype._parsePacket = function() {
285284 this . database = ( packet . database || null ) ;
286285 this . user = ( packet . user || null ) ;
287286
288- if ( this . _handshakeOptions . oldPassword ) {
289- this . _sendPacket ( new Packets . UseOldPasswordPacket ( ) ) ;
290- } else if ( this . _handshakeOptions . authMethodName ) {
291- this . _sendPacket ( new Packets . AuthSwitchRequestPacket ( this . _handshakeOptions ) ) ;
292- } else if ( this . _handshakeOptions . password === 'passwd' ) {
293- var expected = Buffer . from ( '3DA0ADA7C9E1BB3A110575DF53306F9D2DE7FD09' , 'hex' ) ;
294- this . _sendAuthResponse ( packet . scrambleBuff , expected ) ;
295- } else if ( this . _handshakeOptions . user || this . _handshakeOptions . password ) {
296- throw new Error ( 'not implemented' ) ;
297- } else {
287+ if ( ! this . emit ( 'clientAuthentication' , packet ) ) {
298288 this . _sendPacket ( new Packets . OkPacket ( ) ) ;
299289 this . _parser . resetPacketNumber ( ) ;
300290 }
301291 break ;
302292 case Packets . SSLRequestPacket :
303293 this . _startTLS ( ) ;
304294 break ;
305- case Packets . OldPasswordPacket :
306- var expected = Auth . scramble323 ( this . _handshakeInitializationPacket . scrambleBuff ( ) , this . _handshakeOptions . password ) ;
307- this . _sendAuthResponse ( packet . scrambleBuff , expected ) ;
308- break ;
309- case Packets . AuthSwitchResponsePacket :
310- var expected = Auth . token ( this . _handshakeOptions . password , Buffer . from ( '00112233445566778899AABBCCDDEEFF01020304' , 'hex' ) ) ;
311- this . _sendAuthResponse ( packet . data , expected ) ;
312- break ;
313295 case Packets . ComQueryPacket :
314296 if ( ! this . emit ( 'query' , packet ) ) {
315297 this . _handleQueryPacket ( packet ) ;
@@ -322,6 +304,9 @@ FakeConnection.prototype._parsePacket = function() {
322304 }
323305 break ;
324306 case Packets . ComChangeUserPacket :
307+ this . database = ( packet . database || null ) ;
308+ this . user = ( packet . user || null ) ;
309+
325310 if ( ! this . emit ( 'changeUser' , packet ) ) {
326311 if ( packet . user === 'does-not-exist' ) {
327312 this . _sendPacket ( new Packets . ErrorPacket ( {
@@ -339,9 +324,6 @@ FakeConnection.prototype._parsePacket = function() {
339324 break ;
340325 }
341326
342- this . database = ( packet . database || null ) ;
343- this . user = ( packet . user || null ) ;
344-
345327 this . _sendPacket ( new Packets . OkPacket ( ) ) ;
346328 this . _parser . resetPacketNumber ( ) ;
347329 }
@@ -352,7 +334,9 @@ FakeConnection.prototype._parsePacket = function() {
352334 }
353335 break ;
354336 default :
355- throw new Error ( 'Unexpected packet: ' + Packet . name ) ;
337+ if ( ! this . emit ( packet . constructor . name , packet ) ) {
338+ throw new Error ( 'Unexpected packet: ' + Packet . name ) ;
339+ }
356340 }
357341} ;
358342
0 commit comments