Skip to content

Commit 07b2b0d

Browse files
authored
fix: add host/port to cmap connection
NODE-2731
1 parent 7520a74 commit 07b2b0d

File tree

6 files changed

+59
-14
lines changed

6 files changed

+59
-14
lines changed

.evergreen/config.yml

Lines changed: 21 additions & 5 deletions
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
@@ -788,13 +788,26 @@ tasks:
788788
commands:
789789
- func: install dependencies
790790
- func: run atlas tests
791-
- name: test-auth-kerberos
791+
- name: test-auth-kerberos-legacy
792792
tags:
793793
- auth
794794
- kerberos
795+
- legacy
795796
commands:
796797
- func: install dependencies
797798
- func: run kerberos tests
799+
vars:
800+
UNIFIED: 0
801+
- name: test-auth-kerberos-unified
802+
tags:
803+
- auth
804+
- kerberos
805+
- unified
806+
commands:
807+
- func: install dependencies
808+
- func: run kerberos tests
809+
vars:
810+
UNIFIED: 1
798811
- name: test-auth-ldap
799812
tags:
800813
- auth
@@ -877,7 +890,8 @@ buildvariants:
877890
- test-2.6-replica_set-unified
878891
- test-2.6-sharded_cluster-unified
879892
- test-atlas-connectivity
880-
- test-auth-kerberos
893+
- test-auth-kerberos-legacy
894+
- test-auth-kerberos-unified
881895
- test-auth-ldap
882896
- test-tls-support
883897
- name: macos-1014-dubnium
@@ -977,7 +991,8 @@ buildvariants:
977991
- test-2.6-replica_set-unified
978992
- test-2.6-sharded_cluster-unified
979993
- test-atlas-connectivity
980-
- test-auth-kerberos
994+
- test-auth-kerberos-legacy
995+
- test-auth-kerberos-unified
981996
- test-auth-ldap
982997
- name: ubuntu-14.04-dubnium
983998
display_name: Ubuntu 14.04 Node Dubnium
@@ -1047,7 +1062,8 @@ buildvariants:
10471062
- test-3.2-replica_set-unified
10481063
- test-3.2-sharded_cluster-unified
10491064
- test-atlas-connectivity
1050-
- test-auth-kerberos
1065+
- test-auth-kerberos-legacy
1066+
- test-auth-kerberos-unified
10511067
- test-auth-ldap
10521068
- test-tls-support
10531069
- name: ubuntu-18.04-dubnium

.evergreen/config.yml.in

Lines changed: 1 addition & 1 deletion
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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,27 @@ TASKS.push(
108108
commands: [{ func: 'install dependencies' }, { func: 'run atlas tests' }]
109109
},
110110
{
111-
name: 'test-auth-kerberos',
112-
tags: ['auth', 'kerberos'],
111+
name: 'test-auth-kerberos-legacy',
112+
tags: ['auth', 'kerberos', 'legacy'],
113113
commands: [
114114
{ func: 'install dependencies' },
115-
{ func: 'run kerberos tests' }
115+
{ func: 'run kerberos tests',
116+
vars: {
117+
UNIFIED: 0
118+
}
119+
}
120+
]
121+
},
122+
{
123+
name: 'test-auth-kerberos-unified',
124+
tags: ['auth', 'kerberos', 'unified'],
125+
commands: [
126+
{ func: 'install dependencies' },
127+
{ func: 'run kerberos tests',
128+
vars: {
129+
UNIFIED: 1
130+
}
131+
}
116132
]
117133
},
118134
{
@@ -155,6 +171,11 @@ const getTaskList = (() => {
155171
return true;
156172
}
157173

174+
// kerberos tests don't require mongo orchestration
175+
if (task.tags.filter(tag => tag === 'kerberos').length) {
176+
return true;
177+
}
178+
158179
const { VERSION } = tasksWithVars[0].vars || {};
159180
if (VERSION === 'latest') {
160181
return semver.satisfies(semver.coerce(LATEST_EFFECTIVE_VERSION), mongoVersion);

lib/cmap/connection.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Connection extends EventEmitter {
3232
this.address = streamIdentifier(stream);
3333
this.bson = options.bson;
3434
this.socketTimeout = typeof options.socketTimeout === 'number' ? options.socketTimeout : 360000;
35+
this.host = options.host || 'localhost';
36+
this.port = options.port || 27017;
3537
this.monitorCommands =
3638
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false;
3739
this.closed = false;

package.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 4 deletions
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)