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';
|
'use strict';
|
||||||
|
|
||||||
const request = require('../lib/request');
|
const request = require('../lib/request');
|
||||||
const Definitions = require('../src/Options/Definitions');
|
|
||||||
|
|
||||||
const str = 'Hello World!';
|
const str = 'Hello World!';
|
||||||
const data = [];
|
const data = [];
|
||||||
@@ -84,7 +83,6 @@ describe('Parse.File testing', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('supports REST end-to-end file create, read, delete, read', done => {
|
it('supports REST end-to-end file create, read, delete, read', done => {
|
||||||
const headers = {
|
const headers = {
|
||||||
@@ -600,7 +598,9 @@ describe('Parse.File testing', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('deleting files', () => {
|
||||||
it('fails to delete an unkown file', done => {
|
it('fails to delete an unkown file', done => {
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/octet-stream',
|
'Content-Type': 'application/octet-stream',
|
||||||
@@ -623,6 +623,7 @@ describe('Parse.File testing', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
xdescribe('Gridstore Range tests', () => {
|
xdescribe('Gridstore Range tests', () => {
|
||||||
it('supports range requests', done => {
|
it('supports range requests', done => {
|
||||||
@@ -865,11 +866,7 @@ describe('Parse.File testing', () => {
|
|||||||
describe('file upload configuration', () => {
|
describe('file upload configuration', () => {
|
||||||
it('allows file upload only for authenticated user by default', async () => {
|
it('allows file upload only for authenticated user by default', async () => {
|
||||||
await reconfigureServer({
|
await reconfigureServer({
|
||||||
fileUpload: {
|
fileUpload: {},
|
||||||
enableForPublic: Definitions.FileUploadOptions.enableForPublic.default,
|
|
||||||
enableForAnonymousUser: Definitions.FileUploadOptions.enableForAnonymousUser.default,
|
|
||||||
enableForAuthenticatedUser: Definitions.FileUploadOptions.enableForAuthenticatedUser.default,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
let file = new Parse.File('hello.txt', data, 'text/plain');
|
let file = new Parse.File('hello.txt', data, 'text/plain');
|
||||||
await expectAsync(file.save()).toBeRejectedWith(
|
await expectAsync(file.save()).toBeRejectedWith(
|
||||||
@@ -917,7 +914,10 @@ describe('Parse.File testing', () => {
|
|||||||
file = new Parse.File('hello.txt', data, 'text/plain');
|
file = new Parse.File('hello.txt', data, 'text/plain');
|
||||||
const authUser = await Parse.User.signUp('user', 'password');
|
const authUser = await Parse.User.signUp('user', 'password');
|
||||||
await expectAsync(file.save({ sessionToken: authUser.getSessionToken() })).toBeRejectedWith(
|
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');
|
file = new Parse.File('hello.txt', data, 'text/plain');
|
||||||
const authUser = await Parse.User.signUp('user', 'password');
|
const authUser = await Parse.User.signUp('user', 'password');
|
||||||
await expectAsync(file.save({ sessionToken: authUser.getSessionToken() })).toBeRejectedWith(
|
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');
|
file = new Parse.File('hello.txt', data, 'text/plain');
|
||||||
const authUser = await Parse.User.signUp('user', 'password');
|
const authUser = await Parse.User.signUp('user', 'password');
|
||||||
await expectAsync(file.save({ sessionToken: authUser.getSessionToken() })).toBeRejectedWith(
|
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 () => {
|
it('rejects invalid fileUpload configuration', async () => {
|
||||||
const invalidConfigs = [
|
const invalidConfigs = [
|
||||||
|
{ fileUpload: undefined },
|
||||||
|
{ fileUpload: null },
|
||||||
{ fileUpload: [] },
|
{ fileUpload: [] },
|
||||||
{ fileUpload: 1 },
|
{ fileUpload: 1 },
|
||||||
{ fileUpload: "string" },
|
{ fileUpload: 'string' },
|
||||||
];
|
|
||||||
const validConfigs = [
|
|
||||||
{ fileUpload: {} },
|
|
||||||
{ fileUpload: null },
|
|
||||||
{ fileUpload: undefined },
|
|
||||||
];
|
|
||||||
const keys = [
|
|
||||||
"enableForPublic",
|
|
||||||
"enableForAnonymousUser",
|
|
||||||
"enableForAuthenticatedUser",
|
|
||||||
];
|
|
||||||
const invalidValues = [
|
|
||||||
[],
|
|
||||||
{},
|
|
||||||
1,
|
|
||||||
"string",
|
|
||||||
null,
|
|
||||||
];
|
|
||||||
const validValues = [
|
|
||||||
undefined,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
];
|
];
|
||||||
|
const validConfigs = [{ fileUpload: {} }];
|
||||||
|
const keys = ['enableForPublic', 'enableForAnonymousUser', 'enableForAuthenticatedUser'];
|
||||||
|
const invalidValues = [[], {}, 1, 'string', null];
|
||||||
|
const validValues = [undefined, true, false];
|
||||||
for (const config of invalidConfigs) {
|
for (const config of invalidConfigs) {
|
||||||
await expectAsync(reconfigureServer(config)).toBeRejectedWith(
|
await expectAsync(reconfigureServer(config)).toBeRejectedWith(
|
||||||
'fileUpload must be an object value.'
|
'fileUpload must be an object value.'
|
||||||
|
|||||||
@@ -250,12 +250,16 @@ export class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static validateFileUploadOptions(fileUpload) {
|
static validateFileUploadOptions(fileUpload) {
|
||||||
if (!fileUpload) {
|
try {
|
||||||
fileUpload = {};
|
if (fileUpload == null || typeof fileUpload !== 'object' || fileUpload instanceof Array) {
|
||||||
}
|
|
||||||
if (typeof fileUpload !== 'object' || fileUpload instanceof Array) {
|
|
||||||
throw 'fileUpload must be an object value.';
|
throw 'fileUpload must be an object value.';
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof ReferenceError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
if (fileUpload.enableForAnonymousUser === undefined) {
|
if (fileUpload.enableForAnonymousUser === undefined) {
|
||||||
fileUpload.enableForAnonymousUser = FileUploadOptions.enableForAnonymousUser.default;
|
fileUpload.enableForAnonymousUser = FileUploadOptions.enableForAnonymousUser.default;
|
||||||
} else if (typeof fileUpload.enableForAnonymousUser !== 'boolean') {
|
} 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 */
|
:DEFAULT: false */
|
||||||
idempotencyOptions: ?IdempotencyOptions;
|
idempotencyOptions: ?IdempotencyOptions;
|
||||||
/* Options for file uploads
|
/* Options for file uploads
|
||||||
:ENV: PARSE_SERVER_FILE_UPLOAD_OPTIONS */
|
:ENV: PARSE_SERVER_FILE_UPLOAD_OPTIONS
|
||||||
|
:DEFAULT: {} */
|
||||||
fileUpload: ?FileUploadOptions;
|
fileUpload: ?FileUploadOptions;
|
||||||
/* Full path to your GraphQL custom schema.graphql file */
|
/* Full path to your GraphQL custom schema.graphql file */
|
||||||
graphQLSchema: ?string;
|
graphQLSchema: ?string;
|
||||||
|
|||||||
Reference in New Issue
Block a user