File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ function parseSslOptions(family, options) {
243243 }
244244
245245 // Set default sni servername to be the same as host
246- if ( result . servername == null ) {
246+ if ( result . servername == null && ! net . isIP ( result . host ) ) {
247247 result . servername = result . host ;
248248 }
249249
Original file line number Diff line number Diff line change 11'use strict' ;
22const MongoClient = require ( '../..' ) . MongoClient ;
3+ const expect = require ( 'chai' ) . expect ;
4+ const util = require ( 'util' ) ;
5+ const dns = require ( 'dns' ) ;
6+ const dnsLookup = util . promisify ( dns . lookup ) ;
37
48const REQUIRED_ENV = [ 'MONGODB_URI' , 'SSL_KEY_FILE' , 'SSL_CA_FILE' ] ;
59
@@ -28,6 +32,24 @@ describe('TLS Support', function() {
2832 . join ( '&' ) } `
2933 )
3034 ) ;
35+
36+ it ( 'should ignore ip addresses in servername' , function ( ) {
37+ const hostname = connectionString . match ( / m o n g o d b : \/ \/ ( .+ ) : / ) ;
38+ return dnsLookup ( hostname )
39+ . then ( res => {
40+ const client = new MongoClient ( connectionString . replace ( hostname , res [ 0 ] . address ) , {
41+ tls : true
42+ } ) ;
43+ return client . connect ( ) ;
44+ } )
45+ . then ( client => {
46+ const connections = client . topology . connections ( ) ;
47+
48+ for ( const connection of connections ) {
49+ expect ( connection . options . servername ) . to . not . exist ;
50+ }
51+ } ) ;
52+ } ) ;
3153} ) ;
3254
3355function makeConnectionTest ( connectionString , clientOptions ) {
You can’t perform that action at this time.
0 commit comments