From 071d2908dd07c9c98f27db5118485b42c2aa0270 Mon Sep 17 00:00:00 2001 From: Bartosz Marganiec Date: Sat, 15 Jul 2023 15:14:40 +0200 Subject: [PATCH 1/4] Fix: testing file extension against every pattern in file upload extensions config --- src/Routers/FilesRouter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Routers/FilesRouter.js b/src/Routers/FilesRouter.js index 3b42d883d3..cbb59fdcdd 100644 --- a/src/Routers/FilesRouter.js +++ b/src/Routers/FilesRouter.js @@ -147,7 +147,7 @@ export class FilesRouter { if (ext === '*') { return true; } - const regex = new RegExp(fileExtensions); + const regex = new RegExp(ext); if (regex.test(extension)) { return true; } From 5449f0fea218ff59f397c582147822d93bc0b834 Mon Sep 17 00:00:00 2001 From: Bartosz Marganiec Date: Sat, 15 Jul 2023 18:48:46 +0200 Subject: [PATCH 2/4] Add test --- spec/ParseFile.spec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/ParseFile.spec.js b/spec/ParseFile.spec.js index eeab537008..d658c31984 100644 --- a/spec/ParseFile.spec.js +++ b/spec/ParseFile.spec.js @@ -1436,4 +1436,25 @@ describe('Parse.File testing', () => { expect(b.url).toMatch(/^http:\/\/localhost:8378\/1\/files\/test\/.*file.html$/); }); }); + + it('works with array with more elements', async () => { + await reconfigureServer({ + fileUpload: { + enableForPublic: true, + fileExtensions: ['jpeg', 'png'], + }, + }); + await expectAsync( + request({ + method: 'POST', + url: 'http://localhost:8378/1/files/file', + body: JSON.stringify({ + _ApplicationId: 'test', + _JavaScriptKey: 'test', + _ContentType: 'image/jpeg', + base64: 'PGh0bWw+PC9odG1sPgo=', + }), + }) + ).toBeResolved(); + }); }); From 8f1ceacdee3586d2c5b1e996165c6ad9435fff34 Mon Sep 17 00:00:00 2001 From: Bartosz Marganiec Date: Mon, 17 Jul 2023 12:31:32 +0200 Subject: [PATCH 3/4] Move test case into the existing test --- spec/ParseFile.spec.js | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/spec/ParseFile.spec.js b/spec/ParseFile.spec.js index d658c31984..0c0b730fed 100644 --- a/spec/ParseFile.spec.js +++ b/spec/ParseFile.spec.js @@ -1368,7 +1368,7 @@ describe('Parse.File testing', () => { await reconfigureServer({ fileUpload: { enableForPublic: true, - fileExtensions: ['jpg'], + fileExtensions: ['jpg', 'any'], }, }); await expectAsync( @@ -1387,6 +1387,18 @@ describe('Parse.File testing', () => { ).toBeRejectedWith( new Parse.Error(Parse.Error.FILE_SAVE_ERROR, `File upload of extension html is disabled.`) ); + await expectAsync( + request({ + method: 'POST', + url: 'http://localhost:8378/1/files/file', + body: JSON.stringify({ + _ApplicationId: 'test', + _JavaScriptKey: 'test', + _ContentType: 'image/jpg', + base64: 'PGh0bWw+PC9odG1sPgo=', + }), + }) + ).toBeResolved(); }); it('works with array without Content-Type', async () => { @@ -1436,25 +1448,4 @@ describe('Parse.File testing', () => { expect(b.url).toMatch(/^http:\/\/localhost:8378\/1\/files\/test\/.*file.html$/); }); }); - - it('works with array with more elements', async () => { - await reconfigureServer({ - fileUpload: { - enableForPublic: true, - fileExtensions: ['jpeg', 'png'], - }, - }); - await expectAsync( - request({ - method: 'POST', - url: 'http://localhost:8378/1/files/file', - body: JSON.stringify({ - _ApplicationId: 'test', - _JavaScriptKey: 'test', - _ContentType: 'image/jpeg', - base64: 'PGh0bWw+PC9odG1sPgo=', - }), - }) - ).toBeResolved(); - }); }); From f5e4205719b2f26f54cb16b4708744b99d5bc00a Mon Sep 17 00:00:00 2001 From: Bartosz Marganiec Date: Mon, 17 Jul 2023 18:51:29 +0200 Subject: [PATCH 4/4] Add wav file to test case --- spec/ParseFile.spec.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/ParseFile.spec.js b/spec/ParseFile.spec.js index 0c0b730fed..f083c90ae4 100644 --- a/spec/ParseFile.spec.js +++ b/spec/ParseFile.spec.js @@ -1368,7 +1368,7 @@ describe('Parse.File testing', () => { await reconfigureServer({ fileUpload: { enableForPublic: true, - fileExtensions: ['jpg', 'any'], + fileExtensions: ['jpg', 'wav'], }, }); await expectAsync( @@ -1399,6 +1399,18 @@ describe('Parse.File testing', () => { }), }) ).toBeResolved(); + await expectAsync( + request({ + method: 'POST', + url: 'http://localhost:8378/1/files/file', + body: JSON.stringify({ + _ApplicationId: 'test', + _JavaScriptKey: 'test', + _ContentType: 'audio/wav', + base64: 'UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA', + }), + }) + ).toBeResolved(); }); it('works with array without Content-Type', async () => {