Brian Gough 7 лет назад
Родитель
Сommit
20d5cc69a4

+ 3 - 0
services/real-time/app/coffee/DocumentUpdaterManager.coffee

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

+ 16 - 3
services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee

@@ -122,9 +122,9 @@ describe 'DocumentUpdaterManager', ->
 	describe 'queueChange', ->
 		beforeEach ->
 			@change = {
-				"action":"removeText",
-				"range":{"start":{"row":2,"column":2},"end":{"row":2,"column":3}},
-				"text":"e"
+				"doc":"1234567890",
+				"op":["d":"test", "p":345]
+				"v": 789
 			}
 			@rclient.rpush = sinon.stub().yields()
 			@callback = sinon.stub()
@@ -161,3 +161,16 @@ describe 'DocumentUpdaterManager', ->
 
 			it "should not push the change onto the pending-updates-list queue", ->
 				@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