diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 4bb5d2ae8e..73611cadee 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -1076,6 +1076,13 @@ tasks: VERSION: latest TOPOLOGY: server - func: run tls tests + - name: test-auth-ldap + tags: + - auth + - ldap + commands: + - func: install dependencies + - func: run ldap tests - name: test-latest-ocsp-valid-cert-server-staples tags: - ocsp @@ -1371,6 +1378,7 @@ buildvariants: - test-2.6-sharded_cluster-unified - test-atlas-connectivity - test-tls-support + - test-auth-ldap - test-latest-ocsp-valid-cert-server-staples - test-latest-ocsp-invalid-cert-server-staples - test-latest-ocsp-valid-cert-server-does-not-staple @@ -1482,6 +1490,7 @@ buildvariants: - test-2.6-replica_set-unified - test-2.6-sharded_cluster-unified - test-atlas-connectivity + - test-auth-ldap - name: ubuntu-14.04-dubnium display_name: Ubuntu 14.04 Node Dubnium run_on: ubuntu1404-test @@ -1557,6 +1566,7 @@ buildvariants: - test-3.2-sharded_cluster-unified - test-atlas-connectivity - test-tls-support + - test-auth-ldap - test-latest-ocsp-valid-cert-server-staples - test-latest-ocsp-invalid-cert-server-staples - test-latest-ocsp-valid-cert-server-does-not-staple diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index f649f55fdb..c28eadef28 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -126,6 +126,11 @@ TASKS.push( }, { func: 'run tls tests' } ] + }, + { + name: 'test-auth-ldap', + tags: ['auth', 'ldap'], + commands: [{ func: 'install dependencies' }, { func: 'run ldap tests' }] } ); diff --git a/.evergreen/run-ldap-tests.sh b/.evergreen/run-ldap-tests.sh new file mode 100644 index 0000000000..88dd1b19e9 --- /dev/null +++ b/.evergreen/run-ldap-tests.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -o errexit # Exit the script with error if any of the commands fail + +export PROJECT_DIRECTORY="$(pwd)" +NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts" +export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + +npm run check:ldap diff --git a/package.json b/package.json index 97380aef6a..2b0add9a81 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "scripts": { "atlas": "mocha --opts '{}' ./test/manual/atlas_connectivity.test.js", "check:tls": "mocha --opts '{}' test/manual/tls_support.test.js", + "check:ldap": "mocha --opts '{}' test/manual/ldap.test.js", "test": "npm run lint && mocha --recursive test/functional test/unit test/core", "test-nolint": "mocha --recursive test/functional test/unit test/core", "coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/core test/unit test/functional", diff --git a/test/functional/ldap.test.js b/test/functional/ldap.test.js deleted file mode 100644 index 80adcb1bf1..0000000000 --- a/test/functional/ldap.test.js +++ /dev/null @@ -1,117 +0,0 @@ -'use strict'; - -var format = require('util').format; -var test = require('./shared').assert; -var setupDatabase = require('./shared').setupDatabase; - -describe('LDAP', function() { - before(function() { - return setupDatabase(this.configuration); - }); - - /** - * @ignore - */ - it('Should correctly authenticate against ldap', { - metadata: { requires: { topology: 'ldap' } }, - - // The actual test we wish to run - test: function(done) { - var configuration = this.configuration; - - // KDC Server - var server = 'ldaptest.10gen.cc'; - var user = 'drivers-team'; - var pass = 'mongor0x$xgen'; - - // Url - var url = format( - 'mongodb://%s:%s@%s/test?authMechanism=PLAIN&maxPoolSize=1', - user, - pass, - server - ); - - const client = configuration.newClient(url); - client.connect(function(err, client) { - test.equal(null, err); - - client - .db('ldap') - .collection('test') - .findOne(function(err, doc) { - test.equal(null, err); - test.equal(true, doc.ldap); - - client.close(done); - }); - }); - } - }); - - /** - * @ignore - */ - it('Should correctly reauthenticate against ldap', { - metadata: { requires: { topology: 'ldap' } }, - - // The actual test we wish to run - test: function(done) { - var configuration = this.configuration; - - // KDC Server - var server = 'ldaptest.10gen.cc'; - var user = 'drivers-team'; - var pass = 'mongor0x$xgen'; - - // Url - var url = format( - 'mongodb://%s:%s@%s/test?authMechanism=PLAIN&maxPoolSize=1', - user, - pass, - server - ); - - const client = configuration.newClient(url); - client.connect(function(err, client) { - test.equal(null, err); - - client - .db('ldap') - .collection('test') - .findOne(function(err, doc) { - test.equal(null, err); - test.equal(true, doc.ldap); - - client.topology.once('reconnect', function() { - // Await reconnect and re-authentication - client - .db('ldap') - .collection('test') - .findOne(function(err, doc) { - test.equal(null, err); - test.equal(true, doc.ldap); - - // Attempt disconnect again - client.topology.connections()[0].destroy(); - - // Await reconnect and re-authentication - client - .db('ldap') - .collection('test') - .findOne(function(err, doc) { - test.equal(null, err); - test.equal(true, doc.ldap); - - client.close(done); - }); - }); - }); - - // Force close - client.topology.connections()[0].destroy(); - }); - }); - } - }); -}); diff --git a/test/manual/ldap.test.js b/test/manual/ldap.test.js new file mode 100644 index 0000000000..0685f99d2f --- /dev/null +++ b/test/manual/ldap.test.js @@ -0,0 +1,26 @@ +'use strict'; +const MongoClient = require('../..').MongoClient; +var test = require('../functional/shared').assert; + +describe('LDAP', function() { + if (process.env.MONGODB_URI == null) { + throw new Error(`skipping SSL tests, MONGODB_URI environment variable is not defined`); + } + + it('Should correctly authenticate against ldap', function(done) { + const client = new MongoClient(process.env.MONGODB_URI); + client.connect(function(err, client) { + test.equal(null, err); + + client + .db('ldap') + .collection('test') + .findOne(function(err, doc) { + test.equal(null, err); + test.equal(true, doc.ldap); + + client.close(done); + }); + }); + }); +});