node-oracledb/test/dbconfig.js

164 lines
5.4 KiB
JavaScript
Raw Normal View History

2024-05-02 23:38:00 +08:00
/* Copyright (c) 2015, 2024, Oracle and/or its affiliates. */
2015-07-20 12:42:12 +08:00
/******************************************************************************
*
* 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.
2015-07-20 12:42:12 +08:00
*
* 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.
2015-07-20 12:42:12 +08:00
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
2015-07-20 12:42:12 +08:00
*
* 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.
2015-07-20 12:42:12 +08:00
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
2023-02-21 12:04:16 +08:00
* dbconfig.js
2015-07-20 12:42:12 +08:00
*
* DESCRIPTION
* This file provides the configuration for all the tests.
2018-04-03 05:41:52 +08:00
* There are TWO options for users to choose:
2016-03-24 14:09:53 +08:00
*
* 1. Edit the credentials section of this file.
2018-04-03 05:41:52 +08:00
* 2. Set these environment variables:
* NODE_ORACLEDB_USER, NODE_ORACLEDB_PASSWORD, NODE_ORACLEDB_CONNECTIONSTRING,
* NODE_ORACLEDB_DBA_PRIVILEGE,
* NODE_ORACLEDB_DBA_USER, NODE_ORACLEDB_DBA_PASSWORD
* If required:
* NODE_ORACLEDB_EXTERNALAUTH,
* NODE_ORACLEDB_PROXY_SESSION_USER, NODE_ORACLEDB_DRCP,
2024-05-22 18:56:52 +08:00
* NODE_ORACLEDB_IMPLICIT_POOL
* NODE_ORACLEDB_WALLET_LOCATION, NODE_ORACLEDB_WALLET_PASSWORD
2015-07-20 12:42:12 +08:00
*
*****************************************************************************/
2023-05-23 22:20:06 +08:00
const oracledb = require('oracledb');
2023-02-21 12:21:57 +08:00
const config = {
2019-02-08 09:55:21 +08:00
test: {
externalAuth: false,
2019-02-08 09:55:21 +08:00
DBA_PRIVILEGE: false,
2023-02-21 12:04:16 +08:00
printDebugMsg: false,
mode: 'thin',
2023-05-23 22:20:06 +08:00
instantClientPath: '',
2023-05-24 02:01:22 +08:00
isCloudService: false,
isCmanTdm: false,
2024-05-22 18:56:52 +08:00
drcp: false,
implicitPool: false
2019-02-08 09:55:21 +08:00
}
};
2018-04-03 05:41:52 +08:00
2023-06-20 18:28:50 +08:00
let counter = 0;
2018-04-03 05:41:52 +08:00
if (process.env.NODE_ORACLEDB_CONNECTIONSTRING) {
config.connectString = process.env.NODE_ORACLEDB_CONNECTIONSTRING;
2019-02-08 09:55:21 +08:00
} else {
throw new Error("Database Connect String is not set! Set the Environment Variable NODE_ORACLEDB_CONNECTIONSTRING.");
2018-04-03 05:41:52 +08:00
}
if (process.env.NODE_ORACLEDB_EXTERNALAUTH) {
2024-05-02 23:38:00 +08:00
const eauth = process.env.NODE_ORACLEDB_EXTERNALAUTH;
if (eauth.toLowerCase() === 'true') {
if (oracledb.thin) {
throw new Error("Cannot use externalAuth with thin driver.");
}
2018-04-03 05:41:52 +08:00
config.test.externalAuth = true;
}
}
2023-05-24 02:01:22 +08:00
if (process.env.NODE_ORACLEDB_DRCP) {
config.test.drcp = (process.env.NODE_ORACLEDB_DRCP.toLowerCase() === 'true');
}
2024-05-22 18:56:52 +08:00
if (process.env.NODE_ORACLEDB_IMPLICIT_POOL) {
if (!process.env.NODE_ORACLEDB_DRCP)
throw new Error("For Implicit pooling tests, NODE_ORACLEDB_DRCP needs to be enabled! Set the Environment Variable NODE_ORACLEDB_DRCP");
else
config.test.implicitPool = (process.env.NODE_ORACLEDB_IMPLICIT_POOL.toLowerCase() === 'true');
}
2023-12-05 18:27:34 +08:00
if (process.env.NODE_ORACLEDB_USER) {
config.user = process.env.NODE_ORACLEDB_USER;
} else {
throw new Error("Schema User name is not set! Set the Environment Variable NODE_ORACLEDB_USER.");
}
2020-11-19 10:06:47 +08:00
2023-12-05 18:27:34 +08:00
if (process.env.NODE_ORACLEDB_PASSWORD) {
config.password = process.env.NODE_ORACLEDB_PASSWORD;
} else {
throw new Error("Schema User Password is not set! Set the Environment Variable NODE_ORACLEDB_PASSWORD.");
2020-11-19 10:06:47 +08:00
}
if (process.env.NODE_ORACLEDB_QA) {
2024-05-02 23:38:00 +08:00
const isQA = process.env.NODE_ORACLEDB_QA;
if (isQA.toLowerCase() === 'true') {
config.test.NODE_ORACLEDB_QA = true;
}
}
2018-04-03 05:41:52 +08:00
if (process.env.NODE_ORACLEDB_DBA_PRIVILEGE) {
2024-05-02 23:38:00 +08:00
const priv = process.env.NODE_ORACLEDB_DBA_PRIVILEGE;
if (priv.toLowerCase() == 'true') {
2018-04-03 05:41:52 +08:00
config.test.DBA_PRIVILEGE = true;
}
}
2023-05-23 22:20:06 +08:00
if (process.env.NODE_ORACLEDB_WALLET_PASSWORD) {
config.walletPassword = process.env.NODE_ORACLEDB_WALLET_PASSWORD;
}
if (process.env.NODE_ORACLEDB_WALLET_LOCATION) {
config.walletLocation = process.env.NODE_ORACLEDB_WALLET_LOCATION;
}
2018-04-03 05:41:52 +08:00
if (process.env.NODE_ORACLEDB_DBA_USER) {
config.test.DBA_user = process.env.NODE_ORACLEDB_DBA_USER;
2019-02-08 09:55:21 +08:00
} else if (config.test.DBA_PRIVILEGE) {
throw new Error("DBA Privilege is set to True but DBA username is not set! Set the Environment Variable NODE_ORACLEDB_DBA_USER.");
2018-04-03 05:41:52 +08:00
}
if (process.env.NODE_ORACLEDB_DBA_PASSWORD) {
config.test.DBA_password = process.env.NODE_ORACLEDB_DBA_PASSWORD;
2019-02-08 09:55:21 +08:00
} else if (config.test.DBA_PRIVILEGE) {
throw new Error("DBA Privilege is set to True but DBA Password is not set! Set the Environment Variable NODE_ORACLEDB_DBA_PASSWORD.");
2018-04-03 05:41:52 +08:00
}
2018-03-27 14:04:00 +08:00
2019-01-03 06:10:21 +08:00
if (process.env.NODE_ORACLEDB_PROXY_SESSION_USER) {
config.test.proxySessionUser = process.env.NODE_ORACLEDB_PROXY_SESSION_USER;
}
2019-03-13 07:48:49 +08:00
if (process.env.NODE_PRINT_DEBUG_MESSAGE) {
2024-05-02 23:38:00 +08:00
const printDebugMsg = process.env.NODE_PRINT_DEBUG_MESSAGE;
if (printDebugMsg.toLowerCase() == 'true') {
2019-03-13 07:48:49 +08:00
config.test.printDebugMsg = true;
}
}
2023-05-23 22:20:06 +08:00
if (process.env.NODE_ORACLEDB_CLIENT_LIB_DIR) {
config.test.instantClientPath = process.env.NODE_ORACLEDB_CLIENT_LIB_DIR;
}
if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
config.test.mode = 'thick';
console.log("Thick mode selected");
oracledb.initOracleClient({ libDir: config.test.instantClientPath });
} else {
console.log("Thin mode selected");
}
2023-06-20 18:28:50 +08:00
config.createUser = () => {
++counter;
return "NJS_" + counter.toString() + config.user;
};
2021-04-01 12:48:37 +08:00
module.exports = config;