Skip to content

Commit 59fc0d2

Browse files
committed
Merge pull request mysqljs#618 from seanmonstar/change-user-packet
always pass handshakeInitializationPacket to ChangeUser
2 parents 112bc97 + c5fe074 commit 59fc0d2

File tree

5 files changed

+48
-18
lines changed

5 files changed

+48
-18
lines changed

.travis.yml

+12
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,15 @@ node_js:
33
- '0.6'
44
- '0.8'
55
- '0.10'
6+
7+
before_script:
8+
- "mysql -e 'create database node_mysql;'"
9+
10+
env:
11+
- MYSQL_DATABASE=node_mysql
12+
13+
mysql:
14+
adapter: mysql2
15+
username: root
16+
encoding: utf8
17+
database: node_mysql

lib/protocol/Protocol.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,30 @@ Protocol.prototype._enqueue = function(sequence) {
106106

107107
if (this._queue.length === 1) {
108108
this._parser.resetPacketNumber();
109-
sequence.start();
109+
this._startSequence(sequence);
110110
}
111111

112112
return sequence;
113113
};
114114

115115
Protocol.prototype._validateEnqueue = function(sequence) {
116116
var err;
117-
var prefix = 'Cannot enqueue ' + sequence.constructor.name + ' after ';
117+
var prefix = 'Cannot enqueue ' + sequence.constructor.name;
118+
var prefixBefore = prefix + ' before ';
119+
var prefixAfter = prefix + ' after ';
118120

119121
if (this._quitSequence) {
120-
err = new Error(prefix + 'invoking quit.');
122+
err = new Error(prefixAfter + 'invoking quit.');
121123
err.code = 'PROTOCOL_ENQUEUE_AFTER_QUIT';
122124
} else if (this._destroyed) {
123-
err = new Error(prefix + 'being destroyed.');
125+
err = new Error(prefixAfter + 'being destroyed.');
124126
err.code = 'PROTOCOL_ENQUEUE_AFTER_DESTROY';
125127
} else if (this._handshakeSequence && sequence.constructor === Sequences.Handshake) {
126-
err = new Error(prefix + 'already enqueuing a Handshake.');
128+
err = new Error(prefixAfter + 'already enqueuing a Handshake.');
127129
err.code = 'PROTOCOL_ENQUEUE_HANDSHAKE_TWICE';
130+
} else if (!this._handshakeSequence && sequence.constructor === Sequences.ChangeUser) {
131+
err = new Error(prefixBefore + 'a Handshake.');
132+
err.code = 'PROTOCOL_ENQUEUE_BEFORE_HANDSHAKE';
128133
} else {
129134
return true;
130135
}
@@ -222,12 +227,15 @@ Protocol.prototype._dequeue = function() {
222227

223228
this._parser.resetPacketNumber();
224229

225-
if (sequence.constructor == Sequences.ChangeUser) {
230+
this._startSequence(sequence);
231+
};
232+
233+
Protocol.prototype._startSequence = function(sequence) {
234+
if (sequence.constructor === Sequences.ChangeUser) {
226235
sequence.start(this._handshakeInitializationPacket);
227-
return;
236+
} else {
237+
sequence.start();
228238
}
229-
230-
sequence.start();
231239
};
232240

233241
Protocol.prototype.handleNetworkError = function(err) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var common = require('../../common');
2+
var connection = common.createConnection();
3+
var assert = require('assert');
4+
5+
connection.query('CREATE DATABASE ' + common.testDatabase, function(err) {
6+
if (err && err.code !== 'ER_DB_CREATE_EXISTS') throw err;
7+
8+
// wait till protocol._queue is empty
9+
setTimeout(function() {
10+
connection.changeUser({database: common.testDatabase}, function(err) {
11+
assert.ifError(err);
12+
});
13+
14+
connection.end();
15+
}, 2000);
16+
});

test/integration/connection/test-change-user-fatal-error.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ var common = require('../../common');
77
var connection = common.createConnection();
88
var assert = require('assert');
99

10-
if (common.isTravis()) {
11-
return console.log('skipping - travis mysql does not support this test');
12-
}
1310

1411
var err;
15-
connection.changeUser({user: 'does-not-exist'}, function(_err) {
12+
// XXX: user: 'does-not-exist' doesn't cause any error...
13+
connection.changeUser({database: 'does-not-exist'}, function(_err) {
1614
err = _err;
1715
connection.end();
1816
});
1917

2018
process.on('exit', function() {
2119
if (process.env.NO_GRANT == '1' && err === null) return;
22-
assert.equal(err.code, 'ER_ACCESS_DENIED_ERROR');
20+
assert.equal(err.code, 'ER_BAD_DB_ERROR');
2321
assert.equal(err.fatal, true);
2422
});

test/integration/connection/test-change-user.js

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ var common = require('../../common');
22
var connection = common.createConnection();
33
var assert = require('assert');
44

5-
if (common.isTravis()) {
6-
return console.log('skipping - travis mysql does not support this test');
7-
}
8-
95
connection.query('CREATE DATABASE ' + common.testDatabase, function(err) {
106
if (err && err.code !== 'ER_DB_CREATE_EXISTS') throw err;
117
});

0 commit comments

Comments
 (0)