feat: Add Parse Server option enableSanitizedErrorResponse to remove detailed error messages from responses sent to clients (#9944)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const Utils = require('../src/Utils');
|
||||
const Utils = require('../lib/Utils');
|
||||
const { createSanitizedError, createSanitizedHttpError } = require("../lib/Error")
|
||||
|
||||
describe('Utils', () => {
|
||||
describe('encodeForUrl', () => {
|
||||
@@ -173,4 +174,42 @@ describe('Utils', () => {
|
||||
expect(Utils.getNestedProperty(obj, 'database.name')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('createSanitizedError', () => {
|
||||
it('should return "Permission denied" when enableSanitizedErrorResponse is true', () => {
|
||||
const config = { enableSanitizedErrorResponse: true };
|
||||
const error = createSanitizedError(Parse.Error.OPERATION_FORBIDDEN, 'Detailed error message', config);
|
||||
expect(error.message).toBe('Permission denied');
|
||||
});
|
||||
|
||||
it('should not crash with config undefined', () => {
|
||||
const error = createSanitizedError(Parse.Error.OPERATION_FORBIDDEN, 'Detailed error message', undefined);
|
||||
expect(error.message).toBe('Permission denied');
|
||||
});
|
||||
|
||||
it('should return the detailed message when enableSanitizedErrorResponse is false', () => {
|
||||
const config = { enableSanitizedErrorResponse: false };
|
||||
const error = createSanitizedError(Parse.Error.OPERATION_FORBIDDEN, 'Detailed error message', config);
|
||||
expect(error.message).toBe('Detailed error message');
|
||||
});
|
||||
});
|
||||
|
||||
describe('createSanitizedHttpError', () => {
|
||||
it('should return "Permission denied" when enableSanitizedErrorResponse is true', () => {
|
||||
const config = { enableSanitizedErrorResponse: true };
|
||||
const error = createSanitizedHttpError(403, 'Detailed error message', config);
|
||||
expect(error.message).toBe('Permission denied');
|
||||
});
|
||||
|
||||
it('should not crash with config undefined', () => {
|
||||
const error = createSanitizedHttpError(403, 'Detailed error message', undefined);
|
||||
expect(error.message).toBe('Permission denied');
|
||||
});
|
||||
|
||||
it('should return the detailed message when enableSanitizedErrorResponse is false', () => {
|
||||
const config = { enableSanitizedErrorResponse: false };
|
||||
const error = createSanitizedHttpError(403, 'Detailed error message', config);
|
||||
expect(error.message).toBe('Detailed error message');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user