@@ -141,6 +141,85 @@ func TestIsOpForCloning(t *testing.T) {
141
141
}
142
142
}
143
143
144
+ func TestIsOpAllowed (t * testing.T ) {
145
+ testCases := []struct {
146
+ desc string
147
+ entry * db.Oplog
148
+ opAllowed bool
149
+ }{
150
+ {
151
+ desc : "any other than config" ,
152
+ entry : createInsertOp (t , "db1.c1" ),
153
+ opAllowed : true ,
154
+ },
155
+ {
156
+ desc : "config.chunks" ,
157
+ entry : createInsertOp (t , "config.chunks" ),
158
+ opAllowed : true ,
159
+ },
160
+ {
161
+ desc : "config.collections" ,
162
+ entry : createInsertOp (t , "config.collections" ),
163
+ opAllowed : true ,
164
+ },
165
+ {
166
+ desc : "config.databases" ,
167
+ entry : createInsertOp (t , "config.databases" ),
168
+ opAllowed : true ,
169
+ },
170
+ {
171
+ desc : "config.shards" ,
172
+ entry : createInsertOp (t , "config.shards" ),
173
+ opAllowed : true ,
174
+ },
175
+ {
176
+ desc : "config.tags" ,
177
+ entry : createUpdateOp (t , "config.tags" ),
178
+ opAllowed : true ,
179
+ },
180
+ {
181
+ desc : "config.version" ,
182
+ entry : createDeleteOp (t , "config.version" ),
183
+ opAllowed : true ,
184
+ },
185
+ {
186
+ desc : "dissalowed config collection" ,
187
+ entry : createInsertOp (t , "config.mongos" ),
188
+ opAllowed : false ,
189
+ },
190
+ {
191
+ desc : "wrong config.settings doc will not break" ,
192
+ entry : createDeleteOp (t , "config.settings" ),
193
+ opAllowed : true ,
194
+ },
195
+ {
196
+ desc : "settings doc for balancer" ,
197
+ entry : configSettingsBalancerEntry (),
198
+ opAllowed : false ,
199
+ },
200
+ {
201
+ desc : "settings doc for automerge" ,
202
+ entry : configSettingsAutomergeEntry (),
203
+ opAllowed : false ,
204
+ },
205
+ {
206
+ desc : "allowed settings doc" ,
207
+ entry : configSettingsAnyOtherEntry (),
208
+ opAllowed : true ,
209
+ },
210
+ }
211
+
212
+ for _ , tC := range testCases {
213
+ t .Run (tC .desc , func (t * testing.T ) {
214
+ res := isOpAllowed (tC .entry )
215
+ if res != tC .opAllowed {
216
+ t .Errorf ("%s: for entry: %+v isOpAllowed is: %t, but it should be opposite" ,
217
+ tC .desc , tC .entry , tC .opAllowed )
218
+ }
219
+ })
220
+ }
221
+ }
222
+
144
223
func TestApply (t * testing.T ) {
145
224
t .Run ("collection restore" , func (t * testing.T ) {
146
225
testCases := []struct {
@@ -638,3 +717,29 @@ func replaceNsWithinOpEntry(t *testing.T, jsonEntry, ns string) *db.Oplog {
638
717
}
639
718
return & oe
640
719
}
720
+
721
+ func configSettingsBalancerEntry () * db.Oplog {
722
+ return & db.Oplog {
723
+ Operation : "i" ,
724
+ Namespace : "config.settings" ,
725
+ Object : bson.D {{"_id" , "balancer" }, {"mode" , "off" }, {"stopped" , true }},
726
+ Query : bson.D {{"_id" , "balancer" }},
727
+ }
728
+ }
729
+
730
+ func configSettingsAutomergeEntry () * db.Oplog {
731
+ return & db.Oplog {
732
+ Operation : "u" ,
733
+ Namespace : "config.settings" ,
734
+ Query : bson.D {{"_id" , "automerge" }},
735
+ }
736
+ }
737
+
738
+ func configSettingsAnyOtherEntry () * db.Oplog {
739
+ return & db.Oplog {
740
+ Operation : "i" ,
741
+ Namespace : "config.settings" ,
742
+ Object : bson.D {{"_id" , "chunksize" }, {"value" , 128 }},
743
+ Query : bson.D {{"_id" , "chunksize" }},
744
+ }
745
+ }
0 commit comments