From e014aeb10088ca1fe474bd1637a17f113da878e4 Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Tue, 26 May 2020 17:21:21 +0200 Subject: [PATCH] Fixed regular expression to insert/delete files not supporting templates api --- services/filestore/app/js/FileHandler.js | 4 ++-- .../test/unit/js/FileHandlerTests.js | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/services/filestore/app/js/FileHandler.js b/services/filestore/app/js/FileHandler.js index b76bdff7a2..e5933ffca7 100644 --- a/services/filestore/app/js/FileHandler.js +++ b/services/filestore/app/js/FileHandler.js @@ -29,7 +29,7 @@ module.exports = { async function insertFile(bucket, key, stream) { const convertedKey = KeyBuilder.getConvertedFolderKey(key) - if (!convertedKey.match(/^[0-9a-f]{24}\/[0-9a-f]{24}/i)) { + if (!convertedKey.match(/^[0-9a-f]{24}\/([0-9a-f]{24}|v\/[0-9]+\/[a-z]+)/i)) { throw new InvalidParametersError({ message: 'key does not match validation regex', info: { bucket, key, convertedKey } @@ -43,7 +43,7 @@ async function insertFile(bucket, key, stream) { async function deleteFile(bucket, key) { const convertedKey = KeyBuilder.getConvertedFolderKey(key) - if (!convertedKey.match(/^[0-9a-f]{24}\/[0-9a-f]{24}/i)) { + if (!convertedKey.match(/^[0-9a-f]{24}\/([0-9a-f]{24}|v\/[0-9]+\/[a-z]+)/i)) { throw new InvalidParametersError({ message: 'key does not match validation regex', info: { bucket, key, convertedKey } diff --git a/services/filestore/test/unit/js/FileHandlerTests.js b/services/filestore/test/unit/js/FileHandlerTests.js index f6a0c02fa4..22fe8d1503 100644 --- a/services/filestore/test/unit/js/FileHandlerTests.js +++ b/services/filestore/test/unit/js/FileHandlerTests.js @@ -111,6 +111,16 @@ describe('FileHandler', function() { }) }) + it('should accept templates-api key format', function(done) { + KeyBuilder.getConvertedFolderKey.returns( + '5ecba29f1a294e007d0bccb4/v/0/pdf' + ) + FileHandler.insertFile(bucket, key, stream, err => { + expect(err).not.to.exist + done() + }) + }) + it('should throw an error when the key is in the wrong format', function(done) { KeyBuilder.getConvertedFolderKey.returns('wombat') FileHandler.insertFile(bucket, key, stream, err => { @@ -157,6 +167,16 @@ describe('FileHandler', function() { }) }) + it('should accept templates-api key format', function(done) { + KeyBuilder.getConvertedFolderKey.returns( + '5ecba29f1a294e007d0bccb4/v/0/pdf' + ) + FileHandler.deleteFile(bucket, key, err => { + expect(err).not.to.exist + done() + }) + }) + it('should throw an error when the key is in the wrong format', function(done) { KeyBuilder.getConvertedFolderKey.returns('wombat') FileHandler.deleteFile(bucket, key, err => {