From ffbfc1bf57117b7baa7731cd241e3f6bccd6d4ea Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 26 Aug 2021 10:51:22 +0100 Subject: [PATCH] Merge pull request #4885 from overleaf/bg-filestore-delete-project extend filestore project deletion acceptance tests GitOrigin-RevId: 0433817eee88a7465ab90034043398a6f6736bc0 --- services/filestore/package-lock.json | 2 +- .../test/acceptance/js/FilestoreTests.js | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/services/filestore/package-lock.json b/services/filestore/package-lock.json index 80d598b51f..edcb44f7fa 100644 --- a/services/filestore/package-lock.json +++ b/services/filestore/package-lock.json @@ -1079,7 +1079,7 @@ "integrity": "sha512-LsM2s6Iy9G97ktPo0ys4VxtI/m3ahc1ZHwjo5XnhXtjeIkkkVAehsrcRRoV/yWepPjymB0oZonhcfojpjYR/tg==" }, "@overleaf/object-persistor": { - "version": "1.0.1", + "version": "1.0.2", "resolved": "https://registry.npmjs.org/@overleaf/object-persistor/-/object-persistor-1.0.1.tgz", "integrity": "sha512-8yGsmPIeeFqsfXKdKdW1CWQ60mr3Wfoc/HBPl36gKspjehvDKuOrhEnSRxmE5GBZacK3wvW4JloVaUV0RiAKfA==", "requires": { diff --git a/services/filestore/test/acceptance/js/FilestoreTests.js b/services/filestore/test/acceptance/js/FilestoreTests.js index 47d252b07c..2777e79728 100644 --- a/services/filestore/test/acceptance/js/FilestoreTests.js +++ b/services/filestore/test/acceptance/js/FilestoreTests.js @@ -81,7 +81,12 @@ describe('Filestore', function () { // redefine the test suite for every available backend Object.keys(BackendSettings).forEach(backend => { describe(backend, function () { - let app, previousEgress, previousIngress, metricPrefix, projectId + let app, + previousEgress, + previousIngress, + metricPrefix, + projectId, + otherProjectId before(async function () { // create the app with the relevant filestore settings @@ -123,6 +128,7 @@ describe('Filestore', function () { ) } projectId = ObjectId().toString() + otherProjectId = ObjectId().toString() }) it('should send a 200 for the status endpoint', async function () { @@ -302,10 +308,11 @@ describe('Filestore', function () { }) describe('with multiple files', function () { - let fileIds, fileUrls, projectUrl + let fileIds, fileUrls, otherFileUrls, projectUrl, otherProjectUrl const localFileReadPaths = [ '/tmp/filestore_acceptance_tests_file_read_1.txt', '/tmp/filestore_acceptance_tests_file_read_2.txt', + '/tmp/filestore_acceptance_tests_file_read_3.txt', ] const constantFileContents = [ [ @@ -318,39 +325,55 @@ describe('Filestore', function () { 'cats are the best animals', 'wombats are a close second', ].join('\n'), + [ + `another file: ${Math.random()}`, + 'with multiple lines', + 'the end', + ].join('\n'), ] before(async function () { return Promise.all([ fsWriteFile(localFileReadPaths[0], constantFileContents[0]), fsWriteFile(localFileReadPaths[1], constantFileContents[1]), + fsWriteFile(localFileReadPaths[2], constantFileContents[2]), ]) }) beforeEach(async function () { projectUrl = `${filestoreUrl}/project/${projectId}` - fileIds = [ObjectId().toString(), ObjectId().toString()] + otherProjectUrl = `${filestoreUrl}/project/${otherProjectId}` + fileIds = [ + ObjectId().toString(), + ObjectId().toString(), + ObjectId().toString(), + ] fileUrls = [ `${projectUrl}/file/${fileIds[0]}`, `${projectUrl}/file/${fileIds[1]}`, ] + otherFileUrls = [`${otherProjectUrl}/file/${fileIds[2]}`] const writeStreams = [ request.post(fileUrls[0]), request.post(fileUrls[1]), + request.post(otherFileUrls[0]), ] const readStreams = [ fs.createReadStream(localFileReadPaths[0]), fs.createReadStream(localFileReadPaths[1]), + fs.createReadStream(localFileReadPaths[2]), ] // hack to consume the result to ensure the http request has been fully processed const resultStreams = [ fs.createWriteStream('/dev/null'), fs.createWriteStream('/dev/null'), + fs.createWriteStream('/dev/null'), ] return Promise.all([ pipeline(readStreams[0], writeStreams[0], resultStreams[0]), pipeline(readStreams[1], writeStreams[1], resultStreams[1]), + pipeline(readStreams[2], writeStreams[2], resultStreams[2]), ]) }) @@ -385,6 +408,14 @@ describe('Filestore', function () { } }) + it('should not delete files in other projects', async function () { + for (const index in otherFileUrls) { + await expect( + rp.get(otherFileUrls[index]) + ).to.eventually.have.property('statusCode', 200) + } + }) + it('should not delete a partial project id', async function () { await expect( rp.delete(`${filestoreUrl}/project/5`)