-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest-auth-switch-native.js
49 lines (39 loc) · 1.25 KB
/
test-auth-switch-native.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var assert = require('assert');
var Crypto = require('crypto');
var common = require('../../common');
var connection = common.createConnection({
port : common.fakeServerPort,
password : 'authswitch'
});
var random = Crypto.pseudoRandomBytes || Crypto.randomBytes; // Depends on node.js version
var server = common.createFakeServer();
var connected;
server.listen(common.fakeServerPort, function (err) {
assert.ifError(err);
connection.connect(function (err, result) {
assert.ifError(err);
connected = result;
connection.destroy();
server.destroy();
});
});
server.on('connection', function(incomingConnection) {
random(20, function (err, scramble) {
assert.ifError(err);
incomingConnection.on('authSwitchResponse', function (packet) {
this._sendAuthResponse(packet.data, common.Auth.token('authswitch', scramble));
});
incomingConnection.on('clientAuthentication', function () {
this.authSwitchRequest({
authMethodName : 'mysql_native_password',
authMethodData : scramble
});
});
incomingConnection.handshake({
serverCapabilities1: 512 | 1 << 11 // PROTOCOL_41 and SSL
});
});
});
process.on('exit', function() {
assert.equal(connected.fieldCount, 0);
});