filter invalid updates

This commit is contained in:
Brian Gough 2019-05-24 10:19:02 +01:00
parent 8086d01001
commit 20d5cc69a4
2 changed files with 19 additions and 3 deletions

View file

@ -1,4 +1,5 @@
request = require "request" request = require "request"
_ = require "underscore"
logger = require "logger-sharelatex" logger = require "logger-sharelatex"
settings = require "settings-sharelatex" settings = require "settings-sharelatex"
metrics = require("metrics-sharelatex") metrics = require("metrics-sharelatex")
@ -53,6 +54,8 @@ module.exports = DocumentUpdaterManager =
return callback(err) return callback(err)
queueChange: (project_id, doc_id, change, callback = ()->)-> queueChange: (project_id, doc_id, change, callback = ()->)->
allowedKeys = [ 'doc', 'op', 'v', 'dupIfSource', 'meta', 'lastV', 'hash']
change = _.pick change, allowedKeys
jsonChange = JSON.stringify change jsonChange = JSON.stringify change
if jsonChange.indexOf("\u0000") != -1 if jsonChange.indexOf("\u0000") != -1
error = new Error("null bytes found in op") error = new Error("null bytes found in op")

View file

@ -122,9 +122,9 @@ describe 'DocumentUpdaterManager', ->
describe 'queueChange', -> describe 'queueChange', ->
beforeEach -> beforeEach ->
@change = { @change = {
"action":"removeText", "doc":"1234567890",
"range":{"start":{"row":2,"column":2},"end":{"row":2,"column":3}}, "op":["d":"test", "p":345]
"text":"e" "v": 789
} }
@rclient.rpush = sinon.stub().yields() @rclient.rpush = sinon.stub().yields()
@callback = sinon.stub() @callback = sinon.stub()
@ -161,3 +161,16 @@ describe 'DocumentUpdaterManager', ->
it "should not push the change onto the pending-updates-list queue", -> it "should not push the change onto the pending-updates-list queue", ->
@rclient.rpush.called.should.equal false @rclient.rpush.called.should.equal false
describe "with invalid keys", ->
beforeEach ->
@change = {
"op":["d":"test", "p":345]
"version": 789 # not a valid key
}
@DocumentUpdaterManager.queueChange(@project_id, @doc_id, @change, @callback)
it "should remove the invalid keys from the change", ->
@rclient.rpush
.calledWith("PendingUpdates:#{@doc_id}", JSON.stringify({op:@change.op}))
.should.equal true