From dbfe5ac7125973ef8883982d649851f681e94174 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 9 Mar 2017 17:34:33 +0000 Subject: [PATCH] error if doc lines are not array when unarchiving --- services/docstore/app/coffee/DocArchiveManager.coffee | 3 +++ ...rchiveManager.coffee => DocArchiveManagerTests.coffee} | 8 ++++++++ 2 files changed, 11 insertions(+) rename services/docstore/test/unit/coffee/{DocArchiveManager.coffee => DocArchiveManagerTests.coffee} (94%) diff --git a/services/docstore/app/coffee/DocArchiveManager.coffee b/services/docstore/app/coffee/DocArchiveManager.coffee index 925ad3bfc9..8a2c3a2958 100644 --- a/services/docstore/app/coffee/DocArchiveManager.coffee +++ b/services/docstore/app/coffee/DocArchiveManager.coffee @@ -67,6 +67,9 @@ module.exports = DocArchive = if err? || res.statusCode != 200 logger.err err:err, res:res, project_id:project_id, doc_id:doc_id, "something went wrong unarchiving doc from aws" return callback new Errors.NotFoundError("Error in S3 request") + if !(lines instanceof Array) + logger.err err:err, res:res, project_id:project_id, doc_id:doc_id, "doc lines from aws are not in array format, likely not JSON parsable" + return callback(new Error("Error unpacking doc")) MongoManager.upsertIntoDocCollection project_id, doc_id.toString(), {lines}, (err) -> return callback(err) if err? logger.log project_id: project_id, doc_id: doc_id, "deleting doc from s3" diff --git a/services/docstore/test/unit/coffee/DocArchiveManager.coffee b/services/docstore/test/unit/coffee/DocArchiveManagerTests.coffee similarity index 94% rename from services/docstore/test/unit/coffee/DocArchiveManager.coffee rename to services/docstore/test/unit/coffee/DocArchiveManagerTests.coffee index cac4594dd2..7966b30552 100644 --- a/services/docstore/test/unit/coffee/DocArchiveManager.coffee +++ b/services/docstore/test/unit/coffee/DocArchiveManagerTests.coffee @@ -124,6 +124,14 @@ describe "DocArchiveManager", -> should.exist err done() + it "should error if the doc lines are a string not an array", (done)-> + @request.get = sinon.stub().callsArgWith(1, null, statusCode:200, "this is a string") + @request.del = sinon.stub() + @DocArchiveManager.unarchiveDoc @project_id, @mongoDocs[0], (err)=> + should.exist err + @request.del.called.should.equal false + done() + describe "archiveAllDocs", -> it "should archive all project docs which are not in s3", (done)->