@@ -44,6 +44,13 @@ describe('Connection String', function () {
4444 } ) ;
4545 } ) ;
4646
47+ it ( 'throws an error related to the option that was given an empty value' , function ( ) {
48+ expect ( ( ) => parseOptions ( 'mongodb://localhost?tls=' , { } ) ) . to . throw (
49+ MongoAPIError ,
50+ / t l s " c a n n o t / i
51+ ) ;
52+ } ) ;
53+
4754 it ( 'should provide a default port if one is not provided' , function ( ) {
4855 const options = parseOptions ( 'mongodb://hostname' ) ;
4956 expect ( options . hosts [ 0 ] . socketPath ) . to . be . undefined ;
@@ -122,21 +129,18 @@ describe('Connection String', function () {
122129
123130 describe ( 'readPreferenceTags option' , function ( ) {
124131 context ( 'when the option is passed in the uri' , ( ) => {
125- it ( 'should throw an error if no value is passed for readPreferenceTags' , ( ) => {
126- expect ( ( ) => parseOptions ( 'mongodb://hostname?readPreferenceTags=' ) ) . to . throw (
127- MongoAPIError
128- ) ;
129- } ) ;
130132 it ( 'should parse a single read preference tag' , ( ) => {
131133 const options = parseOptions ( 'mongodb://hostname?readPreferenceTags=bar:foo' ) ;
132134 expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } ] ) ;
133135 } ) ;
136+
134137 it ( 'should parse multiple readPreferenceTags' , ( ) => {
135138 const options = parseOptions (
136139 'mongodb://hostname?readPreferenceTags=bar:foo&readPreferenceTags=baz:bar'
137140 ) ;
138141 expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } , { baz : 'bar' } ] ) ;
139142 } ) ;
143+
140144 it ( 'should parse multiple readPreferenceTags for the same key' , ( ) => {
141145 const options = parseOptions (
142146 'mongodb://hostname?readPreferenceTags=bar:foo&readPreferenceTags=bar:banana&readPreferenceTags=baz:bar'
@@ -147,6 +151,19 @@ describe('Connection String', function () {
147151 { baz : 'bar' }
148152 ] ) ;
149153 } ) ;
154+
155+ it ( 'should parse multiple and empty readPreferenceTags' , ( ) => {
156+ const options = parseOptions (
157+ 'mongodb://hostname?readPreferenceTags=bar:foo&readPreferenceTags=baz:bar&readPreferenceTags='
158+ ) ;
159+ expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } , { baz : 'bar' } , { } ] ) ;
160+ } ) ;
161+
162+ it ( 'will set "__proto__" as own property on readPreferenceTag' , ( ) => {
163+ const options = parseOptions ( 'mongodb://hostname?readPreferenceTags=__proto__:foo' ) ;
164+ expect ( options . readPreference . tags ?. [ 0 ] ) . to . have . own . property ( '__proto__' , 'foo' ) ;
165+ expect ( Object . getPrototypeOf ( options . readPreference . tags ?. [ 0 ] ) ) . to . be . null ;
166+ } ) ;
150167 } ) ;
151168
152169 context ( 'when the option is passed in the options object' , ( ) => {
@@ -156,12 +173,14 @@ describe('Connection String', function () {
156173 } ) ;
157174 expect ( options . readPreference . tags ) . to . deep . equal ( [ ] ) ;
158175 } ) ;
176+
159177 it ( 'should parse a single readPreferenceTags object' , ( ) => {
160178 const options = parseOptions ( 'mongodb://hostname?' , {
161179 readPreferenceTags : [ { bar : 'foo' } ]
162180 } ) ;
163181 expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } ] ) ;
164182 } ) ;
183+
165184 it ( 'should parse multiple readPreferenceTags' , ( ) => {
166185 const options = parseOptions ( 'mongodb://hostname?' , {
167186 readPreferenceTags : [ { bar : 'foo' } , { baz : 'bar' } ]
@@ -493,6 +512,18 @@ describe('Connection String', function () {
493512 ) ;
494513 } ) ;
495514
515+ it ( 'throws an error for repeated options that can only appear once' , function ( ) {
516+ // At the time of writing, readPreferenceTags is the only options that can be repeated
517+ expect ( ( ) => parseOptions ( 'mongodb://localhost/?compressors=zstd&compressors=zstd' ) ) . to . throw (
518+ MongoInvalidArgumentError ,
519+ / c a n n o t a p p e a r m o r e t h a n o n c e /
520+ ) ;
521+ expect ( ( ) => parseOptions ( 'mongodb://localhost/?tls=true&tls=true' ) ) . to . throw (
522+ MongoInvalidArgumentError ,
523+ / c a n n o t a p p e a r m o r e t h a n o n c e /
524+ ) ;
525+ } ) ;
526+
496527 it ( 'should validate authMechanism' , function ( ) {
497528 expect ( ( ) => parseOptions ( 'mongodb://localhost/?authMechanism=DOGS' ) ) . to . throw (
498529 MongoParseError ,
0 commit comments