@@ -122,21 +122,18 @@ describe('Connection String', function () {
122
122
123
123
describe ( 'readPreferenceTags option' , function ( ) {
124
124
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
- } ) ;
130
125
it ( 'should parse a single read preference tag' , ( ) => {
131
126
const options = parseOptions ( 'mongodb://hostname?readPreferenceTags=bar:foo' ) ;
132
127
expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } ] ) ;
133
128
} ) ;
129
+
134
130
it ( 'should parse multiple readPreferenceTags' , ( ) => {
135
131
const options = parseOptions (
136
132
'mongodb://hostname?readPreferenceTags=bar:foo&readPreferenceTags=baz:bar'
137
133
) ;
138
134
expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } , { baz : 'bar' } ] ) ;
139
135
} ) ;
136
+
140
137
it ( 'should parse multiple readPreferenceTags for the same key' , ( ) => {
141
138
const options = parseOptions (
142
139
'mongodb://hostname?readPreferenceTags=bar:foo&readPreferenceTags=bar:banana&readPreferenceTags=baz:bar'
@@ -147,6 +144,19 @@ describe('Connection String', function () {
147
144
{ baz : 'bar' }
148
145
] ) ;
149
146
} ) ;
147
+
148
+ it ( 'should parse multiple and empty readPreferenceTags' , ( ) => {
149
+ const options = parseOptions (
150
+ 'mongodb://hostname?readPreferenceTags=bar:foo&readPreferenceTags=baz:bar&readPreferenceTags='
151
+ ) ;
152
+ expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } , { baz : 'bar' } , { } ] ) ;
153
+ } ) ;
154
+
155
+ it ( 'will set "__proto__" as own property on readPreferenceTag' , ( ) => {
156
+ const options = parseOptions ( 'mongodb://hostname?readPreferenceTags=__proto__:foo' ) ;
157
+ expect ( options . readPreference . tags ?. [ 0 ] ) . to . have . own . property ( '__proto__' , 'foo' ) ;
158
+ expect ( Object . getPrototypeOf ( options . readPreference . tags ?. [ 0 ] ) ) . to . be . null ;
159
+ } ) ;
150
160
} ) ;
151
161
152
162
context ( 'when the option is passed in the options object' , ( ) => {
@@ -156,12 +166,14 @@ describe('Connection String', function () {
156
166
} ) ;
157
167
expect ( options . readPreference . tags ) . to . deep . equal ( [ ] ) ;
158
168
} ) ;
169
+
159
170
it ( 'should parse a single readPreferenceTags object' , ( ) => {
160
171
const options = parseOptions ( 'mongodb://hostname?' , {
161
172
readPreferenceTags : [ { bar : 'foo' } ]
162
173
} ) ;
163
174
expect ( options . readPreference . tags ) . to . deep . equal ( [ { bar : 'foo' } ] ) ;
164
175
} ) ;
176
+
165
177
it ( 'should parse multiple readPreferenceTags' , ( ) => {
166
178
const options = parseOptions ( 'mongodb://hostname?' , {
167
179
readPreferenceTags : [ { bar : 'foo' } , { baz : 'bar' } ]
@@ -493,6 +505,18 @@ describe('Connection String', function () {
493
505
) ;
494
506
} ) ;
495
507
508
+ it ( 'throws an error for repeated options that can only appear once' , function ( ) {
509
+ // At the time of writing, readPreferenceTags is the only options that can be repeated
510
+ expect ( ( ) => parseOptions ( 'mongodb://localhost/?compressors=zstd&compressors=zstd' ) ) . to . throw (
511
+ MongoInvalidArgumentError ,
512
+ / c a n n o t a p p e a r m o r e t h a n o n c e /
513
+ ) ;
514
+ expect ( ( ) => parseOptions ( 'mongodb://localhost/?tls=true&tls=true' ) ) . to . throw (
515
+ MongoInvalidArgumentError ,
516
+ / c a n n o t a p p e a r m o r e t h a n o n c e /
517
+ ) ;
518
+ } ) ;
519
+
496
520
it ( 'should validate authMechanism' , function ( ) {
497
521
expect ( ( ) => parseOptions ( 'mongodb://localhost/?authMechanism=DOGS' ) ) . to . throw (
498
522
MongoParseError ,
0 commit comments