Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding external authentication capability when using oracledb driver #1716

Merged
merged 8 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(include Oracle Wallet Authentication), WebSQL) query builder for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... including Oracle Wallet...

Node.js and the Browser, featuring:

- [transactions](http://knexjs.org/#Transactions)
Expand Down
20 changes: 14 additions & 6 deletions src/dialects/oracledb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } :
Copy link
Member

@elhigu elhigu Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 spaces too wide indentation... or below 2 spaces too narrow

{
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;
}
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
42 changes: 42 additions & 0 deletions test/unit/dialects/oracledb.js
Original file line number Diff line number Diff line change
@@ -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);
});
});