[misc] skip duplicate JSON serialization for size check

This commit is contained in:
Jakob Ackermann
2020-03-24 11:22:28 +01:00
parent cb675d38c2
commit af53d3b603
5 changed files with 46 additions and 23 deletions
@@ -71,8 +71,10 @@ describe "applyOtUpdate", ->
describe "when authorized with a huge edit update", ->
before (done) ->
@update = {
op: {p: 12, t: "foo"},
junk: 'this update is too large'.repeat(1024 * 300) # >7MB
op: {
p: 12,
t: "update is too large".repeat(1024 * 400) # >7MB
}
}
async.series [
(cb) =>
@@ -15,6 +15,7 @@ describe 'DocumentUpdaterManager', ->
redis: documentupdater:
key_schema:
pendingUpdates: ({doc_id}) -> "PendingUpdates:#{doc_id}"
maxUpdateSize: 7 * 1024 * 1024
@rclient = {auth:->}
@DocumentUpdaterManager = SandboxedModule.require modulePath,
@@ -163,6 +164,20 @@ describe 'DocumentUpdaterManager', ->
it "should not push the change onto the pending-updates-list queue", ->
@rclient.rpush.called.should.equal false
describe "when the update is too large", ->
beforeEach ->
@change = {op: {p: 12,t: "update is too large".repeat(1024 * 400)}}
@DocumentUpdaterManager.queueChange(@project_id, @doc_id, @change, @callback)
it "should return an error", ->
@callback.calledWithExactly(sinon.match(Error)).should.equal true
it "should add the size to the error", ->
@callback.args[0][0].updateSize.should.equal 7782422
it "should not push the change onto the pending-updates-list queue", ->
@rclient.rpush.called.should.equal false
describe "with invalid keys", ->
beforeEach ->
@change = {
@@ -32,7 +32,6 @@ describe 'WebsocketController', ->
"./DocumentUpdaterManager": @DocumentUpdaterManager = {}
"./ConnectedUsersManager": @ConnectedUsersManager = {}
"./WebsocketLoadBalancer": @WebsocketLoadBalancer = {}
"settings-sharelatex": {maxUpdateSize: 7 * 1024 * 1024}
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() }
"metrics-sharelatex": @metrics =
inc: sinon.stub()
@@ -673,12 +672,11 @@ describe 'WebsocketController', ->
beforeEach (done) ->
@client.disconnect = sinon.stub()
@client.emit = sinon.stub()
@update = {
op: {p: 12, t: "foo"},
junk: 'this update is too large'.repeat(1024 * 300) # >7MB
}
@client.params.user_id = @user_id
@client.params.project_id = @project_id
error = new Error("update is too large")
error.updateSize = 7372835
@DocumentUpdaterManager.queueChange = sinon.stub().callsArgWith(3, error)
@WebsocketController.applyOtUpdate @client, @doc_id, @update, @callback
setTimeout ->
done()