Skip to content

Commit c426924

Browse files
committed
added testChangeUser
1 parent d1e8ad5 commit c426924

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/integration/promise-wrappers/test-promise-wrappers.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var config = require('../../common.js').config;
2+
var Buffer = require('safe-buffer').Buffer;
23

34
var skipTest = false;
45
if (typeof Promise == 'undefined') {
@@ -23,6 +24,7 @@ var doneEventsConnect = false;
2324
var doneCalledPool = false;
2425
var exceptionCaughtPool = false;
2526
var doneEventsPool = false;
27+
var doneChangeUser = false;
2628

2729
function testBasic() {
2830
var connResolved;
@@ -247,6 +249,71 @@ function testEventsPool() {
247249
pool.pool.emit('release');
248250
}
249251

252+
function testChangeUser() {
253+
var onlyUsername = function(name) {
254+
return name.substring(0, name.indexOf('@'));
255+
};
256+
var connResolved;
257+
var connPromise = createConnection(config)
258+
.then(function(conn) {
259+
connResolved = conn;
260+
return connResolved.query(
261+
"GRANT ALL ON *.* TO 'changeuser1'@'%' IDENTIFIED BY 'changeuser1pass'"
262+
);
263+
})
264+
.then(function() {
265+
return connResolved.query(
266+
"GRANT ALL ON *.* TO 'changeuser2'@'%' IDENTIFIED BY 'changeuser2pass'"
267+
);
268+
})
269+
.then(function() {
270+
return connResolved.query('FLUSH PRIVILEGES');
271+
})
272+
.then(function() {
273+
return connResolved.changeUser({
274+
user: 'changeuser1',
275+
password: 'changeuser1pass'
276+
});
277+
})
278+
.then(function() {
279+
return connResolved.query('select current_user()');
280+
})
281+
.then(function(rows) {
282+
assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser1');
283+
return connResolved.changeUser({
284+
user: 'changeuser2',
285+
password: 'changeuser2pass'
286+
});
287+
})
288+
.then(function() {
289+
return connResolved.query('select current_user()');
290+
})
291+
.then(function(rows) {
292+
assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser2');
293+
return connResolved.changeUser({
294+
user: 'changeuser1',
295+
passwordSha1: Buffer.from(
296+
'f961d39c82138dcec42b8d0dcb3e40a14fb7e8cd',
297+
'hex'
298+
) // sha1(changeuser1pass)
299+
});
300+
})
301+
.then(function() {
302+
return connResolved.query('select current_user()');
303+
})
304+
.then(function(rows) {
305+
assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser1');
306+
doneChangeUser = true;
307+
return connResolved.end();
308+
})
309+
.catch(function(err) {
310+
if (connResolved) {
311+
connResolved.end();
312+
}
313+
throw err;
314+
});
315+
}
316+
250317
testBasic();
251318
testErrors();
252319
testObjParams();
@@ -256,6 +323,7 @@ testBasicPool();
256323
testErrorsPool();
257324
testObjParamsPool();
258325
testEventsPool();
326+
testChangeUser();
259327

260328
process.on('exit', function() {
261329
if (skipTest) {
@@ -267,6 +335,7 @@ process.on('exit', function() {
267335
assert.equal(doneCalledPool, true);
268336
assert.equal(exceptionCaughtPool, true);
269337
assert.equal(doneEventsPool, true);
338+
assert.equal(doneChangeUser, true);
270339
});
271340

272341
process.on('unhandledRejection', function(err) {

0 commit comments

Comments
 (0)