From 49b764a308a82939d3c3ce2d2d85cfbf9aa464e2 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 28 Dec 2020 13:16:31 +0000 Subject: [PATCH] [misc] CompileController: exact match for output.pdf The previous regex could mistake user provided pdf files, like `fake_output.pdf`, as the final output file. The frontend expects to find a `output.pdf` file on success. --- services/clsi/app/js/CompileController.js | 6 +-- .../test/unit/js/CompileControllerTests.js | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/services/clsi/app/js/CompileController.js b/services/clsi/app/js/CompileController.js index fb7367cef3..b0ce3bb664 100644 --- a/services/clsi/app/js/CompileController.js +++ b/services/clsi/app/js/CompileController.js @@ -80,11 +80,7 @@ module.exports = CompileController = { let file status = 'failure' for (file of Array.from(outputFiles)) { - if ( - file.path != null - ? file.path.match(/output\.pdf$/) - : undefined - ) { + if (file.path === 'output.pdf') { status = 'success' } } diff --git a/services/clsi/test/unit/js/CompileControllerTests.js b/services/clsi/test/unit/js/CompileControllerTests.js index 1c93c96ea4..70f67b602f 100644 --- a/services/clsi/test/unit/js/CompileControllerTests.js +++ b/services/clsi/test/unit/js/CompileControllerTests.js @@ -129,6 +129,47 @@ describe('CompileController', function () { }) }) + describe('with user provided fake_output.pdf', function () { + beforeEach(function () { + this.output_files = [ + { + path: 'fake_output.pdf', + type: 'pdf', + build: 1234 + }, + { + path: 'output.log', + type: 'log', + build: 1234 + } + ] + this.CompileManager.doCompileWithLock = sinon + .stub() + .callsArgWith(1, null, this.output_files) + this.CompileController.compile(this.req, this.res) + }) + + it('should return the JSON response with status failure', function () { + this.res.status.calledWith(200).should.equal(true) + this.res.send + .calledWith({ + compile: { + status: 'failure', + error: null, + outputFiles: this.output_files.map((file) => { + return { + url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`, + path: file.path, + type: file.type, + build: file.build + } + }) + } + }) + .should.equal(true) + }) + }) + describe('with an error', function () { beforeEach(function () { this.CompileManager.doCompileWithLock = sinon