mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Don't allow a document to be loaded without a pathname
This commit is contained in:
parent
b1b2dbcf53
commit
939eaa2d4b
4 changed files with 25 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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}"))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ->
|
||||
|
|
Loading…
Reference in a new issue