function verify(message, password, bytes){ var expected = new Buffer(bytes); var actual = auth.scramble323(new Buffer(message), password); assert.deepEqual(actual, expected); }
FakeConnection.prototype._parsePacket = function(header) { var Packet = this._determinePacket(header); var packet = new Packet({protocol41: true}); packet.parse(this._parser); switch (Packet) { case Packets.ClientAuthenticationPacket: this._clientAuthenticationPacket = packet; if (this._handshakeOptions.oldPassword) { this._sendPacket(new Packets.UseOldPasswordPacket()); } else if (this._handshakeOptions.password === 'passwd') { var expected = new Buffer('3DA0ADA7C9E1BB3A110575DF53306F9D2DE7FD09', 'hex'); this._sendAuthResponse(packet, expected); } else if (this._handshakeOptions.user || this._handshakeOptions.password) { throw new Error('not implemented'); } else { this._sendPacket(new Packets.OkPacket()); this._parser.resetPacketNumber(); } break; case Packets.SSLRequestPacket: this._startTLS(); break; case Packets.OldPasswordPacket: this._oldPasswordPacket = packet; var expected = Auth.scramble323(this._handshakeInitializationPacket.scrambleBuff(), this._handshakeOptions.password); this._sendAuthResponse(packet, expected); break; case Packets.ComQueryPacket: if (!this.emit('query', packet)) { this._handleQueryPacket(packet); } break; case Packets.ComPingPacket: if (!this.emit('ping', packet)) { this._sendPacket(new Packets.OkPacket()); this._parser.resetPacketNumber(); } break; case Packets.ComChangeUserPacket: if (packet.user === 'does-not-exist') { this._sendPacket(new Packets.ErrorPacket({ errno : Errors.ER_ACCESS_DENIED_ERROR, message : 'User does not exist' })); this._parser.resetPacketNumber(); break; } else if (packet.database === 'does-not-exist') { this._sendPacket(new Packets.ErrorPacket({ errno : Errors.ER_BAD_DB_ERROR, message : 'Database does not exist' })); this._parser.resetPacketNumber(); break; } this._clientAuthenticationPacket = new Packets.ClientAuthenticationPacket({ clientFlags : this._clientAuthenticationPacket.clientFlags, filler : this._clientAuthenticationPacket.filler, maxPacketSize: this._clientAuthenticationPacket.maxPacketSize, protocol41 : this._clientAuthenticationPacket.protocol41, charsetNumber: packet.charsetNumber, database : packet.database, scrambleBuff : packet.scrambleBuff, user : packet.user }); this._sendPacket(new Packets.OkPacket()); this._parser.resetPacketNumber(); break; case Packets.ComQuitPacket: this.emit('quit', packet); this._socket.end(); break; default: throw new Error('Unexpected packet: ' + Packet.name) } };