|
1 | 1 | const Config = require('../lib/Config'); |
2 | | -const ParseServer = require('../lib/index').ParseServer; |
3 | 2 |
|
4 | 3 | describe('Config Keys', () => { |
5 | | - const tests = [ |
6 | | - { |
7 | | - name: 'Invalid Root Keys', |
8 | | - options: { unknow: 'val', masterKeyIPs: '' }, |
9 | | - error: 'unknow, masterKeyIPs', |
10 | | - }, |
11 | | - { name: 'Invalid Schema Keys', options: { schema: { Strict: 'val' } }, error: 'schema.Strict' }, |
12 | | - { |
13 | | - name: 'Invalid Pages Keys', |
14 | | - options: { pages: { customUrls: { EmailVerificationSendFail: 'val' } } }, |
15 | | - error: 'pages.customUrls.EmailVerificationSendFail', |
16 | | - }, |
17 | | - { |
18 | | - name: 'Invalid LiveQueryServerOptions Keys', |
19 | | - options: { liveQueryServerOptions: { MasterKey: 'value' } }, |
20 | | - error: 'liveQueryServerOptions.MasterKey', |
21 | | - }, |
22 | | - { |
23 | | - name: 'Invalid RateLimit Keys - Array Item', |
24 | | - options: { rateLimit: [{ RequestPath: '' }, { RequestTimeWindow: '' }] }, |
25 | | - error: 'rateLimit[0].RequestPath, rateLimit[1].RequestTimeWindow', |
26 | | - }, |
27 | | - ]; |
28 | | - |
29 | | - tests.forEach(test => { |
30 | | - it(test.name, async () => { |
31 | | - const logger = require('../lib/logger').logger; |
32 | | - spyOn(logger, 'error').and.callThrough(); |
33 | | - spyOn(Config, 'validateOptions').and.callFake(() => {}); |
34 | | - |
35 | | - new ParseServer({ |
36 | | - ...defaultConfiguration, |
37 | | - ...test.options, |
38 | | - }); |
39 | | - expect(logger.error).toHaveBeenCalledWith(`Invalid Option Keys Found: ${test.error}`); |
40 | | - }); |
| 4 | + const invalidKeyErrorMessage = 'Invalid key\\(s\\) found in Parse Server configuration'; |
| 5 | + let loggerErrorSpy; |
| 6 | + |
| 7 | + beforeEach(async () => { |
| 8 | + const logger = require('../lib/logger').logger; |
| 9 | + loggerErrorSpy = spyOn(logger, 'error').and.callThrough(); |
| 10 | + spyOn(Config, 'validateOptions').and.callFake(() => {}); |
| 11 | + }); |
| 12 | + |
| 13 | + it('recognizes invalid keys in root', async () => { |
| 14 | + await expectAsync(reconfigureServer({ |
| 15 | + ...defaultConfiguration, |
| 16 | + invalidKey: 1, |
| 17 | + })).toBeResolved(); |
| 18 | + const error = loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], ''); |
| 19 | + expect(error).toMatch(invalidKeyErrorMessage); |
| 20 | + }); |
| 21 | + |
| 22 | + it('recognizes invalid keys in pages.customUrls', async () => { |
| 23 | + await expectAsync(reconfigureServer({ |
| 24 | + ...defaultConfiguration, |
| 25 | + pages: { |
| 26 | + customUrls: { |
| 27 | + invalidKey: 1, |
| 28 | + EmailVerificationSendFail: 1, |
| 29 | + } |
| 30 | + } |
| 31 | + })).toBeResolved(); |
| 32 | + const error = loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], ''); |
| 33 | + expect(error).toMatch(invalidKeyErrorMessage); |
| 34 | + expect(error).toMatch(`invalidKey`); |
| 35 | + expect(error).toMatch(`EmailVerificationSendFail`); |
| 36 | + }); |
| 37 | + |
| 38 | + it('recognizes invalid keys in liveQueryServerOptions', async () => { |
| 39 | + await expectAsync(reconfigureServer({ |
| 40 | + ...defaultConfiguration, |
| 41 | + liveQueryServerOptions: { |
| 42 | + invalidKey: 1, |
| 43 | + MasterKey: 1, |
| 44 | + } |
| 45 | + })).toBeResolved(); |
| 46 | + const error = loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], ''); |
| 47 | + expect(error).toMatch(invalidKeyErrorMessage); |
| 48 | + expect(error).toMatch(`MasterKey`); |
| 49 | + }); |
| 50 | + |
| 51 | + it('recognizes invalid keys in rateLimit', async () => { |
| 52 | + await expectAsync(reconfigureServer({ |
| 53 | + ...defaultConfiguration, |
| 54 | + rateLimit: [ |
| 55 | + { invalidKey: 1 }, |
| 56 | + { RequestPath: 1 }, |
| 57 | + { RequestTimeWindow: 1 }, |
| 58 | + ] |
| 59 | + })).toBeRejected(); |
| 60 | + const error = loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], ''); |
| 61 | + expect(error).toMatch(invalidKeyErrorMessage); |
| 62 | + expect(error).toMatch('rateLimit\\[0\\]\\.invalidKey'); |
| 63 | + expect(error).toMatch('rateLimit\\[1\\]\\.RequestPath'); |
| 64 | + expect(error).toMatch('rateLimit\\[2\\]\\.RequestTimeWindow'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('recognizes valid keys in default configuration', async () => { |
| 68 | + await expectAsync(reconfigureServer({ |
| 69 | + ...defaultConfiguration, |
| 70 | + })).toBeResolved(); |
| 71 | + expect(loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], '')).not.toMatch(invalidKeyErrorMessage); |
41 | 72 | }); |
42 | 73 |
|
43 | | - it('should run fine', async () => { |
44 | | - try { |
45 | | - await reconfigureServer({ |
46 | | - ...defaultConfiguration, |
47 | | - }); |
48 | | - } catch (err) { |
49 | | - fail('Should run without error'); |
50 | | - } |
| 74 | + it_only_db('mongo')('recognizes valid keys in databaseOptions (MongoDB)', async () => { |
| 75 | + await expectAsync(reconfigureServer({ |
| 76 | + databaseURI: 'mongodb://localhost:27017/parse', |
| 77 | + filesAdapter: null, |
| 78 | + databaseAdapter: null, |
| 79 | + databaseOptions: { |
| 80 | + retryWrites: true, |
| 81 | + maxTimeMS: 1000, |
| 82 | + maxStalenessSeconds: 10, |
| 83 | + maxPoolSize: 10, |
| 84 | + }, |
| 85 | + })).toBeResolved(); |
| 86 | + expect(loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], '')).not.toMatch(invalidKeyErrorMessage); |
51 | 87 | }); |
52 | 88 | }); |
0 commit comments