Skip to content

Commit

Permalink
fix: add host/port to cmap connection
Browse files Browse the repository at this point in the history
  • Loading branch information
emadum authored Aug 13, 2020
1 parent 4cc6bcc commit 06a2444
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
26 changes: 21 additions & 5 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ functions:
working_dir: src
script: |
KRB5_KEYTAB='${gssapi_auth_keytab_base64}' KRB5_PRINCIPAL='${gssapi_auth_principal}' \
MONGODB_URI='${gssapi_auth_mongodb_uri}' \
MONGODB_URI='${gssapi_auth_mongodb_uri}' UNIFIED=${UNIFIED} \
NODE_LTS_NAME='${NODE_LTS_NAME}' bash ${PROJECT_DIRECTORY}/.evergreen/run-kerberos-tests.sh
run ldap tests:
- command: shell.exec
Expand Down Expand Up @@ -1074,13 +1074,26 @@ tasks:
commands:
- func: install dependencies
- func: run atlas tests
- name: test-auth-kerberos
- name: test-auth-kerberos-legacy
tags:
- auth
- kerberos
- legacy
commands:
- func: install dependencies
- func: run kerberos tests
vars:
UNIFIED: 0
- name: test-auth-kerberos-unified
tags:
- auth
- kerberos
- unified
commands:
- func: install dependencies
- func: run kerberos tests
vars:
UNIFIED: 1
- name: test-auth-ldap
tags:
- auth
Expand Down Expand Up @@ -1393,7 +1406,8 @@ buildvariants:
- test-2.6-replica_set-unified
- test-2.6-sharded_cluster-unified
- test-atlas-connectivity
- test-auth-kerberos
- test-auth-kerberos-legacy
- test-auth-kerberos-unified
- test-auth-ldap
- test-tls-support
- test-latest-ocsp-valid-cert-server-staples
Expand Down Expand Up @@ -1507,7 +1521,8 @@ buildvariants:
- test-2.6-replica_set-unified
- test-2.6-sharded_cluster-unified
- test-atlas-connectivity
- test-auth-kerberos
- test-auth-kerberos-legacy
- test-auth-kerberos-unified
- test-auth-ldap
- name: ubuntu-14.04-dubnium
display_name: Ubuntu 14.04 Node Dubnium
Expand Down Expand Up @@ -1583,7 +1598,8 @@ buildvariants:
- test-3.2-replica_set-unified
- test-3.2-sharded_cluster-unified
- test-atlas-connectivity
- test-auth-kerberos
- test-auth-kerberos-legacy
- test-auth-kerberos-unified
- test-auth-ldap
- test-tls-support
- test-latest-ocsp-valid-cert-server-staples
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ functions:
working_dir: src
script: |
KRB5_KEYTAB='${gssapi_auth_keytab_base64}' KRB5_PRINCIPAL='${gssapi_auth_principal}' \
MONGODB_URI='${gssapi_auth_mongodb_uri}' \
MONGODB_URI='${gssapi_auth_mongodb_uri}' UNIFIED=${UNIFIED} \
NODE_LTS_NAME='${NODE_LTS_NAME}' bash ${PROJECT_DIRECTORY}/.evergreen/run-kerberos-tests.sh

"run ldap tests":
Expand Down
27 changes: 24 additions & 3 deletions .evergreen/generate_evergreen_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,27 @@ TASKS.push(
commands: [{ func: 'install dependencies' }, { func: 'run atlas tests' }]
},
{
name: 'test-auth-kerberos',
tags: ['auth', 'kerberos'],
name: 'test-auth-kerberos-legacy',
tags: ['auth', 'kerberos', 'legacy'],
commands: [
{ func: 'install dependencies' },
{ func: 'run kerberos tests' }
{ func: 'run kerberos tests',
vars: {
UNIFIED: 0
}
}
]
},
{
name: 'test-auth-kerberos-unified',
tags: ['auth', 'kerberos', 'unified'],
commands: [
{ func: 'install dependencies' },
{ func: 'run kerberos tests',
vars: {
UNIFIED: 1
}
}
]
},
{
Expand Down Expand Up @@ -311,6 +327,11 @@ const getTaskList = (() => {
return true;
}

// kerberos tests don't require mongo orchestration
if (task.tags.filter(tag => tag === 'kerberos').length) {
return true;
}

const { VERSION } = tasksWithVars[0].vars || {};
if (VERSION === 'latest') {
return semver.satisfies(semver.coerce(LATEST_EFFECTIVE_VERSION), mongoVersion);
Expand Down
2 changes: 2 additions & 0 deletions lib/cmap/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Connection extends EventEmitter {
this.address = streamIdentifier(stream);
this.bson = options.bson;
this.socketTimeout = typeof options.socketTimeout === 'number' ? options.socketTimeout : 360000;
this.host = options.host || 'localhost';
this.port = options.port || 27017;
this.monitorCommands =
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false;
this.closed = false;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"scripts": {
"atlas": "mocha --opts '{}' ./test/manual/atlas_connectivity.test.js",
"check:kerberos": "mocha --opts '{}' test/manual/kerberos.test.js",
"check:kerberos": "mocha --opts '{}' -t 60000 test/manual/kerberos.test.js",
"check:ldap": "mocha --opts '{}' test/manual/ldap.test.js",
"check:tls": "mocha --opts '{}' test/manual/tls_support.test.js",
"test": "npm run lint && mocha --recursive test/functional test/unit test/core",
Expand Down
14 changes: 10 additions & 4 deletions test/manual/kerberos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const MongoClient = require('../..').MongoClient;
const chai = require('chai');
const expect = chai.expect;

const clientOptions = parseInt(process.env.UNIFIED) ? { useUnifiedTopology: true } : {};

describe('Kerberos', function() {
if (process.env.MONGODB_URI == null) {
console.log('skipping Kerberos tests, MONGODB_URI environment variable is not defined');
Expand All @@ -19,7 +21,7 @@ describe('Kerberos', function() {
}

it('should authenticate with original uri', function(done) {
const client = new MongoClient(krb5Uri);
const client = new MongoClient(krb5Uri, clientOptions);
client.connect(function(err, client) {
expect(err).to.not.exist;
client
Expand All @@ -37,7 +39,8 @@ describe('Kerberos', function() {

it('validate that SERVICE_REALM and CANONICALIZE_HOST_NAME can be passed in', function(done) {
const client = new MongoClient(
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:false,SERVICE_REALM:windows&maxPoolSize=1`
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:false,SERVICE_REALM:windows&maxPoolSize=1`,
clientOptions
);
client.connect(function(err, client) {
expect(err).to.not.exist;
Expand All @@ -56,7 +59,8 @@ describe('Kerberos', function() {

it('should authenticate with additional authentication properties', function(done) {
const client = new MongoClient(
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:false&maxPoolSize=1`
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:false&maxPoolSize=1`,
clientOptions
);
client.connect(function(err, client) {
expect(err).to.not.exist;
Expand All @@ -75,11 +79,13 @@ describe('Kerberos', function() {

it('should fail to authenticate with bad credentials', function(done) {
const client = new MongoClient(
krb5Uri.replace(encodeURIComponent(process.env.KRB5_PRINCIPAL), 'bad%40creds.cc')
krb5Uri.replace(encodeURIComponent(process.env.KRB5_PRINCIPAL), 'bad%40creds.cc'),
clientOptions
);
client.connect(function(err) {
expect(err).to.exist;
expect(err.message).to.match(/Authentication failed/);
expect(client.isConnected()).to.be.false;
done();
});
});
Expand Down

0 comments on commit 06a2444

Please sign in to comment.