Просмотр исходного кода

Merge pull request #23 from sharelatex/ja-pathname-fixes

Don't allow a document to be loaded without a pathname
James Allen 8 лет назад
Родитель
Сommit
c62e336eb8

+ 1 - 1
services/document-updater/app/coffee/DocumentManager.coffee

@@ -24,7 +24,7 @@ module.exports = DocumentManager =
 				logger.log {project_id, doc_id}, "doc not in redis so getting from persistence API"
 				PersistenceManager.getDoc project_id, doc_id, (error, lines, version, ranges, pathname) ->
 					return callback(error) if error?
-					logger.log {project_id, doc_id, lines, version}, "got doc from persistence API"
+					logger.log {project_id, doc_id, lines, version, pathname}, "got doc from persistence API"
 					RedisManager.putDocInMemory project_id, doc_id, lines, version, ranges, pathname, (error) ->
 						return callback(error) if error?
 						callback null, lines, version, ranges, pathname, null, false

+ 2 - 0
services/document-updater/app/coffee/PersistenceManager.coffee

@@ -42,6 +42,8 @@ module.exports = PersistenceManager =
 					return callback(new Error("web API response had no doc lines"))
 				if !body.version? or not body.version instanceof Number
 					return callback(new Error("web API response had no valid doc version"))
+				if !body.pathname?
+					return callback(new Error("web API response had no valid doc pathname"))
 				return callback null, body.lines, body.version, body.ranges, body.pathname
 			else if res.statusCode == 404
 				return callback(new Errors.NotFoundError("doc not not found: #{url}"))

+ 1 - 1
services/document-updater/app/coffee/RedisManager.coffee

@@ -47,7 +47,7 @@ module.exports = RedisManager =
 			logger.error {err: error, doc_id: doc_id, docLines: docLines}, error.message
 			return callback(error)
 		docHash = RedisManager._computeHash(docLines)
-		logger.log project_id:project_id, doc_id:doc_id, version: version, hash:docHash, "putting doc in redis"
+		logger.log {project_id, doc_id, version, docHash, pathname}, "putting doc in redis"
 		RedisManager._serializeRanges ranges, (error, ranges) ->
 			if error?
 				logger.error {err: error, doc_id, project_id}, error.message

+ 21 - 8
services/document-updater/test/unit/coffee/PersistenceManager/PersistenceManagerTests.coffee

@@ -30,15 +30,17 @@ describe "PersistenceManager", ->
 				pass: @pass = "password"
 
 	describe "getDoc", ->
+		beforeEach ->
+			@webResponse = {
+				lines: @lines,
+				version: @version,
+				ranges: @ranges
+				pathname: @pathname,
+			}
 
 		describe "with a successful response from the web api", ->
 			beforeEach ->
-				@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify({
-					lines: @lines,
-					version: @version,
-					ranges: @ranges
-					pathname: @pathname,
-				}))
+				@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(@webResponse))
 				@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
 
 			it "should call the web api", ->
@@ -98,7 +100,8 @@ describe "PersistenceManager", ->
 
 		describe "when request returns an doc without lines", ->
 			beforeEach ->
-				@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(version: @version))
+				delete @webResponse.lines
+				@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(@webResponse))
 				@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
 
 			it "should return and error", ->
@@ -106,12 +109,22 @@ describe "PersistenceManager", ->
 
 		describe "when request returns an doc without a version", ->
 			beforeEach ->
-				@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(lines: @lines))
+				delete @webResponse.version
+				@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(@webResponse))
 				@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
 
 			it "should return and error", ->
 				@callback.calledWith(new Error("web API response had no valid doc version")).should.equal true
 
+		describe "when request returns an doc without a pathname", ->
+			beforeEach ->
+				delete @webResponse.pathname
+				@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(@webResponse))
+				@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
+
+			it "should return and error", ->
+				@callback.calledWith(new Error("web API response had no valid doc pathname")).should.equal true
+
 	describe "setDoc", ->
 		describe "with a successful response from the web api", ->
 			beforeEach ->