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

Don't allow a document to be loaded without a pathname
This commit is contained in:
James Allen 2018-03-06 10:20:01 +00:00 committed by GitHub
commit c62e336eb8
4 changed files with 25 additions and 10 deletions

View file

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

View file

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

View file

@ -47,7 +47,7 @@ module.exports = RedisManager =
logger.error {err: error, doc_id: doc_id, docLines: docLines}, error.message logger.error {err: error, doc_id: doc_id, docLines: docLines}, error.message
return callback(error) return callback(error)
docHash = RedisManager._computeHash(docLines) 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) -> RedisManager._serializeRanges ranges, (error, ranges) ->
if error? if error?
logger.error {err: error, doc_id, project_id}, error.message logger.error {err: error, doc_id, project_id}, error.message

View file

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