mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add in guards on bad data from web API
This commit is contained in:
parent
546d9e9cee
commit
efab68e6b2
2 changed files with 21 additions and 1 deletions
|
@ -35,6 +35,10 @@ module.exports = PersistenceManager =
|
|||
body = JSON.parse body
|
||||
catch e
|
||||
return callback(e)
|
||||
if !body.lines?
|
||||
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"))
|
||||
return callback null, body.lines, body.version
|
||||
else if res.statusCode == 404
|
||||
return callback(new Errors.NotFoundError("doc not not found: #{url}"))
|
||||
|
|
|
@ -84,5 +84,21 @@ describe "PersistenceManager.getDoc", ->
|
|||
|
||||
it "should time the execution", ->
|
||||
@Metrics.Timer::done.called.should.equal true
|
||||
|
||||
|
||||
describe "when request returns an doc without lines", ->
|
||||
beforeEach ->
|
||||
@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(version: @version))
|
||||
@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
|
||||
|
||||
it "should return and error", ->
|
||||
@callback.calledWith(new Error("web API response had no doc lines")).should.equal true
|
||||
|
||||
describe "when request returns an doc without a version", ->
|
||||
beforeEach ->
|
||||
@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(lines: @lines))
|
||||
@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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue