Skip to content

Commit 6c8ecf5

Browse files
committed
Allow non null username for external proxy authentication and non-token authentication - Issue #1628
1 parent e89492a commit 6c8ecf5

File tree

7 files changed

+55
-7
lines changed

7 files changed

+55
-7
lines changed

doc/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ Thin Mode Changes
8686
Thick Mode Changes
8787
++++++++++++++++++
8888

89+
#) Fixed bug that causes an 'NJS-136' exception to be thrown
90+
when a proxy user is used for external authentication.
91+
`Issue #1628 <https://github.com/oracle/node-oracledb/issues/1628>`__.
92+
8993
#) Fixed bug resulting in a segfault on some platforms when using two-phase
9094
commit. (`ODPI-C change
9195
<https://github.com/oracle/odpi/commit/3102b45c6712c9b6d53eb770b1314c06102c69e0>`__).

lib/errors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const ERR_WRONG_CRED_FOR_EXTAUTH = 136;
137137
const ERR_MISSING_BIND_VALUE = 137;
138138
const ERR_SERVER_VERSION_NOT_SUPPORTED = 138;
139139
const ERR_UNEXPECTED_XML_TYPE = 139;
140+
const ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY = 140;
140141

141142
// Oracle Net layer errors start from 500
142143
const ERR_CONNECTION_CLOSED = 500;
@@ -396,6 +397,8 @@ messages.set(ERR_SERVER_VERSION_NOT_SUPPORTED, // NJS-138
396397
'connections to this database server version are not supported by node-oracledb in Thin mode');
397398
messages.set(ERR_UNEXPECTED_XML_TYPE, // NJS-139
398399
'unexpected XML type with flag %d');
400+
messages.set(ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY, // NJS-140
401+
'user name must be enclosed in [] when using external authentication with a proxy user');
399402

400403
// Oracle Net layer errors
401404

@@ -776,6 +779,7 @@ module.exports = {
776779
ERR_MISSING_BIND_VALUE,
777780
ERR_SERVER_VERSION_NOT_SUPPORTED,
778781
ERR_UNEXPECTED_XML_TYPE,
782+
ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY,
779783
ERR_CONNECTION_CLOSED_CODE: `${ERR_PREFIX}-${ERR_CONNECTION_CLOSED}`,
780784
assert,
781785
assertArgCount,

lib/oracledb.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,20 @@ async function _verifyOptions(options, inCreatePool) {
497497

498498
}
499499

500-
// Check external Auth config
501-
if (outOptions.token === undefined && outOptions.externalAuth && (outOptions.user || outOptions.password)) {
502-
errors.throwErr(errors.ERR_WRONG_CRED_FOR_EXTAUTH);
500+
// Check external Auth config.
501+
// Allow Session User enclosed in [] for proxy authentication.
502+
if (outOptions.token === undefined && outOptions.externalAuth) {
503+
if (outOptions.password) {
504+
errors.throwErr(errors.ERR_WRONG_CRED_FOR_EXTAUTH);
505+
}
506+
if (outOptions.user) {
507+
if (inCreatePool) {
508+
errors.throwErr(errors.ERR_WRONG_CRED_FOR_EXTAUTH);
509+
} else if (outOptions.user[0] !== '[' || outOptions.user.slice(-1) !== ']') {
510+
// username is not enclosed in [].
511+
errors.throwErr(errors.ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY);
512+
}
513+
}
503514
}
504515

505516
return outOptions;

lib/pool.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,20 @@ class Pool extends EventEmitter {
192192
outOptions.user = options.username;
193193
}
194194

195+
if (this.externalAuth &&
196+
outOptions.user && (outOptions.user[0] !== '['
197+
|| outOptions.user.slice(-1) !== ']')) {
198+
// username is not enclosed in [].
199+
errors.throwErr(errors.ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY);
200+
}
201+
195202
// password must be a string
196203
if (options.password !== undefined) {
197204
errors.assertParamPropValue(typeof options.password === 'string', 1,
198205
"password");
206+
if (this.externalAuth) {
207+
errors.throwErr(errors.ERR_WRONG_CRED_FOR_EXTAUTH);
208+
}
199209
outOptions.password = options.password;
200210
}
201211

test/externalAuth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ const dbConfig = require('./dbconfig.js');
9292
}
9393
);
9494
},
95-
// NJS-136: user and password should not be set when using external authentication
96-
/NJS-136:/
95+
// ORA-01017: ORA-01017: invalid credential or not authorized; logon denied'
96+
/ORA-01017:/
9797
);
9898
}); // 5.1.3
9999

test/externalProxyAuth.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,27 @@ describe('180. externalProxyAuth.js', function() {
120120
externalAuth: true,
121121
});
122122
},
123-
/DPI-1069:/
123+
/NJS-140:/
124124
);
125125
});
126+
127+
it('180.1.6 Non-Pool Connect: External Auth with proxy and session user', async function() {
128+
if (!dbConfig.test.externalAuth || !dbConfig.test.proxySessionUser) {
129+
this.skip();
130+
}
131+
132+
await assert.rejects(
133+
async () => {
134+
await oracledb.getConnection({
135+
connectString: dbConfig.connectString,
136+
user: `${dbConfig.user}[${dbConfig.test.proxySessionUser}]`,
137+
externalAuth: true,
138+
});
139+
},
140+
/NJS-140:/
141+
);
142+
});
143+
126144
});
127145

128146
describe('180.2 Pooled Connect', function() {
@@ -262,7 +280,7 @@ describe('180. externalProxyAuth.js', function() {
262280
async () => {
263281
await pool.getConnection({user: dbConfig.test.proxySessionUser});
264282
},
265-
/DPI-1069:/
283+
/NJS-140:/
266284
);
267285
await pool.close(0);
268286
});

test/list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4344,6 +4344,7 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
43444344
180.1.3 Non-Pool Connect: Basic Auth with proxy
43454345
180.1.4 Non-Pool Connect: External Auth with proxy
43464346
180.1.5 Non-Pool Connect: External Auth with proxy no brackets
4347+
180.1.6 Non-Pool Connect: External Auth with proxy and session user
43474348
180.2 Pooled Connect
43484349
180.2.1 Pooled Connect: Basic Auth
43494350
180.2.2 Pooled Connect: External Auth

0 commit comments

Comments
 (0)