Permalink
Browse files

Adding external authentication capability when using oracledb driver (#…

…1716)

* Adding external authentication capability as mentioned in https://github.com/oracle/node-oracledb/blob/master/doc/api.md#extauth

* Add unit test for externalAuth

* Cover the connection string part

* Update documentation

* fix spaces

* Hide the fake Oracle server error

* minor grammar changes and spaces changes
  • Loading branch information...
1 parent 2ddcf64 commit da5ed9682587980256c909526ca15a58301e7f4a @nixgadget nixgadget committed with elhigu Nov 30, 2016
Showing with 62 additions and 7 deletions.
  1. +1 −1 README.md
  2. +14 −6 src/dialects/oracledb/index.js
  3. +5 −0 test/index.js
  4. +42 −0 test/unit/dialects/oracledb.js
View
@@ -8,7 +8,7 @@
> **A SQL query builder that is _flexible_, _portable_, and _fun_ to use!**
-A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, WebSQL, Oracle) query builder for
+A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle(including Oracle Wallet Authentication), WebSQL) query builder for
Node.js and the Browser, featuring:
- [transactions](http://knexjs.org/#Transactions)
@@ -65,15 +65,23 @@ Client_Oracledb.prototype.acquireRawConnection = function() {
const client = this;
const asyncConnection = new Promise(function(resolver, rejecter) {
- const oracleDbConfig = {
- user: client.connectionSettings.user,
- password: client.connectionSettings.password,
- connectString: client.connectionSettings.connectString ||
- (client.connectionSettings.host + '/' + client.connectionSettings.database)
- }
+ // If external authentication dont have to worry about username/password and
+ // if not need to set the username and password
+ const oracleDbConfig = client.connectionSettings.externalAuth ?
+ { externalAuth : client.connectionSettings.externalAuth } :
+ {
+ user : client.connectionSettings.user,
+ password : client.connectionSettings.password
+ }
+
+ // In the case of external authentication connection string will be given
+ oracleDbConfig.connectString = client.connectionSettings.connectString ||
+ (client.connectionSettings.host + '/' + client.connectionSettings.database);
+
if (client.connectionSettings.prefetchRowCount) {
oracleDbConfig.prefetchRows = client.connectionSettings.prefetchRowCount
}
+
if (!_.isUndefined(client.connectionSettings.stmtCacheSize)) {
oracleDbConfig.stmtCacheSize = client.connectionSettings.stmtCacheSize;
}
View
@@ -31,6 +31,11 @@ describe('Query Building Tests', function() {
require('./unit/schema/oracledb')
})
+describe('ExternalAuth ORACLE Tests', function() {
+ this.timeout(process.env.KNEX_TEST_TIMEOUT || 5000);
+ require('./unit/dialects/oracledb')
+})
+
describe('Integration Tests', function() {
this.timeout(process.env.KNEX_TEST_TIMEOUT || 5000);
require('./integration')
@@ -0,0 +1,42 @@
+/*global it, describe, expect*/
+
+'use strict';
+var expect = require('chai').expect;
+var knex = require('../../../knex');
+var knexInstance = knex(
+ {
+ client: 'oracledb',
+ connection: {
+ user : "user",
+ password : "password",
+ connectString : 'connect-string',
+ externalAuth : true,
+ host : "host",
+ database : "database"
+ }
+ }
+ );
+var spy;
+
+beforeEach(function() {
+ spy = sinon.spy(knexInstance.client.driver, "getConnection");
+});
+
+afterEach(function() {
+ sinon.restore(knexInstance.client.driver.getConnection);
+});
+
+describe("OracleDb externalAuth", function() {
+ it('externalAuth and connectString should be sent to the getConnection', function() {
+ var connectionWithExternalAuth = {
+ connectString: "connect-string",
+ externalAuth: true
+ }
+ knexInstance.client.acquireRawConnection().then(
+ function(resolve) {},
+ function(reject) {}
+ );
+ expect(spy).to.have.callCount(1);
+ expect(spy).to.have.been.calledWith(connectionWithExternalAuth);
+ });
+});

0 comments on commit da5ed96

Please sign in to comment.