Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
feat(kerberos): expose warning for kerberos mismatch versions
Browse files Browse the repository at this point in the history
We were originally blindly catching errors for a kerberos version
mismatch, and silently failing. This exposes the error message
to users if it exists.

Fixes NODE-1523
  • Loading branch information
daprahamian authored and mbroadst committed Jun 26, 2018
1 parent d95a4d1 commit efc0e43
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
18 changes: 18 additions & 0 deletions lib/auth/getKerberos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const requireOptional = require('require_optional');

let Kerberos = null;
let MongoAuthProcess = null;

try {
const kerberos = requireOptional('kerberos');
if (kerberos) {
Kerberos = kerberos.Kerberos;
MongoAuthProcess = kerberos.processes.MongoAuthProcess;
}
} catch (err) {
console.warn(err.message);
}

module.exports = { Kerberos, MongoAuthProcess };
22 changes: 7 additions & 15 deletions lib/auth/gssapi.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict';

var f = require('util').format,
require_optional = require('require_optional'),
Query = require('../connection/commands').Query,
MongoError = require('../error').MongoError;
const f = require('util').format;
const Query = require('../connection/commands').Query;
const MongoError = require('../error').MongoError;

// Kerberos class
const Kerberos = require('./getKerberos').Kerberos;
const MongoAuthProcess = require('./getKerberos').MongoAuthProcess;

var AuthSession = function(db, username, password, options) {
this.db = db;
Expand All @@ -20,17 +23,6 @@ AuthSession.prototype.equal = function(session) {
);
};

// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;

// Try to grab the Kerberos class
try {
Kerberos = require_optional('kerberos').Kerberos;
// Authentication process for Mongo
MongoAuthProcess = require_optional('kerberos').processes.MongoAuthProcess;
} catch (err) {} // eslint-disable-line

/**
* Creates a new GSSAPI authentication mechanism
* @class
Expand Down
22 changes: 7 additions & 15 deletions lib/auth/sspi.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict';

var f = require('util').format,
require_optional = require('require_optional'),
Query = require('../connection/commands').Query,
MongoError = require('../error').MongoError;
const f = require('util').format;
const Query = require('../connection/commands').Query;
const MongoError = require('../error').MongoError;

// Kerberos class
const Kerberos = require('./getKerberos').Kerberos;
const MongoAuthProcess = require('./getKerberos').MongoAuthProcess;

var AuthSession = function(db, username, password, options) {
this.db = db;
Expand All @@ -20,17 +23,6 @@ AuthSession.prototype.equal = function(session) {
);
};

// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;

// Try to grab the Kerberos class
try {
Kerberos = require_optional('kerberos').Kerberos;
// Authentication process for Mongo
MongoAuthProcess = require_optional('kerberos').processes.MongoAuthProcess;
} catch (err) {} // eslint-disable-line

/**
* Creates a new SSPI authentication mechanism
* @class
Expand Down

0 comments on commit efc0e43

Please sign in to comment.