Skip to content

Commit c3088f6

Browse files
committed
always allow file upload with master key
1 parent 1e8378e commit c3088f6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

spec/ParseFile.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,18 @@ describe('Parse.File testing', () => {
885885
await expectAsync(file.save({ sessionToken: authUser.getSessionToken() })).toBeResolved();
886886
});
887887

888+
fit('allows file upload with master key', async () => {
889+
await reconfigureServer({
890+
fileUpload: {
891+
enableForPublic: false,
892+
enableForAnonymousUser: false,
893+
enableForAuthenticatedUser: false,
894+
},
895+
});
896+
let file = new Parse.File('hello.txt', data, 'text/plain');
897+
await expectAsync(file.save({ useMasterKey: true })).toBeResolved();
898+
});
899+
888900
it('rejects all file uploads', async () => {
889901
await reconfigureServer({
890902
fileUpload: {

src/Routers/FilesRouter.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,23 @@ export class FilesRouter {
9595
async createHandler(req, res, next) {
9696
const config = req.config;
9797
const user = req.auth.user;
98+
const isMaster = req.auth.isMaster;
9899
const isLinked = user && Parse.AnonymousUtils.isLinked(user);
99-
if (!config.fileUpload.enableForAnonymousUser && isLinked) {
100+
if (!isMaster && !config.fileUpload.enableForAnonymousUser && isLinked) {
100101
next(new Parse.Error(
101102
Parse.Error.FILE_SAVE_ERROR,
102103
'File upload by anonymous user is disabled.'
103104
));
104105
return;
105106
}
106-
if (!config.fileUpload.enableForAuthenticatedUser && !isLinked && user) {
107+
if (!isMaster && !config.fileUpload.enableForAuthenticatedUser && !isLinked && user) {
107108
next(new Parse.Error(
108109
Parse.Error.FILE_SAVE_ERROR,
109110
'File upload by authenticated user is disabled.'
110111
));
111112
return;
112113
}
113-
if (!config.fileUpload.enableForPublic && !user) {
114+
if (!isMaster && !config.fileUpload.enableForPublic && !user) {
114115
next(new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'File upload by public is disabled.'));
115116
return;
116117
}

0 commit comments

Comments
 (0)