@@ -71,6 +71,14 @@ function FakeConnection(socket) {
7171 socket . on ( 'data' , this . _handleData . bind ( this ) ) ;
7272}
7373
74+ FakeConnection . prototype . deny = function deny ( message , errno ) {
75+ this . _sendPacket ( new Packets . ErrorPacket ( {
76+ message : ( message || 'Access Denied' ) ,
77+ errno : ( errno || Errors . ER_ACCESS_DENIED_ERROR )
78+ } ) ) ;
79+ this . _parser . resetPacketNumber ( ) ;
80+ } ;
81+
7482FakeConnection . prototype . handshake = function ( options ) {
7583 this . _handshakeOptions = options || { } ;
7684
@@ -86,21 +94,11 @@ FakeConnection.prototype.handshake = function(options) {
8694 this . _sendPacket ( this . _handshakeInitializationPacket ) ;
8795} ;
8896
89- FakeConnection . prototype . deny = function ( message , errno ) {
90- this . _sendPacket ( new Packets . ErrorPacket ( {
91- message : message ,
92- errno : errno
93- } ) ) ;
94- } ;
95-
9697FakeConnection . prototype . _sendAuthResponse = function _sendAuthResponse ( got , expected ) {
9798 if ( expected . toString ( 'hex' ) === got . toString ( 'hex' ) ) {
9899 this . _sendPacket ( new Packets . OkPacket ( ) ) ;
99100 } else {
100- this . _sendPacket ( new Packets . ErrorPacket ( {
101- message : 'expected ' + expected . toString ( 'hex' ) + ' got ' + got . toString ( 'hex' ) ,
102- errno : Errors . ER_ACCESS_DENIED_ERROR
103- } ) ) ;
101+ this . deny ( 'expected ' + expected . toString ( 'hex' ) + ' got ' + got . toString ( 'hex' ) ) ;
104102 }
105103
106104 this . _parser . resetPacketNumber ( ) ;
@@ -309,11 +307,7 @@ FakeConnection.prototype._parsePacket = function() {
309307
310308 if ( ! this . emit ( 'changeUser' , packet ) ) {
311309 if ( packet . user === 'does-not-exist' ) {
312- this . _sendPacket ( new Packets . ErrorPacket ( {
313- errno : Errors . ER_ACCESS_DENIED_ERROR ,
314- message : 'User does not exist'
315- } ) ) ;
316- this . _parser . resetPacketNumber ( ) ;
310+ this . deny ( 'User does not exist' ) ;
317311 break ;
318312 } else if ( packet . database === 'does-not-exist' ) {
319313 this . _sendPacket ( new Packets . ErrorPacket ( {
0 commit comments