Skip to content

Commit 6cde9eb

Browse files
committed
tests: use deny helper method
1 parent 4e90574 commit 6cde9eb

9 files changed

+23
-29
lines changed

test/FakeServer.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
7482
FakeConnection.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-
9697
FakeConnection.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({

test/unit/connection/test-connect-error-event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ server.listen(common.fakeServerPort, function (err) {
1818
});
1919

2020
server.on('connection', function (conn) {
21-
conn.deny('You suck.', common.Errors.ER_ACCESS_DENIED_ERROR);
21+
conn.deny();
2222
});

test/unit/connection/test-connection-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function end() {
5050
}
5151

5252
server.on('connection', function(incomingConnection) {
53-
incomingConnection.deny('You suck.', common.Errors.ER_HOST_NOT_PRIVILEGED);
53+
incomingConnection.deny();
5454
});
5555

5656
process.on('exit', function() {

test/unit/connection/test-fatal-connect-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ server.listen(common.fakeServerPort, function (err) {
3737

3838
server.on('connection', function (conn) {
3939
if (count === 0) {
40-
conn.deny('You suck.', common.Errors.ER_ACCESS_DENIED_ERROR);
40+
conn.deny();
4141
return;
4242
}
4343

test/unit/pool-cluster/test-connection-error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ server.listen(common.fakeServerPort, function(err) {
1515

1616
cluster.getConnection('MASTER', function (err) {
1717
assert.ok(err);
18-
assert.equal(err.code, 'ER_HOST_NOT_PRIVILEGED');
18+
assert.equal(err.code, 'ER_ACCESS_DENIED_ERROR');
1919
assert.equal(err.fatal, true);
2020
assert.equal(connCount, 5);
2121

@@ -28,5 +28,5 @@ server.listen(common.fakeServerPort, function(err) {
2828

2929
server.on('connection', function(incomingConnection) {
3030
connCount += 1;
31-
incomingConnection.deny('You suck.', common.Errors.ER_HOST_NOT_PRIVILEGED);
31+
incomingConnection.deny();
3232
});

test/unit/pool-cluster/test-connection-no-retry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ server.listen(common.fakeServerPort, function(err) {
1212

1313
cluster.getConnection('MASTER', function (err) {
1414
assert.ok(err);
15-
assert.equal(err.code, 'ER_HOST_NOT_PRIVILEGED');
15+
assert.equal(err.code, 'ER_ACCESS_DENIED_ERROR');
1616
assert.equal(err.fatal, true);
1717
assert.equal(connCount, 1);
1818

@@ -25,5 +25,5 @@ server.listen(common.fakeServerPort, function(err) {
2525

2626
server.on('connection', function (conn) {
2727
connCount += 1;
28-
conn.deny('You suck.', common.Errors.ER_HOST_NOT_PRIVILEGED);
28+
conn.deny();
2929
});

test/unit/pool-cluster/test-query-connection-error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ server.listen(common.fakeServerPort, function (err) {
1515

1616
pool.query('SELECT 1', function (err) {
1717
assert.ok(err, 'got error');
18-
assert.equal(err.code, 'ER_HOST_NOT_PRIVILEGED');
18+
assert.equal(err.code, 'ER_ACCESS_DENIED_ERROR');
1919
server.destroy();
2020
});
2121
});
2222

2323
server.on('connection', function (conn) {
24-
conn.deny('You suck.', common.Errors.ER_HOST_NOT_PRIVILEGED);
24+
conn.deny();
2525
});

test/unit/pool/test-query-connection-error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ server.listen(common.fakeServerPort, function (err) {
88

99
pool.query('SELECT 1', function (err) {
1010
assert.ok(err, 'got error');
11-
assert.equal(err.code, 'ER_HOST_NOT_PRIVILEGED');
11+
assert.equal(err.code, 'ER_ACCESS_DENIED_ERROR');
1212
assert.equal(err.fatal, true);
1313
server.destroy();
1414
});
1515
});
1616

1717
server.on('connection', function (conn) {
18-
conn.deny('You suck.', common.Errors.ER_HOST_NOT_PRIVILEGED);
18+
conn.deny();
1919
});

test/unit/pool/test-query-stream-connection-error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ server.listen(common.fakeServerPort, function (err) {
1010

1111
query.on('error', function (err) {
1212
assert.ok(err, 'got error');
13-
assert.equal(err.code, 'ER_HOST_NOT_PRIVILEGED');
13+
assert.equal(err.code, 'ER_ACCESS_DENIED_ERROR');
1414
assert.equal(err.fatal, true);
1515
server.destroy();
1616
});
1717
});
1818

1919
server.on('connection', function (conn) {
20-
conn.deny('You suck.', common.Errors.ER_HOST_NOT_PRIVILEGED);
20+
conn.deny();
2121
});

0 commit comments

Comments
 (0)