@@ -4,6 +4,7 @@ import { ObjectId } from 'bson';
44import { expect } from 'chai' ;
55import * as sinon from 'sinon' ;
66
7+ import { DEFAULT_ALLOWED_HOSTS } from '../../src/cmap/auth/mongo_credentials' ;
78import { LEGACY_HELLO_COMMAND } from '../../src/constants' ;
89import { MongoInvalidArgumentError , MongoRuntimeError } from '../../src/error' ;
910import { decorateWithExplain , Explain } from '../../src/explain' ;
@@ -155,6 +156,19 @@ describe('driver utils', function () {
155156 } ) ;
156157 } ) ;
157158
159+ context ( 'when using default allowed hosts' , function ( ) {
160+ it ( 'returns false' , function ( ) {
161+ for ( const host of DEFAULT_ALLOWED_HOSTS ) {
162+ // Only test the wildcard hosts, the non-wildcard hosts are tested in other test cases
163+ if ( ! host . startsWith ( '*.' ) ) {
164+ continue ;
165+ }
166+ const wrongHost = host . replace ( '*.' , 'test-' ) ;
167+ expect ( hostMatchesWildcards ( wrongHost , DEFAULT_ALLOWED_HOSTS ) ) . to . be . false ;
168+ }
169+ } ) ;
170+ } ) ;
171+
158172 context ( 'when the host matches a FQDN' , function ( ) {
159173 it ( 'returns true' , function ( ) {
160174 expect ( hostMatchesWildcards ( 'mongodb.net' , [ '*.mongodb.net' , 'other' ] ) ) . to . be . true ;
0 commit comments