@@ -940,56 +940,69 @@ describe('driver utils', function () {
940
940
} ) ;
941
941
942
942
describe ( 'checkParentDomainMatch()' , ( ) => {
943
- const exampleSrvName = 'i-love-javascript.mongodb.io' ;
944
- const exampleSrvNameWithDot = 'i-love-javascript.mongodb.io.' ;
945
- const exampleHostNameWithoutDot = 'i-love-javascript-00.mongodb.io' ;
946
- const exampleHostNamesWithDot = exampleHostNameWithoutDot + '.' ;
947
- const exampleHostNamThatDoNotMatchParent = 'i-love-javascript-00.evil-mongodb.io' ;
948
- const exampleHostNamThatDoNotMatchParentWithDot = 'i-love-javascript-00.evil-mongodb.io.' ;
949
943
950
- context ( 'when address does not match parent domain' , ( ) => {
951
- it ( 'without a trailing dot throws' , ( ) => {
952
- expect ( ( ) =>
953
- checkParentDomainMatch ( exampleHostNamThatDoNotMatchParent , exampleSrvName )
954
- ) . to . throw ( 'Server record does not share hostname with parent URI' ) ;
955
- } ) ;
944
+ const exampleSrvName = [ 'i-love-js' , 'i-love-js.mongodb' , 'i-love-javascript.mongodb.io' ] ;
945
+ const exampleSrvNameWithDot = [ 'i-love-js.' , 'i-love-js.mongodb.' , 'i-love-javascript.mongodb.io.' ] ;
946
+ const exampleHostNameWithoutDot = [ 'js-00.i-love-js' , 'js-00.i-love-js.mongodb' , 'i-love-javascript-00.mongodb.io' ] ;
947
+ const exampleHostNamesWithDot = [ 'js-00.i-love-js.' , 'js-00.i-love-js.mongodb.' , 'i-love-javascript-00.mongodb.io.' ] ;
948
+ const exampleHostNameThatDoNotMatchParent = [ 'js-00.i-love-js-a-little' , 'js-00.i-love-js-a-little.mongodb' , 'i-love-javascript-00.evil-mongodb.io' ] ;
949
+ const exampleHostNameThatDoNotMatchParentWithDot = [ 'i-love-js' , '' , 'i-love-javascript-00.evil-mongodb.io.' ] ;
950
+
951
+ for ( let num = 0 ; num < 3 ; num += 1 ) {
952
+ context ( `when srvName has ${ num + 1 } part${ num !== 0 ? 's' : '' } ` , ( ) => {
953
+ context ( 'when address does not match parent domain' , ( ) => {
954
+ it ( 'without a trailing dot throws' , ( ) => {
955
+ expect ( ( ) =>
956
+ checkParentDomainMatch ( exampleHostNameThatDoNotMatchParent [ num ] , exampleSrvName [ num ] )
957
+ ) . to . throw ( 'Server record does not share hostname with parent URI' ) ;
958
+ } ) ;
956
959
957
- it ( 'with a trailing dot throws' , ( ) => {
958
- expect ( ( ) =>
959
- checkParentDomainMatch ( exampleHostNamThatDoNotMatchParentWithDot , exampleSrvName )
960
- ) . to . throw ( 'Server record does not share hostname with parent URI' ) ;
961
- } ) ;
962
- } ) ;
960
+ it ( 'with a trailing dot throws' , ( ) => {
961
+ expect ( ( ) =>
962
+ checkParentDomainMatch ( exampleHostNameThatDoNotMatchParentWithDot [ num ] , exampleSrvName [ num ] )
963
+ ) . to . throw ( ) ;
964
+ } ) ;
965
+ } ) ;
963
966
964
- context ( 'when addresses in SRV record end with a dot' , ( ) => {
965
- it ( 'accepts address since it is considered to still match the parent domain' , ( ) => {
966
- expect ( ( ) =>
967
- checkParentDomainMatch ( exampleHostNamesWithDot , exampleSrvName )
968
- ) . to . not . throw ( ) ;
969
- } ) ;
970
- } ) ;
967
+ context ( 'when addresses in SRV record end with a dot' , ( ) => {
968
+ it ( 'accepts address since it is considered to still match the parent domain' , ( ) => {
969
+ expect ( ( ) =>
970
+ checkParentDomainMatch ( exampleHostNamesWithDot [ num ] , exampleSrvName [ num ] )
971
+ ) . to . not . throw ( ) ;
972
+ } ) ;
973
+ } ) ;
971
974
972
- context ( 'when SRV host ends with a dot' , ( ) => {
973
- it ( 'accepts address if it ends with a dot' , ( ) => {
974
- expect ( ( ) =>
975
- checkParentDomainMatch ( exampleHostNamesWithDot , exampleSrvNameWithDot )
976
- ) . to . not . throw ( ) ;
977
- } ) ;
975
+ context ( 'when SRV host ends with a dot' , ( ) => {
976
+ it ( 'accepts address if it ends with a dot' , ( ) => {
977
+ expect ( ( ) =>
978
+ checkParentDomainMatch ( exampleHostNamesWithDot [ num ] , exampleSrvNameWithDot [ num ] )
979
+ ) . to . not . throw ( ) ;
980
+ } ) ;
978
981
979
- it ( 'accepts address if it does not end with a dot' , ( ) => {
980
- expect ( ( ) =>
981
- checkParentDomainMatch ( exampleHostNameWithoutDot , exampleSrvName )
982
- ) . to . not . throw ( ) ;
983
- } ) ;
984
- } ) ;
982
+ it ( 'accepts address if it does not end with a dot' , ( ) => {
983
+ expect ( ( ) =>
984
+ checkParentDomainMatch ( exampleHostNameWithoutDot [ num ] , exampleSrvNameWithDot [ num ] )
985
+ ) . to . not . throw ( ) ;
986
+ } ) ;
987
+
988
+ if ( num < 2 ) {
989
+ it ( 'does not accept address if it does not contain an extra domain level' , ( ) => {
990
+ expect ( ( ) =>
991
+ checkParentDomainMatch ( exampleSrvNameWithDot [ num ] , exampleSrvNameWithDot [ num ] )
992
+ ) . to . throw ( 'Server record does not have at least one more domain level than parent URI' ) ;
993
+ } ) ;
994
+ }
995
+ } ) ;
985
996
986
- context ( 'when addresses in SRV record end without dots' , ( ) => {
987
- it ( 'accepts address since it matches the parent domain' , ( ) => {
988
- expect ( ( ) =>
989
- checkParentDomainMatch ( exampleHostNamesWithDot , exampleSrvName )
990
- ) . to . not . throw ( ) ;
997
+ context ( 'when addresses in SRV record end without dots' , ( ) => {
998
+ it ( 'accepts address since it matches the parent domain' , ( ) => {
999
+ expect ( ( ) =>
1000
+ checkParentDomainMatch ( exampleHostNamesWithDot [ num ] , exampleSrvName [ num ] )
1001
+ ) . to . not . throw ( ) ;
1002
+ } ) ;
1003
+ } ) ;
991
1004
} ) ;
992
- } ) ;
1005
+ }
993
1006
} ) ;
994
1007
995
1008
describe ( 'isUint8Array()' , ( ) => {
0 commit comments