2014-11-14 10:12:35 +00:00
|
|
|
async = require "async"
|
|
|
|
chai = require("chai")
|
|
|
|
expect = chai.expect
|
|
|
|
chai.should()
|
|
|
|
|
|
|
|
RealTimeClient = require "./helpers/RealTimeClient"
|
|
|
|
FixturesManager = require "./helpers/FixturesManager"
|
|
|
|
|
|
|
|
settings = require "settings-sharelatex"
|
|
|
|
redis = require "redis-sharelatex"
|
2018-05-23 14:00:46 +00:00
|
|
|
rclient = redis.createClient(settings.redis.websessions)
|
2014-11-14 10:12:35 +00:00
|
|
|
|
2019-02-04 09:47:11 +00:00
|
|
|
redisSettings = settings.redis
|
|
|
|
|
2014-11-13 17:07:05 +00:00
|
|
|
describe "applyOtUpdate", ->
|
2014-11-14 10:12:35 +00:00
|
|
|
before ->
|
|
|
|
@update = {
|
|
|
|
op: [{i: "foo", p: 42}]
|
|
|
|
}
|
2014-11-13 17:07:05 +00:00
|
|
|
describe "when authorized", ->
|
2014-11-14 10:12:35 +00:00
|
|
|
before (done) ->
|
|
|
|
async.series [
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: "readAndWrite"
|
|
|
|
}, (e, {@project_id, @user_id}) =>
|
|
|
|
cb(e)
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
|
|
|
|
cb(e)
|
2016-12-08 11:25:25 +00:00
|
|
|
|
2014-11-14 10:12:35 +00:00
|
|
|
(cb) =>
|
|
|
|
@client = RealTimeClient.connect()
|
2016-12-08 11:25:25 +00:00
|
|
|
@client.on "connectionAccepted", cb
|
|
|
|
|
|
|
|
(cb) =>
|
2014-11-14 10:12:35 +00:00
|
|
|
@client.emit "joinProject", project_id: @project_id, cb
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "joinDoc", @doc_id, cb
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "applyOtUpdate", @doc_id, @update, cb
|
|
|
|
], done
|
2014-11-13 17:07:05 +00:00
|
|
|
|
2014-11-14 10:12:35 +00:00
|
|
|
it "should push the doc into the pending updates list", (done) ->
|
|
|
|
rclient.lrange "pending-updates-list", 0, -1, (error, [doc_id]) =>
|
|
|
|
doc_id.should.equal "#{@project_id}:#{@doc_id}"
|
|
|
|
done()
|
2019-05-30 09:58:05 +00:00
|
|
|
return null
|
2014-11-14 10:12:35 +00:00
|
|
|
|
|
|
|
it "should push the update into redis", (done) ->
|
2019-02-04 09:47:11 +00:00
|
|
|
rclient.lrange redisSettings.documentupdater.key_schema.pendingUpdates({@doc_id}), 0, -1, (error, [update]) =>
|
2014-11-14 10:12:35 +00:00
|
|
|
update = JSON.parse(update)
|
|
|
|
update.op.should.deep.equal @update.op
|
|
|
|
update.meta.should.deep.equal {
|
|
|
|
source: @client.socket.sessionid
|
|
|
|
user_id: @user_id
|
|
|
|
}
|
|
|
|
done()
|
2019-05-30 09:58:05 +00:00
|
|
|
return null
|
|
|
|
|
2014-11-14 10:12:35 +00:00
|
|
|
after (done) ->
|
|
|
|
async.series [
|
|
|
|
(cb) => rclient.del "pending-updates-list", cb
|
|
|
|
(cb) => rclient.del "DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}", cb
|
2019-02-04 09:47:11 +00:00
|
|
|
(cb) => rclient.del redisSettings.documentupdater.key_schema.pendingUpdates(@doc_id), cb
|
2014-11-14 10:12:35 +00:00
|
|
|
], done
|
2014-11-13 17:07:05 +00:00
|
|
|
|
2017-03-15 15:45:52 +00:00
|
|
|
describe "when authorized to read-only with an edit update", ->
|
2014-11-14 10:12:35 +00:00
|
|
|
before (done) ->
|
|
|
|
async.series [
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: "readOnly"
|
|
|
|
}, (e, {@project_id, @user_id}) =>
|
|
|
|
cb(e)
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
|
|
|
|
cb(e)
|
2016-12-08 11:25:25 +00:00
|
|
|
|
2014-11-14 10:12:35 +00:00
|
|
|
(cb) =>
|
|
|
|
@client = RealTimeClient.connect()
|
2016-12-08 11:25:25 +00:00
|
|
|
@client.on "connectionAccepted", cb
|
|
|
|
|
|
|
|
(cb) =>
|
2014-11-14 10:12:35 +00:00
|
|
|
@client.emit "joinProject", project_id: @project_id, cb
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "joinDoc", @doc_id, cb
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "applyOtUpdate", @doc_id, @update, (@error) =>
|
|
|
|
cb()
|
|
|
|
], done
|
|
|
|
|
|
|
|
it "should return an error", ->
|
|
|
|
expect(@error).to.exist
|
2014-11-13 17:07:05 +00:00
|
|
|
|
2014-11-14 10:12:35 +00:00
|
|
|
it "should disconnect the client", (done) ->
|
|
|
|
setTimeout () =>
|
|
|
|
@client.socket.connected.should.equal false
|
|
|
|
done()
|
|
|
|
, 300
|
|
|
|
|
|
|
|
it "should not put the update in redis", (done) ->
|
2019-02-04 09:47:11 +00:00
|
|
|
rclient.llen redisSettings.documentupdater.key_schema.pendingUpdates({@doc_id}), (error, len) =>
|
2014-11-14 10:12:35 +00:00
|
|
|
len.should.equal 0
|
2017-03-15 15:45:52 +00:00
|
|
|
done()
|
2019-05-30 09:58:05 +00:00
|
|
|
return null
|
2017-03-15 15:45:52 +00:00
|
|
|
|
|
|
|
describe "when authorized to read-only with a comment update", ->
|
|
|
|
before (done) ->
|
|
|
|
@comment_update = {
|
|
|
|
op: [{c: "foo", p: 42}]
|
|
|
|
}
|
|
|
|
async.series [
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: "readOnly"
|
|
|
|
}, (e, {@project_id, @user_id}) =>
|
|
|
|
cb(e)
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
|
|
|
|
cb(e)
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client = RealTimeClient.connect()
|
|
|
|
@client.on "connectionAccepted", cb
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "joinProject", project_id: @project_id, cb
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "joinDoc", @doc_id, cb
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "applyOtUpdate", @doc_id, @comment_update, cb
|
|
|
|
], done
|
|
|
|
|
|
|
|
it "should push the doc into the pending updates list", (done) ->
|
|
|
|
rclient.lrange "pending-updates-list", 0, -1, (error, [doc_id]) =>
|
|
|
|
doc_id.should.equal "#{@project_id}:#{@doc_id}"
|
|
|
|
done()
|
2019-05-30 09:58:05 +00:00
|
|
|
return null
|
2017-03-15 15:45:52 +00:00
|
|
|
|
|
|
|
it "should push the update into redis", (done) ->
|
2019-02-04 09:47:11 +00:00
|
|
|
rclient.lrange redisSettings.documentupdater.key_schema.pendingUpdates({@doc_id}), 0, -1, (error, [update]) =>
|
2017-03-15 15:45:52 +00:00
|
|
|
update = JSON.parse(update)
|
|
|
|
update.op.should.deep.equal @comment_update.op
|
|
|
|
update.meta.should.deep.equal {
|
|
|
|
source: @client.socket.sessionid
|
|
|
|
user_id: @user_id
|
|
|
|
}
|
|
|
|
done()
|
2019-05-30 09:58:05 +00:00
|
|
|
return null
|
|
|
|
|
2017-03-15 15:45:52 +00:00
|
|
|
after (done) ->
|
|
|
|
async.series [
|
|
|
|
(cb) => rclient.del "pending-updates-list", cb
|
|
|
|
(cb) => rclient.del "DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}", cb
|
2019-02-04 09:47:11 +00:00
|
|
|
(cb) => rclient.del redisSettings.documentupdater.key_schema.pendingUpdates({@doc_id}), cb
|
2017-03-15 15:45:52 +00:00
|
|
|
], done
|