-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Parse Server
databaseOptions
nested keys incorrectly identifie…
…d as invalid (#9213)
- Loading branch information
Showing
7 changed files
with
195 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,88 @@ | ||
const Config = require('../lib/Config'); | ||
const ParseServer = require('../lib/index').ParseServer; | ||
|
||
describe('Config Keys', () => { | ||
const tests = [ | ||
{ | ||
name: 'Invalid Root Keys', | ||
options: { unknow: 'val', masterKeyIPs: '' }, | ||
error: 'unknow, masterKeyIPs', | ||
}, | ||
{ name: 'Invalid Schema Keys', options: { schema: { Strict: 'val' } }, error: 'schema.Strict' }, | ||
{ | ||
name: 'Invalid Pages Keys', | ||
options: { pages: { customUrls: { EmailVerificationSendFail: 'val' } } }, | ||
error: 'pages.customUrls.EmailVerificationSendFail', | ||
}, | ||
{ | ||
name: 'Invalid LiveQueryServerOptions Keys', | ||
options: { liveQueryServerOptions: { MasterKey: 'value' } }, | ||
error: 'liveQueryServerOptions.MasterKey', | ||
}, | ||
{ | ||
name: 'Invalid RateLimit Keys - Array Item', | ||
options: { rateLimit: [{ RequestPath: '' }, { RequestTimeWindow: '' }] }, | ||
error: 'rateLimit[0].RequestPath, rateLimit[1].RequestTimeWindow', | ||
}, | ||
]; | ||
|
||
tests.forEach(test => { | ||
it(test.name, async () => { | ||
const logger = require('../lib/logger').logger; | ||
spyOn(logger, 'error').and.callThrough(); | ||
spyOn(Config, 'validateOptions').and.callFake(() => {}); | ||
|
||
new ParseServer({ | ||
...defaultConfiguration, | ||
...test.options, | ||
}); | ||
expect(logger.error).toHaveBeenCalledWith(`Invalid Option Keys Found: ${test.error}`); | ||
}); | ||
const invalidKeyErrorMessage = 'Invalid key\\(s\\) found in Parse Server configuration'; | ||
let loggerErrorSpy; | ||
|
||
beforeEach(async () => { | ||
const logger = require('../lib/logger').logger; | ||
loggerErrorSpy = spyOn(logger, 'error').and.callThrough(); | ||
spyOn(Config, 'validateOptions').and.callFake(() => {}); | ||
}); | ||
|
||
it('recognizes invalid keys in root', async () => { | ||
await expectAsync(reconfigureServer({ | ||
...defaultConfiguration, | ||
invalidKey: 1, | ||
})).toBeResolved(); | ||
const error = loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], ''); | ||
expect(error).toMatch(invalidKeyErrorMessage); | ||
}); | ||
|
||
it('recognizes invalid keys in pages.customUrls', async () => { | ||
await expectAsync(reconfigureServer({ | ||
...defaultConfiguration, | ||
pages: { | ||
customUrls: { | ||
invalidKey: 1, | ||
EmailVerificationSendFail: 1, | ||
} | ||
} | ||
})).toBeResolved(); | ||
const error = loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], ''); | ||
expect(error).toMatch(invalidKeyErrorMessage); | ||
expect(error).toMatch(`invalidKey`); | ||
expect(error).toMatch(`EmailVerificationSendFail`); | ||
}); | ||
|
||
it('recognizes invalid keys in liveQueryServerOptions', async () => { | ||
await expectAsync(reconfigureServer({ | ||
...defaultConfiguration, | ||
liveQueryServerOptions: { | ||
invalidKey: 1, | ||
MasterKey: 1, | ||
} | ||
})).toBeResolved(); | ||
const error = loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], ''); | ||
expect(error).toMatch(invalidKeyErrorMessage); | ||
expect(error).toMatch(`MasterKey`); | ||
}); | ||
|
||
it('recognizes invalid keys in rateLimit', async () => { | ||
await expectAsync(reconfigureServer({ | ||
...defaultConfiguration, | ||
rateLimit: [ | ||
{ invalidKey: 1 }, | ||
{ RequestPath: 1 }, | ||
{ RequestTimeWindow: 1 }, | ||
] | ||
})).toBeRejected(); | ||
const error = loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], ''); | ||
expect(error).toMatch(invalidKeyErrorMessage); | ||
expect(error).toMatch('rateLimit\\[0\\]\\.invalidKey'); | ||
expect(error).toMatch('rateLimit\\[1\\]\\.RequestPath'); | ||
expect(error).toMatch('rateLimit\\[2\\]\\.RequestTimeWindow'); | ||
}); | ||
|
||
it('recognizes valid keys in default configuration', async () => { | ||
await expectAsync(reconfigureServer({ | ||
...defaultConfiguration, | ||
})).toBeResolved(); | ||
expect(loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], '')).not.toMatch(invalidKeyErrorMessage); | ||
}); | ||
|
||
it('should run fine', async () => { | ||
try { | ||
await reconfigureServer({ | ||
...defaultConfiguration, | ||
}); | ||
} catch (err) { | ||
fail('Should run without error'); | ||
} | ||
it_only_db('mongo')('recognizes valid keys in databaseOptions (MongoDB)', async () => { | ||
await expectAsync(reconfigureServer({ | ||
databaseURI: 'mongodb://localhost:27017/parse', | ||
filesAdapter: null, | ||
databaseAdapter: null, | ||
databaseOptions: { | ||
retryWrites: true, | ||
maxTimeMS: 1000, | ||
maxStalenessSeconds: 10, | ||
maxPoolSize: 10, | ||
}, | ||
})).toBeResolved(); | ||
expect(loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], '')).not.toMatch(invalidKeyErrorMessage); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const Utils = require('../src/Utils'); | ||
|
||
describe('Utils', () => { | ||
describe('addNestedKeysToRoot', () => { | ||
it('should move the nested keys to root of object', async () => { | ||
const obj = { | ||
a: 1, | ||
b: { | ||
c: 2, | ||
d: 3 | ||
}, | ||
e: 4 | ||
}; | ||
Utils.addNestedKeysToRoot(obj, 'b'); | ||
expect(obj).toEqual({ | ||
a: 1, | ||
c: 2, | ||
d: 3, | ||
e: 4 | ||
}); | ||
}); | ||
|
||
it('should not modify the object if the key does not exist', async () => { | ||
const obj = { | ||
a: 1, | ||
e: 4 | ||
}; | ||
Utils.addNestedKeysToRoot(obj, 'b'); | ||
expect(obj).toEqual({ | ||
a: 1, | ||
e: 4 | ||
}); | ||
}); | ||
|
||
it('should not modify the object if the key is not an object', () => { | ||
const obj = { | ||
a: 1, | ||
b: 2, | ||
e: 4 | ||
}; | ||
Utils.addNestedKeysToRoot(obj, 'b'); | ||
expect(obj).toEqual({ | ||
a: 1, | ||
b: 2, | ||
e: 4 | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters