-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support auth switch in change user flow
closes #1776
- Loading branch information
1 parent
776d843
commit d916479
Showing
6 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
test/unit/connection/test-change-user-auth-switch-unknown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var assert = require('assert'); | ||
var Buffer = require('safe-buffer').Buffer; | ||
var common = require('../../common'); | ||
var connection = common.createConnection({ | ||
port : common.fakeServerPort, | ||
user : 'user_1', | ||
password : 'pass_1' | ||
}); | ||
|
||
var server = common.createFakeServer(); | ||
|
||
server.listen(common.fakeServerPort, function(err) { | ||
assert.ifError(err); | ||
|
||
connection.query('SELECT CURRENT_USER()', function (err, result) { | ||
assert.ifError(err); | ||
assert.strictEqual(result[0]['CURRENT_USER()'], 'user_1@localhost'); | ||
|
||
connection.changeUser({user: 'user_2', password: 'pass_2'}, function (err) { | ||
assert.ok(err); | ||
assert.equal(err.code, 'UNSUPPORTED_AUTH_METHOD'); | ||
assert.equal(err.fatal, true); | ||
assert.ok(/foo_plugin_password/.test(err.message)); | ||
|
||
connection.destroy(); | ||
server.destroy(); | ||
}); | ||
}); | ||
}); | ||
|
||
server.on('connection', function (incomingConnection) { | ||
incomingConnection.on('changeUser', function () { | ||
this.authSwitchRequest({ | ||
authMethodName : 'foo_plugin_password', | ||
authMethodData : Buffer.alloc(0) | ||
}); | ||
}); | ||
|
||
incomingConnection.handshake(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var assert = require('assert'); | ||
var Crypto = require('crypto'); | ||
var common = require('../../common'); | ||
var connection = common.createConnection({ | ||
port : common.fakeServerPort, | ||
user : 'user_1', | ||
password : 'pass_1' | ||
}); | ||
|
||
var random = Crypto.pseudoRandomBytes || Crypto.randomBytes; // Depends on node.js version | ||
var server = common.createFakeServer(); | ||
|
||
server.listen(common.fakeServerPort, function(err) { | ||
assert.ifError(err); | ||
|
||
connection.query('SELECT CURRENT_USER()', function (err, result) { | ||
assert.ifError(err); | ||
assert.strictEqual(result[0]['CURRENT_USER()'], 'user_1@localhost'); | ||
|
||
connection.changeUser({user: 'user_2', password: 'pass_2'}, function (err) { | ||
assert.ifError(err); | ||
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('pass_2', scramble)); | ||
}); | ||
|
||
incomingConnection.on('changeUser', function () { | ||
this.authSwitchRequest({ | ||
authMethodName : 'mysql_native_password', | ||
authMethodData : scramble | ||
}); | ||
}); | ||
|
||
incomingConnection.handshake(); | ||
}); | ||
}); |