Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJS-139] createConnection(string)` does not support URL-encoded cr…
…edentials #115
  • Loading branch information
rusher committed Jul 1, 2020
1 parent 2f9b559 commit 1fd343a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
14 changes: 8 additions & 6 deletions lib/config/connection-options.js
Expand Up @@ -168,7 +168,7 @@ class ConnectionOptions {
opts.charsetNumber = Number.parseInt(opts.charsetNumber);
}
if (opts.compress) opts.compress = opts.compress == 'true';
if (opts.connectAttributes) opts.connectAttributes = opts.connectAttributes == 'true';
if (opts.connectAttributes) opts.connectAttributes = JSON.parse(opts.connectAttributes);
if (opts.connectTimeout) opts.connectTimeout = parseInt(opts.connectTimeout);
if (opts.socketTimeout) opts.socketTimeout = parseInt(opts.socketTimeout);
if (opts.dateStrings) opts.dateStrings = opts.dateStrings == 'true';
Expand Down Expand Up @@ -208,11 +208,11 @@ class ConnectionOptions {
);
}
const options = {
user: matchResults[2],
password: matchResults[4],
host: matchResults[6],
user: matchResults[2] ? decodeURIComponent(matchResults[2]) : undefined,
password: matchResults[4] ? decodeURIComponent(matchResults[4]) : undefined,
host: matchResults[6] ? decodeURIComponent(matchResults[6]) : matchResults[6],
port: matchResults[8] ? parseInt(matchResults[8]) : undefined,
database: matchResults[9]
database: matchResults[9] ? decodeURIComponent(matchResults[9]) : matchResults[9]
};

const variousOptsString = matchResults[11];
Expand All @@ -221,7 +221,9 @@ class ConnectionOptions {
keyVals.forEach(function (keyVal) {
const equalIdx = keyVal.indexOf('=');
if (equalIdx !== 1) {
options[keyVal.substring(0, equalIdx)] = keyVal.substring(equalIdx + 1);
let val = keyVal.substring(equalIdx + 1);
val = val ? decodeURIComponent(val) : undefined;
options[keyVal.substring(0, equalIdx)] = val;
}
});
}
Expand Down
46 changes: 26 additions & 20 deletions test/integration/test-batch.js
Expand Up @@ -1278,7 +1278,7 @@ describe('batch', () => {
describe('standard question mark using bulk', () => {
const useCompression = false;
it('simple batch, local date', function (done) {
if (process.env.SKYSQL || !base.utf8Collation()) {
if (process.env.SKYSQL || !base.utf8Collation()) {
this.skip();
return;
}
Expand All @@ -1288,7 +1288,7 @@ describe('batch', () => {
});

it('simple batch with option', function (done) {
if (process.env.SKYSQL) {
if (process.env.SKYSQL) {
this.skip();
return;
}
Expand All @@ -1298,7 +1298,7 @@ describe('batch', () => {
});

it('batch without value', function (done) {
if (process.env.SKYSQL) {
if (process.env.SKYSQL) {
this.skip();
return;
}
Expand All @@ -1308,7 +1308,10 @@ describe('batch', () => {
});

it('batch without parameter', function (done) {
if (process.env.SKYSQL || (!shareConn.info.isMariaDB() && !shareConn.info.hasMinVersion(5, 6, 0))) {
if (
process.env.SKYSQL ||
(!shareConn.info.isMariaDB() && !shareConn.info.hasMinVersion(5, 6, 0))
) {
this.skip();
return;
}
Expand All @@ -1328,7 +1331,10 @@ describe('batch', () => {
});

it('batch with erroneous parameter', function (done) {
if (process.env.SKYSQL) || (!shareConn.info.isMariaDB() && !shareConn.info.hasMinVersion(5, 6, 0))) {
if (
process.env.SKYSQL ||
(!shareConn.info.isMariaDB() && !shareConn.info.hasMinVersion(5, 6, 0))
) {
this.skip();
return;
}
Expand All @@ -1353,7 +1359,7 @@ describe('batch', () => {
});

it('simple batch offset date', function (done) {
if (process.env.SKYSQL || !base.utf8Collation()) {
if (process.env.SKYSQL || !base.utf8Collation()) {
this.skip();
return;
}
Expand All @@ -1363,7 +1369,7 @@ describe('batch', () => {
});

it('simple batch offset date Z ', function (done) {
if (process.env.SKYSQL||!base.utf8Collation()) {
if (process.env.SKYSQL || !base.utf8Collation()) {
this.skip();
return;
}
Expand All @@ -1373,7 +1379,7 @@ describe('batch', () => {
});

it('simple batch encoding CP1251', function (done) {
if (process.env.SKYSQL) {
if (process.env.SKYSQL) {
this.skip();
return;
}
Expand Down Expand Up @@ -1430,7 +1436,7 @@ describe('batch', () => {
it('16M+ error batch', function (done) {
if (process.env.SKYSQL || maxAllowedSize <= testSize) {
this.skip();
}else {
} else {
this.timeout(360000);
bigBatchError(useCompression, true, done);
}
Expand All @@ -1439,7 +1445,7 @@ describe('batch', () => {
it('16M+ single insert batch with no maxAllowedPacket set', function (done) {
if (process.env.SKYSQL || !process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
this.skip();
}else{
} else {
this.timeout(360000);
singleBigInsertWithoutMaxAllowedPacket(useCompression, true, done);
}
Expand All @@ -1448,7 +1454,7 @@ describe('batch', () => {
it('batch with streams', function (done) {
if (process.env.SKYSQL || !base.utf8Collation()) {
this.skip();
} else{
} else {
this.timeout(30000);
batchWithStream(useCompression, true, done);
}
Expand All @@ -1457,7 +1463,7 @@ describe('batch', () => {
it('batch error with streams', function (done) {
if (process.env.SKYSQL) {
this.skip();
}else {
} else {
this.timeout(30000);
batchErrorWithStream(useCompression, true, done);
}
Expand Down Expand Up @@ -1785,7 +1791,7 @@ describe('batch', () => {
});

it('simple batch offset date', function (done) {
if (!base.utf8Collation()) {
if (!base.utf8Collation()) {
this.skip();
return;
}
Expand Down Expand Up @@ -1853,7 +1859,7 @@ describe('batch', () => {
});

it('16M+ batch with 16M max_allowed_packet', function (done) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
this.skip();
return;
}
Expand All @@ -1862,7 +1868,7 @@ describe('batch', () => {
});

it('16M+ batch with max_allowed_packet set to 4M', function (done) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= 4 * 1024 * 1024) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= 4 * 1024 * 1024) {
this.skip();
return;
}
Expand All @@ -1871,7 +1877,7 @@ describe('batch', () => {
});

it('16M+ error batch', function (done) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
this.skip();
return;
}
Expand All @@ -1880,7 +1886,7 @@ describe('batch', () => {
});

it('16M+ single insert batch with no maxAllowedPacket set', function (done) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
this.skip();
return;
}
Expand All @@ -1889,7 +1895,7 @@ describe('batch', () => {
});

it('batch with streams', function (done) {
if (!base.utf8Collation()) {
if (!base.utf8Collation()) {
this.skip();
return;
}
Expand All @@ -1903,7 +1909,7 @@ describe('batch', () => {
});

it('16M+ batch with streams', function (done) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
this.skip();
return;
}
Expand All @@ -1912,7 +1918,7 @@ describe('batch', () => {
});

it('16M+ error batch with streams', function (done) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
if (!process.env.RUN_LONG_TEST || maxAllowedSize <= testSize) {
this.skip();
return;
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/config/test-connection-options.js
Expand Up @@ -100,6 +100,18 @@ describe('test connection options', () => {
assert.equal(result.collation.index, 200);
});

it('URL decoding test', () => {
const result = new ConnOptions(
'mariadb://root%C3%A5:p%40ssword@example.com:3307/%D1%88db?connectAttributes=%7B"par1":"bouh","par2":"bla"%7D'
);
assert.equal(result.database, 'шdb');
assert.equal(result.host, 'example.com');
assert.equal(result.password, 'p@ssword');
assert.equal(result.port, 3307);
assert.equal(result.user, 'rootå');
assert.deepEqual(result.connectAttributes, { par1: 'bouh', par2: 'bla' });
});

it('unknown option', () => {
const result = new ConnOptions(
'mariadb://root:pass@example.com:3307/db?wrongOption=false&ssl=true&dateStrings=true'
Expand Down

0 comments on commit 1fd343a

Please sign in to comment.