null check stat when we check file on disk

https://sentry.io/sharelatex-1/sl-web-server-prod/issues/125814174/
This commit is contained in:
Henry Oswald 2017-03-17 13:03:16 +00:00
parent 9a8ee112a5
commit d453a4d5c7
2 changed files with 10 additions and 0 deletions

View file

@ -13,6 +13,9 @@ module.exports = FileStoreHandler =
if err?
logger.err err:err, project_id:project_id, file_id:file_id, fsPath:fsPath, "error stating file"
callback(err)
if !stat?
logger.err project_id:project_id, file_id:file_id, fsPath:fsPath, "stat is not available, can not check file from disk"
return callback(new Error("error getting stat, not available"))
if !stat.isFile()
logger.log project_id:project_id, file_id:file_id, fsPath:fsPath, "tried to upload symlink, not contining"
return callback(new Error("can not upload symlink"))

View file

@ -96,6 +96,13 @@ describe "FileStoreHandler", ->
@fs.createReadStream.called.should.equal false
done()
describe "symlink", ->
it "should not read file stat returns nothing", (done)->
@fs.lstat = sinon.stub().callsArgWith(1, null, null)
@handler.uploadFileFromDisk @project_id, @file_id, @fsPath, =>
@fs.createReadStream.called.should.equal false
done()
describe "when upload fails", ->
beforeEach ->
@writeStream.on = (type, cb) ->