Merge pull request #16 from sharelatex/ho-check-unarchive-lines

error if doc lines are not array when unarchiving
This commit is contained in:
Henry Oswald 2017-03-09 17:38:02 +00:00 committed by GitHub
commit 2fbb148438
2 changed files with 12 additions and 1 deletions

View file

@ -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, lines:lines, "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"
@ -87,4 +90,4 @@ module.exports = DocArchive =
timeout: thirtySeconds
json: content
uri:"https://#{settings.docstore.s3.bucket}.s3.amazonaws.com/#{key}"
}
}

View file

@ -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)->