@@ -225,6 +225,34 @@ describe('resolveMongodbSrv', () => {
225225 await resolveMongodbSrv ( 'mongodb+srv://server.example.com/?srvMaxHosts=1' , { dns } ) ,
226226 / ^ m o n g o d b : \/ \/ h o s t [ 1 - 3 ] \. e x a m p l e \. c o m \/ \? t l s = t r u e $ / ) ;
227227 } ) ;
228+
229+ it ( 'rejects SRV records without additional subdomain when parent domain has fewer than 3 parts' , async ( ) => {
230+ txtResult = [ ] ;
231+ srvResult = [ { name : 'example.com' , port : 27017 } ] ;
232+ await assert . rejects ( resolveMongodbSrv ( 'mongodb+srv://example.com' , { dns } ) ) ;
233+ } ) ;
234+
235+ it ( 'allow trailing dot in SRV lookup' , async ( ) => {
236+ txtResult = [ ] ;
237+ srvResult = [
238+ { name : 'asdf.example.com' , port : 27017 } ,
239+ { name : 'meow.example.com' , port : 27017 }
240+ ] ;
241+ assert . strictEqual (
242+ await resolveMongodbSrv ( 'mongodb+srv://server.example.com.' , { dns } ) ,
243+ 'mongodb://asdf.example.com,meow.example.com/?tls=true' ) ;
244+
245+ srvResult = [
246+ { name : 'asdf.example.com.' , port : 27017 } ,
247+ { name : 'meow.example.com' , port : 27017 }
248+ ] ;
249+ assert . strictEqual (
250+ await resolveMongodbSrv ( 'mongodb+srv://server.example.com' , { dns } ) ,
251+ 'mongodb://asdf.example.com.,meow.example.com/?tls=true' ) ;
252+ assert . strictEqual (
253+ await resolveMongodbSrv ( 'mongodb+srv://server.example.com.' , { dns } ) ,
254+ 'mongodb://asdf.example.com.,meow.example.com/?tls=true' ) ;
255+ } ) ;
228256 } ) ;
229257
230258 for ( const [ name , dnsProvider ] of [
0 commit comments