@@ -10,7 +10,8 @@ import {
1010 MongoAPIError ,
1111 MongoDriverError ,
1212 MongoInvalidArgumentError ,
13- MongoParseError
13+ MongoParseError ,
14+ MongoRuntimeError
1415} from '../../src/error' ;
1516import { MongoClient , MongoOptions } from '../../src/mongo_client' ;
1617
@@ -573,4 +574,51 @@ describe('Connection String', function () {
573574 expect ( client . s . options ) . to . have . property ( flag , null ) ;
574575 } ) ;
575576 } ) ;
577+
578+ describe ( 'IPv6 host addresses' , ( ) => {
579+ it ( 'should not allow multiple unbracketed portless localhost IPv6 addresses' , ( ) => {
580+ // Note there is no "port-full" version of this test, there's no way to distinguish when a port begins without brackets
581+ expect ( ( ) => new MongoClient ( 'mongodb://::1,::1,::1/test' ) ) . to . throw (
582+ / i n v a l i d c o n n e c t i o n s t r i n g / i
583+ ) ;
584+ } ) ;
585+
586+ it ( 'should not allow multiple unbracketed portless remote IPv6 addresses' , ( ) => {
587+ expect (
588+ ( ) =>
589+ new MongoClient (
590+ 'mongodb://ABCD:f::abcd:abcd:abcd:abcd,ABCD:f::abcd:abcd:abcd:abcd,ABCD:f::abcd:abcd:abcd:abcd/test'
591+ )
592+ ) . to . throw ( MongoRuntimeError ) ;
593+ } ) ;
594+
595+ it ( 'should allow multiple bracketed portless localhost IPv6 addresses' , ( ) => {
596+ const client = new MongoClient ( 'mongodb://[::1],[::1],[::1]/test' ) ;
597+ expect ( client . options . hosts ) . to . deep . equal ( [
598+ { host : '::1' , port : 27017 , isIPv6 : true } ,
599+ { host : '::1' , port : 27017 , isIPv6 : true } ,
600+ { host : '::1' , port : 27017 , isIPv6 : true }
601+ ] ) ;
602+ } ) ;
603+
604+ it ( 'should allow multiple bracketed portless localhost IPv6 addresses' , ( ) => {
605+ const client = new MongoClient (
606+ 'mongodb://[ABCD:f::abcd:abcd:abcd:abcd],[ABCD:f::abcd:abcd:abcd:abcd],[ABCD:f::abcd:abcd:abcd:abcd]/test'
607+ ) ;
608+ expect ( client . options . hosts ) . to . deep . equal ( [
609+ { host : 'abcd:f::abcd:abcd:abcd:abcd' , port : 27017 , isIPv6 : true } ,
610+ { host : 'abcd:f::abcd:abcd:abcd:abcd' , port : 27017 , isIPv6 : true } ,
611+ { host : 'abcd:f::abcd:abcd:abcd:abcd' , port : 27017 , isIPv6 : true }
612+ ] ) ;
613+ } ) ;
614+
615+ it ( 'should allow multiple bracketed port-full IPv6 addresses' , ( ) => {
616+ const client = new MongoClient ( 'mongodb://[::1]:27018,[::1]:27019,[::1]:27020/test' ) ;
617+ expect ( client . options . hosts ) . to . deep . equal ( [
618+ { host : '::1' , port : 27018 , isIPv6 : true } ,
619+ { host : '::1' , port : 27019 , isIPv6 : true } ,
620+ { host : '::1' , port : 27020 , isIPv6 : true }
621+ ] ) ;
622+ } ) ;
623+ } ) ;
576624} ) ;
0 commit comments