feat: Add Parse Server option enableSanitizedErrorResponse to remove detailed error messages from responses sent to clients (#9944)
This commit is contained in:
@@ -767,13 +767,11 @@ describe('Parse.File testing', () => {
|
||||
|
||||
describe('getting files', () => {
|
||||
it('does not crash on file request with invalid app ID', async () => {
|
||||
loggerErrorSpy.calls.reset();
|
||||
const res1 = await request({
|
||||
url: 'http://localhost:8378/1/files/invalid-id/invalid-file.txt',
|
||||
}).catch(e => e);
|
||||
expect(res1.status).toBe(403);
|
||||
expect(res1.data).toEqual({ code: 119, error: 'Permission denied' });
|
||||
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('Invalid application ID.'));
|
||||
expect(res1.data).toEqual({ code: 119, error: 'Invalid application ID.' });
|
||||
// Ensure server did not crash
|
||||
const res2 = await request({ url: 'http://localhost:8378/1/health' });
|
||||
expect(res2.status).toEqual(200);
|
||||
|
||||
@@ -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