-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathexternalProxyAuth.js
329 lines (300 loc) · 11.7 KB
/
externalProxyAuth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/* Copyright (c) 2021, 2025, Oracle and/or its affiliates. */
/******************************************************************************
*
* This software is dual-licensed to you under the Universal Permissive License
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
* either license.
*
* If you elect to accept the software under the Apache License, Version 2.0,
* the following applies:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 180. externalProxyAuth.js
*
* DESCRIPTION
* Test external proxy authentication.
* Create a database user based on the client certificate's DN.
* e.g., create user ssluser identified externally as 'CN=client’
* Set NODE_ORACLEDB_PROXY_SESSION_USER to the newly created user.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
async function ShowUserInfo(conn) {
const result = await conn.execute(`
select
sys_context('USERENV', 'PROXY_USER'),
sys_context('USERENV', 'SESSION_USER')
from dual`);
return [result.rows[0][0], result.rows[0][1]];
}
describe('180. externalProxyAuth.js', function() {
before('Check version greater than 1202000000', async function() {
const preReqSucc = await testsUtil.checkPrerequisites(1202000000, 1202000000);
if (!preReqSucc) {
console.log(" Version less than 1202000000, Aborting.");
this.skip();
}
});
describe('180.1 Non-Pool Connect', function() {
it('180.1.1 Non-Pool Connect: Username-Password Auth', async function() {
const conn = await oracledb.getConnection(dbConfig);
const schema = await testsUtil.getUser(conn);
const [proxy_user, session_user] = await ShowUserInfo(conn);
assert.strictEqual(proxy_user, null);
assert.strictEqual(session_user, schema);
await conn.close();
});
it('180.1.2 Non-Pool Connect: External Auth', async function() {
if (!dbConfig.test.externalAuth) {
this.skip();
}
const conn = await oracledb.getConnection({
connectString: dbConfig.connectString,
externalAuth: true,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation
});
const schema = await testsUtil.getUser(conn);
const [proxy_user, session_user] = await ShowUserInfo(conn);
assert.strictEqual(proxy_user, null);
assert.strictEqual(session_user, schema);
await conn.close();
});
it('180.1.3 Non-Pool Connect: Username-Password Auth with proxy', async function() {
if (!dbConfig.test.proxySessionUser) {
this.skip();
}
const conn = await oracledb.getConnection({
...dbConfig,
user: `${dbConfig.user}[${dbConfig.test.proxySessionUser}]`
});
const [proxy_user, session_user] = await ShowUserInfo(conn);
assert.strictEqual(proxy_user, dbConfig.user.toUpperCase());
assert.strictEqual(session_user, dbConfig.test.proxySessionUser.toUpperCase());
await conn.close();
});
it('180.1.4 Non-Pool Connect: External Auth with proxy', async function() {
if (!dbConfig.test.externalAuth || !dbConfig.test.proxySessionUser) {
this.skip();
}
const dbaConn = await oracledb.getConnection({
user: dbConfig.test.DBA_user,
password: dbConfig.test.DBA_password,
connectString: dbConfig.connectString,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation,
privilege: oracledb.SYSDBA
});
await dbaConn.execute(`alter user ${dbConfig.user} grant connect through ${dbConfig.test.proxySessionUser}`);
await dbaConn.close();
const conn = await oracledb.getConnection({
connectString: dbConfig.connectString,
user: `[${dbConfig.user}]`,
externalAuth: true,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation
});
const [proxy_user, session_user] = await ShowUserInfo(conn);
assert.strictEqual(proxy_user, dbConfig.test.proxySessionUser.toUpperCase());
assert.strictEqual(session_user, dbConfig.user.toUpperCase());
await conn.close();
});
it('180.1.5 Non-Pool Connect: External Auth with proxy no brackets', async function() {
if (!dbConfig.test.externalAuth || !dbConfig.test.proxySessionUser) {
this.skip();
}
await assert.rejects(
async () => {
await oracledb.getConnection({
connectString: dbConfig.connectString,
user: dbConfig.test.proxySessionUser,
externalAuth: true,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation
});
},
/NJS-140:/
);
});
it('180.1.6 Non-Pool Connect: External Auth with proxy and session user', async function() {
if (!dbConfig.test.externalAuth || !dbConfig.test.proxySessionUser) {
this.skip();
}
await assert.rejects(
async () => {
await oracledb.getConnection({
connectString: dbConfig.connectString,
user: `${dbConfig.user}[${dbConfig.test.proxySessionUser}]`,
externalAuth: true,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation
});
},
/NJS-140:/
);
});
});
describe('180.2 Pooled Connect', function() {
it('180.2.1 Pooled Connect: Username-Password Auth', async function() {
const pool = await oracledb.createPool(dbConfig);
const conn = await pool.getConnection();
const schema = await testsUtil.getUser(conn);
const [proxy_user, session_user] = await ShowUserInfo(conn);
assert.strictEqual(proxy_user, null);
assert.strictEqual(session_user, schema);
await conn.close();
await pool.close(0);
});
it('180.2.2 Pooled Connect: External Auth', async function() {
if (!dbConfig.test.externalAuth) {
this.skip();
}
const pool = await oracledb.createPool({
connectString: dbConfig.connectString,
externalAuth: true,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation
});
const conn = await pool.getConnection();
const schema = await testsUtil.getUser(conn);
const [proxy_user, session_user] = await ShowUserInfo(conn);
assert.strictEqual(proxy_user, null);
assert.strictEqual(session_user, schema);
await conn.close();
await pool.close(0);
});
it('180.2.3 Pooled Connect: Username-Password Auth with proxy when create pool', async function() {
if (!dbConfig.test.proxySessionUser) {
this.skip();
}
const pool = await oracledb.createPool({
...dbConfig,
user: `${dbConfig.user}[${dbConfig.test.proxySessionUser}]`,
});
const conn = await pool.getConnection();
const [proxy_user, session_user] = await ShowUserInfo(conn);
assert.strictEqual(proxy_user, dbConfig.user.toUpperCase());
assert.strictEqual(session_user, dbConfig.test.proxySessionUser.toUpperCase());
await conn.close();
await pool.close(0);
});
it('180.2.4 Pooled Connect: Username-Password Auth with proxy when acquire connection', async function() {
if (oracledb.thin || !dbConfig.test.proxySessionUser) {
this.skip();
}
const pool = await oracledb.createPool({
...dbConfig,
homogeneous: false,
});
const conn = await pool.getConnection({ "user": dbConfig.test.proxySessionUser });
const [proxy_user, session_user] = await ShowUserInfo(conn);
assert.strictEqual(proxy_user, dbConfig.user.toUpperCase());
assert.strictEqual(session_user, dbConfig.test.proxySessionUser.toUpperCase());
await conn.close();
await pool.close(0);
});
it('180.2.5 Pooled Connect: Username-Password Auth with proxy when acquire connection', async function() {
if (oracledb.thin || !dbConfig.test.proxySessionUser) {
this.skip();
}
const pool = await oracledb.createPool({
...dbConfig,
homogeneous: false,
});
await assert.rejects(
async () => {
await pool.getConnection({ "user": `[${dbConfig.test.proxySessionUser}]` });
},
/ORA-00987:/
);
await pool.close(0);
});
it('180.2.6 Pooled Connect: External Auth with proxy when create pool', async function() {
if (!dbConfig.test.externalAuth || !dbConfig.test.proxySessionUser) {
this.skip();
}
await assert.rejects(
async () => {
await oracledb.createPool({
connectString: dbConfig.connectString,
user: `[${dbConfig.test.proxySessionUser}]`,
externalAuth: true,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation
});
},
/NJS-136:/
);
});
it('180.2.7 Pooled Connect: External Auth with proxy no brackets when create pool', async function() {
if (!dbConfig.test.externalAuth || !dbConfig.test.proxySessionUser) {
this.skip();
}
await assert.rejects(
async () => {
await oracledb.createPool({
connectString: dbConfig.connectString,
user: dbConfig.test.proxySessionUser,
externalAuth: true,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation
});
},
/NJS-136:/
);
});
it('180.2.8 Pooled Connect: External Auth with proxy when acquire connection', async function() {
// Currently, heterogeneous pools are not supported for thin mode.
if (oracledb.thin || !dbConfig.test.externalAuth || !dbConfig.test.proxySessionUser) {
this.skip();
}
const pool = await oracledb.createPool({
connectString: dbConfig.connectString,
externalAuth: true,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation
});
const conn = await pool.getConnection({user: `[${dbConfig.user.toUpperCase()}]`});
const [proxy_user, session_user] = await ShowUserInfo(conn);
assert.strictEqual(proxy_user, dbConfig.test.proxySessionUser.toUpperCase());
assert.strictEqual(session_user, dbConfig.user.toUpperCase());
await conn.close();
await pool.close(0);
});
it('180.2.9 Pooled Connect: External Auth with proxy no brackets when acquire connection', async function() {
if (!dbConfig.test.externalAuth || !dbConfig.test.proxySessionUser) {
this.skip();
}
const pool = await oracledb.createPool({
connectString: dbConfig.connectString,
externalAuth: true,
walletPassword: dbConfig.walletPassword,
walletLocation: dbConfig.walletLocation
});
await assert.rejects(
async () => {
await pool.getConnection({user: dbConfig.test.proxySessionUser});
},
/NJS-140:/
);
await pool.close(0);
});
});
});