Эх сурвалжийг харах

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

error if doc lines are not array when unarchiving
Henry Oswald 9 жил өмнө
parent
commit
2fbb148438

+ 4 - 1
services/docstore/app/coffee/DocArchiveManager.coffee

@@ -67,6 +67,9 @@ module.exports = DocArchive =
 			if err? || res.statusCode != 200
 			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"
 				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")
 				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) ->
 			MongoManager.upsertIntoDocCollection project_id, doc_id.toString(), {lines}, (err) ->
 				return callback(err) if err?
 				return callback(err) if err?
 				logger.log project_id: project_id, doc_id: doc_id, "deleting doc from s3"
 				logger.log project_id: project_id, doc_id: doc_id, "deleting doc from s3"
@@ -87,4 +90,4 @@ module.exports = DocArchive =
 				timeout: thirtySeconds
 				timeout: thirtySeconds
 				json: content
 				json: content
 				uri:"https://#{settings.docstore.s3.bucket}.s3.amazonaws.com/#{key}"
 				uri:"https://#{settings.docstore.s3.bucket}.s3.amazonaws.com/#{key}"
-		}
+		}

+ 8 - 0
services/docstore/test/unit/coffee/DocArchiveManager.coffee → services/docstore/test/unit/coffee/DocArchiveManagerTests.coffee

@@ -124,6 +124,14 @@ describe "DocArchiveManager", ->
 				should.exist err
 				should.exist err
 				done()
 				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", ->
 	describe "archiveAllDocs", ->
 
 
 		it "should archive all project docs which are not in s3", (done)->
 		it "should archive all project docs which are not in s3", (done)->