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) {
243
243
}
244
244
245
245
// Set default sni servername to be the same as host
246
- if ( result . servername == null ) {
246
+ if ( result . servername == null && ! net . isIP ( result . host ) ) {
247
247
result . servername = result . host ;
248
248
}
249
249
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
const 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 ) ;
3
7
4
8
const REQUIRED_ENV = [ 'MONGODB_URI' , 'SSL_KEY_FILE' , 'SSL_CA_FILE' ] ;
5
9
@@ -28,6 +32,24 @@ describe('TLS Support', function() {
28
32
. join ( '&' ) } `
29
33
)
30
34
) ;
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
+ } ) ;
31
53
} ) ;
32
54
33
55
function makeConnectionTest ( connectionString , clientOptions ) {
You can’t perform that action at this time.
0 commit comments