Skip to content

Commit 5648672

Browse files
committed
Improve authentication handling in Thin mode
1 parent 65b221a commit 5648672

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

lib/thin/connection.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,10 @@ class ThinConnectionImpl extends ConnectionImpl {
466466
* @return {Promise}
467467
*/
468468
async connect(params) {
469-
if (params.password === undefined && params.token === undefined) {
470-
errors.throwErr(errors.ERR_MISSING_CREDENTIALS);
471-
} else if (!params.connectString) {
469+
if (!params.connectString) {
472470
errors.throwErr(errors.ERR_EMPTY_CONNECT_STRING);
473471
}
472+
thinUtil.checkCredentials(params);
474473

475474
this.sessionID = 0;
476475
this.serialNum = 0;

lib/thin/pool.js

+6
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ const protocolUtil = require('./protocol/utils.js');
3232
const errors = require('../errors.js');
3333
const settings = require('../settings.js');
3434
const util = require('../util.js');
35+
const thinUtil = require('./util.js');
3536
const {getConnectionInfo} = require('./sqlnet/networkSession.js');
3637
const crypto = require('crypto');
3738
const EventEmitter = require('events');
3839

3940
class ThinPoolImpl extends PoolImpl {
4041

4142
_init(params) {
43+
if (!params.homogeneous) {
44+
errors.throwErr(errors.ERR_NOT_IMPLEMENTED, 'Heterogeneous Pool');
45+
}
46+
thinUtil.checkCredentials(params);
47+
4248
this._availableObjects = [];
4349
this._name = 'node-thin';
4450
this._poolMin = params.poolMin;

lib/thin/util.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'use strict';
2828

2929
const constants = require('../constants');
30+
const errors = require('../errors.js');
3031

3132
//---------------------------------------------------------------------------
3233
// getMetadataMany(sql)
@@ -260,12 +261,29 @@ function checkProxyUserValidity(userName) {
260261
return result;
261262
}
262263

264+
//---------------------------------------------------------------------------
265+
// checkCredentials()
266+
//
267+
// Check Credentials for Password Authentication
268+
//---------------------------------------------------------------------------
269+
function checkCredentials(params) {
270+
if (params.token === undefined) {
271+
if (params.password === undefined) {
272+
errors.throwErr(errors.ERR_MISSING_CREDENTIALS);
273+
}
274+
if (params.externalAuth === true) {
275+
errors.throwErr(errors.ERR_NOT_IMPLEMENTED, 'External Auth');
276+
}
277+
}
278+
}
279+
263280
module.exports = {
264281
getMetadataMany,
265282
cleanSql,
266283
getExecuteOutBinds,
267284
getExecuteManyOutBinds,
268285
getOutBinds,
269286
getBindVars,
270-
checkProxyUserValidity
287+
checkProxyUserValidity,
288+
checkCredentials
271289
};

test/pool.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,16 @@ describe('2. pool.js', function() {
810810
homogeneous: false
811811
};
812812
delete config.user;
813-
const pool = await oracledb.createPool(config);
814-
assert.strictEqual(pool.homogeneous, false);
815-
await pool.close(0);
813+
if (!oracledb.thin) {
814+
const pool = await oracledb.createPool(config);
815+
assert.strictEqual(pool.homogeneous, false);
816+
await pool.close(0);
817+
} else {
818+
await assert.rejects(
819+
async () => await oracledb.createPool(config),
820+
/NJS-089:/
821+
);
822+
}
816823
}); // 2.15.11
817824

818825
it('2.15.12 user name', async function() {
@@ -864,6 +871,21 @@ describe('2. pool.js', function() {
864871
await pool.close(0);
865872
}); // 2.15.14
866873

874+
it('2.15.15 externalAuth - true and non-empty password', async function() {
875+
const config = {
876+
connectString: dbConfig.connectString,
877+
poolMin: 1,
878+
poolMax: 1,
879+
poolIncrement: 0,
880+
externalAuth: true,
881+
password: 'nopass'
882+
};
883+
await assert.rejects(
884+
async () => await oracledb.createPool(config),
885+
/DPI-1032:|NJS-089:/
886+
);
887+
}); // 2.15.15
888+
867889
}); // 2.15
868890

869891
describe('2.16 Pool non-configurable properties global/local override', function() {

0 commit comments

Comments
 (0)