@@ -10,6 +10,7 @@ import {
1010 checkParentDomainMatch ,
1111 compareObjectId ,
1212 decorateWithExplain ,
13+ DEFAULT_ALLOWED_HOSTS ,
1314 Explain ,
1415 hasAtomicOperators ,
1516 HostAddress ,
@@ -149,6 +150,26 @@ describe('driver utils', function () {
149150 } ) ;
150151 } ) ;
151152
153+ context ( 'when the wildcard starts with *.' , function ( ) {
154+ it ( 'returns false' , function ( ) {
155+ expect ( hostMatchesWildcards ( 'test-mongodb.com' , [ '*.mongodb.com' , 'test2' ] ) ) . to . be
156+ . false ;
157+ } ) ;
158+ } ) ;
159+
160+ context ( 'when using default allowed hosts' , function ( ) {
161+ it ( 'returns false' , function ( ) {
162+ for ( const host of DEFAULT_ALLOWED_HOSTS ) {
163+ // Only test the wildcard hosts, the non-wildcard hosts are tested in other test cases
164+ if ( ! host . startsWith ( '*.' ) ) {
165+ continue ;
166+ }
167+ const wrongHost = host . replace ( '*.' , 'test-' ) ;
168+ expect ( hostMatchesWildcards ( wrongHost , DEFAULT_ALLOWED_HOSTS ) ) . to . be . false ;
169+ }
170+ } ) ;
171+ } ) ;
172+
152173 context ( 'when the host matches a FQDN' , function ( ) {
153174 it ( 'returns true' , function ( ) {
154175 expect ( hostMatchesWildcards ( 'mongodb.net' , [ '*.mongodb.net' , 'other' ] ) ) . to . be . true ;
@@ -222,6 +243,14 @@ describe('driver utils', function () {
222243 . to . be . false ;
223244 } ) ;
224245 } ) ;
246+
247+ context ( 'when the host does not match partial matches' , function ( ) {
248+ it ( 'returns false' , function ( ) {
249+ expect (
250+ hostMatchesWildcards ( '/tmp/test-mongodb-27017.sock' , [ '*/mongodb-27017.sock' , 'test2' ] )
251+ ) . to . be . false ;
252+ } ) ;
253+ } ) ;
225254 } ) ;
226255 } ) ;
227256
0 commit comments