Skip to content

Commit 06a2444

Browse files
authored
fix: add host/port to cmap connection
NODE-2731
1 parent 4cc6bcc commit 06a2444

File tree

6 files changed

+59
-14
lines changed

6 files changed

+59
-14
lines changed

.evergreen/config.yml

+21-5
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ functions:
179179
working_dir: src
180180
script: |
181181
KRB5_KEYTAB='${gssapi_auth_keytab_base64}' KRB5_PRINCIPAL='${gssapi_auth_principal}' \
182-
MONGODB_URI='${gssapi_auth_mongodb_uri}' \
182+
MONGODB_URI='${gssapi_auth_mongodb_uri}' UNIFIED=${UNIFIED} \
183183
NODE_LTS_NAME='${NODE_LTS_NAME}' bash ${PROJECT_DIRECTORY}/.evergreen/run-kerberos-tests.sh
184184
run ldap tests:
185185
- command: shell.exec
@@ -1074,13 +1074,26 @@ tasks:
10741074
commands:
10751075
- func: install dependencies
10761076
- func: run atlas tests
1077-
- name: test-auth-kerberos
1077+
- name: test-auth-kerberos-legacy
10781078
tags:
10791079
- auth
10801080
- kerberos
1081+
- legacy
10811082
commands:
10821083
- func: install dependencies
10831084
- func: run kerberos tests
1085+
vars:
1086+
UNIFIED: 0
1087+
- name: test-auth-kerberos-unified
1088+
tags:
1089+
- auth
1090+
- kerberos
1091+
- unified
1092+
commands:
1093+
- func: install dependencies
1094+
- func: run kerberos tests
1095+
vars:
1096+
UNIFIED: 1
10841097
- name: test-auth-ldap
10851098
tags:
10861099
- auth
@@ -1393,7 +1406,8 @@ buildvariants:
13931406
- test-2.6-replica_set-unified
13941407
- test-2.6-sharded_cluster-unified
13951408
- test-atlas-connectivity
1396-
- test-auth-kerberos
1409+
- test-auth-kerberos-legacy
1410+
- test-auth-kerberos-unified
13971411
- test-auth-ldap
13981412
- test-tls-support
13991413
- test-latest-ocsp-valid-cert-server-staples
@@ -1507,7 +1521,8 @@ buildvariants:
15071521
- test-2.6-replica_set-unified
15081522
- test-2.6-sharded_cluster-unified
15091523
- test-atlas-connectivity
1510-
- test-auth-kerberos
1524+
- test-auth-kerberos-legacy
1525+
- test-auth-kerberos-unified
15111526
- test-auth-ldap
15121527
- name: ubuntu-14.04-dubnium
15131528
display_name: Ubuntu 14.04 Node Dubnium
@@ -1583,7 +1598,8 @@ buildvariants:
15831598
- test-3.2-replica_set-unified
15841599
- test-3.2-sharded_cluster-unified
15851600
- test-atlas-connectivity
1586-
- test-auth-kerberos
1601+
- test-auth-kerberos-legacy
1602+
- test-auth-kerberos-unified
15871603
- test-auth-ldap
15881604
- test-tls-support
15891605
- test-latest-ocsp-valid-cert-server-staples

.evergreen/config.yml.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ functions:
218218
working_dir: src
219219
script: |
220220
KRB5_KEYTAB='${gssapi_auth_keytab_base64}' KRB5_PRINCIPAL='${gssapi_auth_principal}' \
221-
MONGODB_URI='${gssapi_auth_mongodb_uri}' \
221+
MONGODB_URI='${gssapi_auth_mongodb_uri}' UNIFIED=${UNIFIED} \
222222
NODE_LTS_NAME='${NODE_LTS_NAME}' bash ${PROJECT_DIRECTORY}/.evergreen/run-kerberos-tests.sh
223223

224224
"run ldap tests":

.evergreen/generate_evergreen_tasks.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,27 @@ TASKS.push(
109109
commands: [{ func: 'install dependencies' }, { func: 'run atlas tests' }]
110110
},
111111
{
112-
name: 'test-auth-kerberos',
113-
tags: ['auth', 'kerberos'],
112+
name: 'test-auth-kerberos-legacy',
113+
tags: ['auth', 'kerberos', 'legacy'],
114114
commands: [
115115
{ func: 'install dependencies' },
116-
{ func: 'run kerberos tests' }
116+
{ func: 'run kerberos tests',
117+
vars: {
118+
UNIFIED: 0
119+
}
120+
}
121+
]
122+
},
123+
{
124+
name: 'test-auth-kerberos-unified',
125+
tags: ['auth', 'kerberos', 'unified'],
126+
commands: [
127+
{ func: 'install dependencies' },
128+
{ func: 'run kerberos tests',
129+
vars: {
130+
UNIFIED: 1
131+
}
132+
}
117133
]
118134
},
119135
{
@@ -311,6 +327,11 @@ const getTaskList = (() => {
311327
return true;
312328
}
313329

330+
// kerberos tests don't require mongo orchestration
331+
if (task.tags.filter(tag => tag === 'kerberos').length) {
332+
return true;
333+
}
334+
314335
const { VERSION } = tasksWithVars[0].vars || {};
315336
if (VERSION === 'latest') {
316337
return semver.satisfies(semver.coerce(LATEST_EFFECTIVE_VERSION), mongoVersion);

lib/cmap/connection.js

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class Connection extends EventEmitter {
3333
this.address = streamIdentifier(stream);
3434
this.bson = options.bson;
3535
this.socketTimeout = typeof options.socketTimeout === 'number' ? options.socketTimeout : 360000;
36+
this.host = options.host || 'localhost';
37+
this.port = options.port || 27017;
3638
this.monitorCommands =
3739
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false;
3840
this.closed = false;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"scripts": {
6767
"atlas": "mocha --opts '{}' ./test/manual/atlas_connectivity.test.js",
68-
"check:kerberos": "mocha --opts '{}' test/manual/kerberos.test.js",
68+
"check:kerberos": "mocha --opts '{}' -t 60000 test/manual/kerberos.test.js",
6969
"check:ldap": "mocha --opts '{}' test/manual/ldap.test.js",
7070
"check:tls": "mocha --opts '{}' test/manual/tls_support.test.js",
7171
"test": "npm run lint && mocha --recursive test/functional test/unit test/core",

test/manual/kerberos.test.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const MongoClient = require('../..').MongoClient;
33
const chai = require('chai');
44
const expect = chai.expect;
55

6+
const clientOptions = parseInt(process.env.UNIFIED) ? { useUnifiedTopology: true } : {};
7+
68
describe('Kerberos', function() {
79
if (process.env.MONGODB_URI == null) {
810
console.log('skipping Kerberos tests, MONGODB_URI environment variable is not defined');
@@ -19,7 +21,7 @@ describe('Kerberos', function() {
1921
}
2022

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

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

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

7680
it('should fail to authenticate with bad credentials', function(done) {
7781
const client = new MongoClient(
78-
krb5Uri.replace(encodeURIComponent(process.env.KRB5_PRINCIPAL), 'bad%40creds.cc')
82+
krb5Uri.replace(encodeURIComponent(process.env.KRB5_PRINCIPAL), 'bad%40creds.cc'),
83+
clientOptions
7984
);
8085
client.connect(function(err) {
8186
expect(err).to.exist;
8287
expect(err.message).to.match(/Authentication failed/);
88+
expect(client.isConnected()).to.be.false;
8389
done();
8490
});
8591
});

0 commit comments

Comments
 (0)