forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRequestComplexity.spec.js
More file actions
855 lines (770 loc) · 27.2 KB
/
RequestComplexity.spec.js
File metadata and controls
855 lines (770 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
'use strict';
const Config = require('../lib/Config');
const auth = require('../lib/Auth');
const rest = require('../lib/rest');
describe('request complexity', () => {
function buildNestedInQuery(depth, className = '_User') {
let where = {};
for (let i = 0; i < depth; i++) {
where = { username: { $inQuery: { className, where } } };
}
return where;
}
function buildNestedNotInQuery(depth, className = '_User') {
let where = {};
for (let i = 0; i < depth; i++) {
where = { username: { $notInQuery: { className, where } } };
}
return where;
}
function buildNestedSelect(depth, className = '_User') {
let where = {};
for (let i = 0; i < depth; i++) {
where = { username: { $select: { query: { className, where }, key: 'username' } } };
}
return where;
}
function buildNestedDontSelect(depth, className = '_User') {
let where = {};
for (let i = 0; i < depth; i++) {
where = { username: { $dontSelect: { query: { className, where }, key: 'username' } } };
}
return where;
}
function buildNestedOrQuery(depth) {
let where = { username: 'test' };
for (let i = 0; i < depth; i++) {
where = { $or: [where, { username: 'test' }] };
}
return where;
}
function buildNestedAndQuery(depth) {
let where = { username: 'test' };
for (let i = 0; i < depth; i++) {
where = { $and: [where, { username: 'test' }] };
}
return where;
}
function buildNestedNorQuery(depth) {
let where = { username: 'test' };
for (let i = 0; i < depth; i++) {
where = { $nor: [where, { username: 'test' }] };
}
return where;
}
describe('config validation', () => {
it('should accept valid requestComplexity config', async () => {
await expectAsync(
reconfigureServer({
requestComplexity: {
includeDepth: 10,
includeCount: 100,
subqueryDepth: 5,
queryDepth: 10,
graphQLDepth: 15,
graphQLFields: 300,
},
})
).toBeResolved();
});
it('should accept -1 to disable a specific limit', async () => {
await expectAsync(
reconfigureServer({
requestComplexity: {
includeDepth: -1,
includeCount: -1,
subqueryDepth: -1,
queryDepth: -1,
graphQLDepth: -1,
graphQLFields: -1,
},
})
).toBeResolved();
});
it('should reject value of 0', async () => {
await expectAsync(
reconfigureServer({
requestComplexity: { includeDepth: 0 },
})
).toBeRejectedWith(
new Error('requestComplexity.includeDepth must be a positive integer or -1 to disable.')
);
});
it('should reject non-integer values', async () => {
await expectAsync(
reconfigureServer({
requestComplexity: { includeDepth: 3.5 },
})
).toBeRejectedWith(
new Error('requestComplexity.includeDepth must be a positive integer or -1 to disable.')
);
});
it('should reject non-boolean value for allowRegex', async () => {
await expectAsync(
reconfigureServer({
requestComplexity: { allowRegex: 'yes' },
})
).toBeRejectedWith(
new Error('requestComplexity.allowRegex must be a boolean.')
);
});
it('should reject unknown properties', async () => {
await expectAsync(
reconfigureServer({
requestComplexity: { unknownProp: 5 },
})
).toBeRejectedWith(
new Error("requestComplexity contains unknown property 'unknownProp'.")
);
});
it('should reject non-object values', async () => {
await expectAsync(
reconfigureServer({
requestComplexity: 'invalid',
})
).toBeRejectedWith(new Error('requestComplexity must be an object.'));
});
it('should apply defaults for missing properties', async () => {
await reconfigureServer({
requestComplexity: { includeDepth: 3 },
});
const config = Config.get('test');
expect(config.requestComplexity.includeDepth).toBe(3);
expect(config.requestComplexity.includeCount).toBe(-1);
expect(config.requestComplexity.subqueryDepth).toBe(-1);
expect(config.requestComplexity.queryDepth).toBe(-1);
expect(config.requestComplexity.graphQLDepth).toBe(-1);
expect(config.requestComplexity.graphQLFields).toBe(-1);
});
it('should apply full defaults when not configured', async () => {
await reconfigureServer({});
const config = Config.get('test');
expect(config.requestComplexity).toEqual({
allowRegex: true,
batchRequestLimit: -1,
includeDepth: -1,
includeCount: -1,
subqueryDepth: -1,
subqueryLimit: -1,
queryDepth: -1,
graphQLDepth: -1,
graphQLFields: -1,
});
});
});
describe('subquery depth', () => {
let config;
beforeEach(async () => {
await reconfigureServer({
requestComplexity: { subqueryDepth: 3 },
});
config = Config.get('test');
});
it('should allow $inQuery within depth limit', async () => {
const where = buildNestedInQuery(3);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeResolved();
});
it('should reject $inQuery exceeding depth limit', async () => {
const where = buildNestedInQuery(4);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Subquery nesting depth exceeds maximum allowed depth of 3/),
})
);
});
it('should reject $notInQuery exceeding depth limit', async () => {
const where = buildNestedNotInQuery(4);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Subquery nesting depth exceeds maximum allowed depth of 3/),
})
);
});
it('should reject $select exceeding depth limit', async () => {
const where = buildNestedSelect(4);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Subquery nesting depth exceeds maximum allowed depth of 3/),
})
);
});
it('should reject $dontSelect exceeding depth limit', async () => {
const where = buildNestedDontSelect(4);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Subquery nesting depth exceeds maximum allowed depth of 3/),
})
);
});
it('should allow subqueries with master key even when exceeding limit', async () => {
const where = buildNestedInQuery(4);
await expectAsync(
rest.find(config, auth.master(config), '_User', where)
).toBeResolved();
});
it('should allow subqueries with maintenance key even when exceeding limit', async () => {
const where = buildNestedInQuery(4);
await expectAsync(
rest.find(config, auth.maintenance(config), '_User', where)
).toBeResolved();
});
it('should allow unlimited subqueries when subqueryDepth is -1', async () => {
await reconfigureServer({
requestComplexity: { subqueryDepth: -1 },
});
config = Config.get('test');
const where = buildNestedInQuery(15);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeResolved();
});
it('should allow multiple sibling $inQuery at same depth within limit', async () => {
await reconfigureServer({
requestComplexity: { subqueryDepth: 1 },
});
config = Config.get('test');
// Multiple sibling $inQuery operators in $or, each at depth 1 — within the limit
const where = {
$or: [
{ username: { $inQuery: { className: '_User', where: { username: 'a' } } } },
{ username: { $inQuery: { className: '_User', where: { username: 'b' } } } },
{ username: { $inQuery: { className: '_User', where: { username: 'c' } } } },
],
};
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeResolved();
});
it('should reject sibling $inQuery when nested beyond depth limit', async () => {
await reconfigureServer({
requestComplexity: { subqueryDepth: 1 },
});
config = Config.get('test');
// Each sibling contains a nested $inQuery at depth 2 — exceeds limit
const where = {
$or: [
{
username: {
$inQuery: {
className: '_User',
where: { username: { $inQuery: { className: '_User', where: {} } } },
},
},
},
{
username: {
$inQuery: {
className: '_User',
where: { username: { $inQuery: { className: '_User', where: {} } } },
},
},
},
],
};
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Subquery nesting depth exceeds maximum allowed depth of 1/),
})
);
});
it('should allow multiple sibling $notInQuery at same depth within limit', async () => {
await reconfigureServer({
requestComplexity: { subqueryDepth: 1 },
});
config = Config.get('test');
const where = {
$or: [
{ username: { $notInQuery: { className: '_User', where: { username: 'a' } } } },
{ username: { $notInQuery: { className: '_User', where: { username: 'b' } } } },
{ username: { $notInQuery: { className: '_User', where: { username: 'c' } } } },
],
};
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeResolved();
});
it('should allow mixed sibling $inQuery and $notInQuery at same depth within limit', async () => {
await reconfigureServer({
requestComplexity: { subqueryDepth: 1 },
});
config = Config.get('test');
const where = {
$or: [
{ username: { $inQuery: { className: '_User', where: { username: 'a' } } } },
{ username: { $notInQuery: { className: '_User', where: { username: 'b' } } } },
{ username: { $inQuery: { className: '_User', where: { username: 'c' } } } },
],
};
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeResolved();
});
});
describe('query depth', () => {
let config;
beforeEach(async () => {
await reconfigureServer({
requestComplexity: { queryDepth: 3 },
});
config = Config.get('test');
});
it('should allow $or within depth limit', async () => {
const where = buildNestedOrQuery(3);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeResolved();
});
it('should reject $or exceeding depth limit', async () => {
const where = buildNestedOrQuery(4);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Query condition nesting depth exceeds maximum allowed depth of 3/),
})
);
});
it('should reject $and exceeding depth limit', async () => {
const where = buildNestedAndQuery(4);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Query condition nesting depth exceeds maximum allowed depth of 3/),
})
);
});
it('should reject $nor exceeding depth limit', async () => {
const where = buildNestedNorQuery(4);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Query condition nesting depth exceeds maximum allowed depth of 3/),
})
);
});
it('should reject mixed nested operators exceeding depth limit', async () => {
// $or > $and > $nor > $or = depth 4
const where = {
$or: [
{
$and: [
{
$nor: [
{ $or: [{ username: 'a' }, { username: 'b' }] },
],
},
],
},
],
};
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Query condition nesting depth exceeds maximum allowed depth of 3/),
})
);
});
it('should allow with master key even when exceeding limit', async () => {
const where = buildNestedOrQuery(4);
await expectAsync(
rest.find(config, auth.master(config), '_User', where)
).toBeResolved();
});
it('should allow with maintenance key even when exceeding limit', async () => {
const where = buildNestedOrQuery(4);
await expectAsync(
rest.find(config, auth.maintenance(config), '_User', where)
).toBeResolved();
});
it('should allow unlimited when queryDepth is -1', async () => {
await reconfigureServer({
requestComplexity: { queryDepth: -1 },
});
config = Config.get('test');
const where = buildNestedOrQuery(15);
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeResolved();
});
});
describe('include limits', () => {
let config;
beforeEach(async () => {
await reconfigureServer({
requestComplexity: { includeDepth: 3, includeCount: 5 },
});
config = Config.get('test');
});
it('should allow include within depth limit', async () => {
await expectAsync(
rest.find(config, auth.nobody(config), '_User', {}, { include: 'a.b.c' })
).toBeResolved();
});
it('should reject include exceeding depth limit', async () => {
await expectAsync(
rest.find(config, auth.nobody(config), '_User', {}, { include: 'a.b.c.d' })
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Include depth of 4 exceeds maximum allowed depth of 3/),
})
);
});
it('should allow include count within limit', async () => {
await expectAsync(
rest.find(config, auth.nobody(config), '_User', {}, { include: 'a,b,c,d,e' })
).toBeResolved();
});
it('should reject include count exceeding limit', async () => {
await expectAsync(
rest.find(config, auth.nobody(config), '_User', {}, { include: 'a,b,c,d,e,f' })
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Number of include fields \(\d+\) exceeds maximum allowed \(5\)/),
})
);
});
it('should allow includeAll when within count limit', async () => {
const schema = new Parse.Schema('IncludeTestClass');
schema.addPointer('ptr1', '_User');
schema.addPointer('ptr2', '_User');
schema.addPointer('ptr3', '_User');
await schema.save();
const obj = new Parse.Object('IncludeTestClass');
await obj.save();
await expectAsync(
rest.find(config, auth.nobody(config), 'IncludeTestClass', {}, { includeAll: true })
).toBeResolved();
});
it('should reject includeAll when exceeding count limit', async () => {
await reconfigureServer({
requestComplexity: { includeDepth: 3, includeCount: 2 },
});
config = Config.get('test');
const schema = new Parse.Schema('IncludeTestClass2');
schema.addPointer('ptr1', '_User');
schema.addPointer('ptr2', '_User');
schema.addPointer('ptr3', '_User');
await schema.save();
const obj = new Parse.Object('IncludeTestClass2');
await obj.save();
await expectAsync(
rest.find(config, auth.nobody(config), 'IncludeTestClass2', {}, { includeAll: true })
).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Number of include fields .* exceeds maximum allowed/),
})
);
});
it('should allow includes with master key even when exceeding limits', async () => {
await expectAsync(
rest.find(config, auth.master(config), '_User', {}, { include: 'a.b.c.d' })
).toBeResolved();
});
it('should allow unlimited depth when includeDepth is -1', async () => {
await reconfigureServer({
requestComplexity: { includeDepth: -1 },
});
config = Config.get('test');
await expectAsync(
rest.find(config, auth.nobody(config), '_User', {}, { include: 'a.b.c.d.e.f.g' })
).toBeResolved();
});
it('should allow unlimited count when includeCount is -1', async () => {
await reconfigureServer({
requestComplexity: { includeCount: -1 },
});
config = Config.get('test');
const includes = Array.from({ length: 100 }, (_, i) => `field${i}`).join(',');
await expectAsync(
rest.find(config, auth.nobody(config), '_User', {}, { include: includes })
).toBeResolved();
});
});
describe('allowRegex', () => {
let config;
beforeEach(async () => {
await reconfigureServer({
requestComplexity: { allowRegex: false },
});
config = Config.get('test');
});
it('should reject $regex query when allowRegex is false (unauthenticated)', async () => {
const where = { username: { $regex: 'test' } };
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: '$regex operator is not allowed',
})
);
});
it('should reject $regex query when allowRegex is false (authenticated user)', async () => {
const user = new Parse.User();
user.setUsername('testuser');
user.setPassword('testpass');
await user.signUp();
const userAuth = new auth.Auth({
config,
isMaster: false,
user,
});
const where = { username: { $regex: 'test' } };
await expectAsync(
rest.find(config, userAuth, '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: '$regex operator is not allowed',
})
);
});
it('should allow $regex query when allowRegex is false with master key', async () => {
const where = { username: { $regex: 'test' } };
await expectAsync(
rest.find(config, auth.master(config), '_User', where)
).toBeResolved();
});
it('should allow $regex query when allowRegex is true (default)', async () => {
await reconfigureServer({
requestComplexity: { allowRegex: true },
});
config = Config.get('test');
const where = { username: { $regex: 'test' } };
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeResolved();
});
it('should reject $regex inside $or when allowRegex is false', async () => {
const where = {
$or: [
{ username: { $regex: 'test' } },
{ username: 'exact' },
],
};
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: '$regex operator is not allowed',
})
);
});
it('should reject $regex inside $and when allowRegex is false', async () => {
const where = {
$and: [
{ username: { $regex: 'test' } },
{ username: 'exact' },
],
};
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: '$regex operator is not allowed',
})
);
});
it('should reject $regex inside $nor when allowRegex is false', async () => {
const where = {
$nor: [
{ username: { $regex: 'test' } },
],
};
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: '$regex operator is not allowed',
})
);
});
it('should allow $regex by default when allowRegex is not configured', async () => {
await reconfigureServer({});
config = Config.get('test');
const where = { username: { $regex: 'test' } };
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeResolved();
});
it('should reject empty-string $regex when allowRegex is false', async () => {
const where = { username: { $regex: '' } };
await expectAsync(
rest.find(config, auth.nobody(config), '_User', where)
).toBeRejectedWith(
jasmine.objectContaining({
message: '$regex operator is not allowed',
})
);
});
it('should allow $regex with maintenance key when allowRegex is false', async () => {
const where = { username: { $regex: 'test' } };
await expectAsync(
rest.find(config, auth.maintenance(config), '_User', where)
).toBeResolved();
});
describe('LiveQuery', () => {
beforeEach(async () => {
await reconfigureServer({
requestComplexity: { allowRegex: false },
liveQuery: { classNames: ['TestObject'] },
startLiveQueryServer: true,
});
config = Config.get('test');
});
afterEach(async () => {
const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient();
if (client) {
await client.close();
}
});
it('should reject LiveQuery subscription with $regex when allowRegex is false', async () => {
const query = new Parse.Query('TestObject');
query.matches('field', /test/);
await expectAsync(query.subscribe()).toBeRejectedWith(
jasmine.objectContaining({ code: Parse.Error.INVALID_QUERY })
);
});
it('should reject LiveQuery subscription with $regex inside $or when allowRegex is false', async () => {
const query = new Parse.Query('TestObject');
query._where = {
$or: [
{ field: { $regex: 'test' } },
{ field: 'exact' },
],
};
await expectAsync(query.subscribe()).toBeRejectedWith(
jasmine.objectContaining({ code: Parse.Error.INVALID_QUERY })
);
});
it('should allow LiveQuery subscription without $regex when allowRegex is false', async () => {
const query = new Parse.Query('TestObject');
query.equalTo('field', 'test');
const subscription = await query.subscribe();
expect(subscription).toBeDefined();
subscription.unsubscribe();
});
});
});
describe('subquery result limit', () => {
let config;
const totalObjects = 5;
const resultLimit = 3;
beforeEach(async () => {
await reconfigureServer({
requestComplexity: { subqueryLimit: resultLimit },
});
config = Config.get('test');
// Create target objects
const targets = [];
for (let i = 0; i < totalObjects; i++) {
const obj = new Parse.Object('Target');
obj.set('value', `v${i}`);
targets.push(obj);
}
await Parse.Object.saveAll(targets);
// Create source objects, each pointing to a target
const sources = [];
for (let i = 0; i < totalObjects; i++) {
const obj = new Parse.Object('Source');
obj.set('ref', targets[i]);
obj.set('value', targets[i].get('value'));
sources.push(obj);
}
await Parse.Object.saveAll(sources);
});
it('should limit $inQuery subquery results', async () => {
const where = {
ref: {
$inQuery: { className: 'Target', where: {} },
},
};
const result = await rest.find(config, auth.nobody(config), 'Source', where);
expect(result.results.length).toBe(resultLimit);
});
it('should limit $notInQuery subquery results', async () => {
const where = {
ref: {
$notInQuery: { className: 'Target', where: {} },
},
};
const result = await rest.find(config, auth.nobody(config), 'Source', where);
// With limit, only `resultLimit` targets are excluded, so (totalObjects - resultLimit) sources remain
expect(result.results.length).toBe(totalObjects - resultLimit);
});
it('should limit $select subquery results', async () => {
const where = {
value: {
$select: { query: { className: 'Target', where: {} }, key: 'value' },
},
};
const result = await rest.find(config, auth.nobody(config), 'Source', where);
expect(result.results.length).toBe(resultLimit);
});
it('should limit $dontSelect subquery results', async () => {
const where = {
value: {
$dontSelect: { query: { className: 'Target', where: {} }, key: 'value' },
},
};
const result = await rest.find(config, auth.nobody(config), 'Source', where);
expect(result.results.length).toBe(totalObjects - resultLimit);
});
it('should allow unlimited subquery results with master key', async () => {
const where = {
ref: {
$inQuery: { className: 'Target', where: {} },
},
};
const result = await rest.find(config, auth.master(config), 'Source', where);
expect(result.results.length).toBe(totalObjects);
});
it('should allow unlimited subquery results with maintenance key', async () => {
const where = {
ref: {
$inQuery: { className: 'Target', where: {} },
},
};
const result = await rest.find(config, auth.maintenance(config), 'Source', where);
expect(result.results.length).toBe(totalObjects);
});
it('should allow unlimited subquery results when subqueryLimit is -1', async () => {
await reconfigureServer({
requestComplexity: { subqueryLimit: -1 },
});
config = Config.get('test');
const where = {
ref: {
$inQuery: { className: 'Target', where: {} },
},
};
const result = await rest.find(config, auth.nobody(config), 'Source', where);
expect(result.results.length).toBe(totalObjects);
});
it('should include subqueryLimit in config defaults', async () => {
await reconfigureServer({});
config = Config.get('test');
expect(config.requestComplexity.subqueryLimit).toBe(-1);
});
it('should accept subqueryLimit in config validation', async () => {
await expectAsync(
reconfigureServer({
requestComplexity: { subqueryLimit: 100 },
})
).toBeResolved();
});
});
});