@@ -11,6 +11,7 @@ import {
1111 HostAddress ,
1212 isHello ,
1313 List ,
14+ matchesParentDomain ,
1415 maybeCallback ,
1516 MongoDBNamespace ,
1617 shuffle
@@ -858,4 +859,46 @@ describe('driver utils', function () {
858859 it ( title , ( ) => expect ( compareObjectId ( oid1 , oid2 ) ) . to . equal ( result ) ) ;
859860 }
860861 } ) ;
862+
863+ describe ( 'matchesParentDomain()' , ( ) => {
864+ const exampleSrvName = 'i-love-javascript.mongodb.io' ;
865+ const exampleSrvNameWithDot = 'i-love-javascript.mongodb.io.' ;
866+ const exampleHostNameWithoutDot = 'i-love-javascript-00.mongodb.io' ;
867+ const exampleHostNamesWithDot = exampleHostNameWithoutDot + '.' ;
868+ const exampleHostNamThatDoNotMatchParent = 'i-love-javascript-00.evil-mongodb.io' ;
869+ const exampleHostNamThatDoNotMatchParentWithDot = 'i-love-javascript-00.evil-mongodb.io.' ;
870+
871+ context ( 'when address does not match parent domain' , ( ) => {
872+ it ( 'without a trailing dot returns false' , ( ) => {
873+ expect ( matchesParentDomain ( exampleHostNamThatDoNotMatchParent , exampleSrvName ) ) . to . be . false ;
874+ } ) ;
875+
876+ it ( 'with a trailing dot returns false' , ( ) => {
877+ expect ( matchesParentDomain ( exampleHostNamThatDoNotMatchParentWithDot , exampleSrvName ) ) . to . be
878+ . false ;
879+ } ) ;
880+ } ) ;
881+
882+ context ( 'when addresses in SRV record end with a dot' , ( ) => {
883+ it ( 'accepts address since it is considered to still match the parent domain' , ( ) => {
884+ expect ( matchesParentDomain ( exampleHostNamesWithDot , exampleSrvName ) ) . to . be . true ;
885+ } ) ;
886+ } ) ;
887+
888+ context ( 'when SRV host ends with a dot' , ( ) => {
889+ it ( 'accepts address if it ends with a dot' , ( ) => {
890+ expect ( matchesParentDomain ( exampleHostNamesWithDot , exampleSrvNameWithDot ) ) . to . be . true ;
891+ } ) ;
892+
893+ it ( 'accepts address if it does not end with a dot' , ( ) => {
894+ expect ( matchesParentDomain ( exampleHostNameWithoutDot , exampleSrvName ) ) . to . be . true ;
895+ } ) ;
896+ } ) ;
897+
898+ context ( 'when addresses in SRV record end without dots' , ( ) => {
899+ it ( 'accepts address since it matches the parent domain' , ( ) => {
900+ expect ( matchesParentDomain ( exampleHostNamesWithDot , exampleSrvName ) ) . to . be . true ;
901+ } ) ;
902+ } ) ;
903+ } ) ;
861904} ) ;
0 commit comments