Fix fileupload defaults not applied (#7086)
* added fileUpload definition default value * added undefined and null as invalid * removed explicit default value reference * improved test grouping in describes
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
'use strict';
|
||||
|
||||
const request = require('../lib/request');
|
||||
const Definitions = require('../src/Options/Definitions');
|
||||
|
||||
const str = 'Hello World!';
|
||||
const data = [];
|
||||
@@ -84,7 +83,6 @@ describe('Parse.File testing', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('supports REST end-to-end file create, read, delete, read', done => {
|
||||
const headers = {
|
||||
@@ -600,7 +598,9 @@ describe('Parse.File testing', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleting files', () => {
|
||||
it('fails to delete an unkown file', done => {
|
||||
const headers = {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
@@ -623,6 +623,7 @@ describe('Parse.File testing', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
xdescribe('Gridstore Range tests', () => {
|
||||
it('supports range requests', done => {
|
||||
@@ -865,11 +866,7 @@ describe('Parse.File testing', () => {
|
||||
describe('file upload configuration', () => {
|
||||
it('allows file upload only for authenticated user by default', async () => {
|
||||
await reconfigureServer({
|
||||
fileUpload: {
|
||||
enableForPublic: Definitions.FileUploadOptions.enableForPublic.default,
|
||||
enableForAnonymousUser: Definitions.FileUploadOptions.enableForAnonymousUser.default,
|
||||
enableForAuthenticatedUser: Definitions.FileUploadOptions.enableForAuthenticatedUser.default,
|
||||
}
|
||||
fileUpload: {},
|
||||
});
|
||||
let file = new Parse.File('hello.txt', data, 'text/plain');
|
||||
await expectAsync(file.save()).toBeRejectedWith(
|
||||
@@ -917,7 +914,10 @@ describe('Parse.File testing', () => {
|
||||
file = new Parse.File('hello.txt', data, 'text/plain');
|
||||
const authUser = await Parse.User.signUp('user', 'password');
|
||||
await expectAsync(file.save({ sessionToken: authUser.getSessionToken() })).toBeRejectedWith(
|
||||
new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'File upload by authenticated user is disabled.')
|
||||
new Parse.Error(
|
||||
Parse.Error.FILE_SAVE_ERROR,
|
||||
'File upload by authenticated user is disabled.'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -957,7 +957,10 @@ describe('Parse.File testing', () => {
|
||||
file = new Parse.File('hello.txt', data, 'text/plain');
|
||||
const authUser = await Parse.User.signUp('user', 'password');
|
||||
await expectAsync(file.save({ sessionToken: authUser.getSessionToken() })).toBeRejectedWith(
|
||||
new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'File upload by authenticated user is disabled.')
|
||||
new Parse.Error(
|
||||
Parse.Error.FILE_SAVE_ERROR,
|
||||
'File upload by authenticated user is disabled.'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -979,7 +982,10 @@ describe('Parse.File testing', () => {
|
||||
file = new Parse.File('hello.txt', data, 'text/plain');
|
||||
const authUser = await Parse.User.signUp('user', 'password');
|
||||
await expectAsync(file.save({ sessionToken: authUser.getSessionToken() })).toBeRejectedWith(
|
||||
new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'File upload by authenticated user is disabled.')
|
||||
new Parse.Error(
|
||||
Parse.Error.FILE_SAVE_ERROR,
|
||||
'File upload by authenticated user is disabled.'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1007,32 +1013,16 @@ describe('Parse.File testing', () => {
|
||||
|
||||
it('rejects invalid fileUpload configuration', async () => {
|
||||
const invalidConfigs = [
|
||||
{ fileUpload: undefined },
|
||||
{ fileUpload: null },
|
||||
{ fileUpload: [] },
|
||||
{ fileUpload: 1 },
|
||||
{ fileUpload: "string" },
|
||||
];
|
||||
const validConfigs = [
|
||||
{ fileUpload: {} },
|
||||
{ fileUpload: null },
|
||||
{ fileUpload: undefined },
|
||||
];
|
||||
const keys = [
|
||||
"enableForPublic",
|
||||
"enableForAnonymousUser",
|
||||
"enableForAuthenticatedUser",
|
||||
];
|
||||
const invalidValues = [
|
||||
[],
|
||||
{},
|
||||
1,
|
||||
"string",
|
||||
null,
|
||||
];
|
||||
const validValues = [
|
||||
undefined,
|
||||
true,
|
||||
false,
|
||||
{ fileUpload: 'string' },
|
||||
];
|
||||
const validConfigs = [{ fileUpload: {} }];
|
||||
const keys = ['enableForPublic', 'enableForAnonymousUser', 'enableForAuthenticatedUser'];
|
||||
const invalidValues = [[], {}, 1, 'string', null];
|
||||
const validValues = [undefined, true, false];
|
||||
for (const config of invalidConfigs) {
|
||||
await expectAsync(reconfigureServer(config)).toBeRejectedWith(
|
||||
'fileUpload must be an object value.'
|
||||
@@ -1043,12 +1033,12 @@ describe('Parse.File testing', () => {
|
||||
}
|
||||
for (const key of keys) {
|
||||
for (const value of invalidValues) {
|
||||
await expectAsync(reconfigureServer({ fileUpload: { [key]: value }})).toBeRejectedWith(
|
||||
await expectAsync(reconfigureServer({ fileUpload: { [key]: value } })).toBeRejectedWith(
|
||||
`fileUpload.${key} must be a boolean value.`
|
||||
);
|
||||
}
|
||||
for (const value of validValues) {
|
||||
await expectAsync(reconfigureServer({ fileUpload: { [key]: value }})).toBeResolved();
|
||||
await expectAsync(reconfigureServer({ fileUpload: { [key]: value } })).toBeResolved();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -250,12 +250,16 @@ export class Config {
|
||||
}
|
||||
|
||||
static validateFileUploadOptions(fileUpload) {
|
||||
if (!fileUpload) {
|
||||
fileUpload = {};
|
||||
}
|
||||
if (typeof fileUpload !== 'object' || fileUpload instanceof Array) {
|
||||
try {
|
||||
if (fileUpload == null || typeof fileUpload !== 'object' || fileUpload instanceof Array) {
|
||||
throw 'fileUpload must be an object value.';
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof ReferenceError) {
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
if (fileUpload.enableForAnonymousUser === undefined) {
|
||||
fileUpload.enableForAnonymousUser = FileUploadOptions.enableForAnonymousUser.default;
|
||||
} else if (typeof fileUpload.enableForAnonymousUser !== 'boolean') {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -199,7 +199,8 @@ export interface ParseServerOptions {
|
||||
:DEFAULT: false */
|
||||
idempotencyOptions: ?IdempotencyOptions;
|
||||
/* Options for file uploads
|
||||
:ENV: PARSE_SERVER_FILE_UPLOAD_OPTIONS */
|
||||
:ENV: PARSE_SERVER_FILE_UPLOAD_OPTIONS
|
||||
:DEFAULT: {} */
|
||||
fileUpload: ?FileUploadOptions;
|
||||
/* Full path to your GraphQL custom schema.graphql file */
|
||||
graphQLSchema: ?string;
|
||||
|
||||
Reference in New Issue
Block a user