2016-03-08 15:59:04 +00:00
|
|
|
expect = require("chai").expect
|
2016-03-18 15:59:03 +00:00
|
|
|
async = require("async")
|
|
|
|
User = require "./helpers/User"
|
|
|
|
request = require "./helpers/request"
|
|
|
|
settings = require "settings-sharelatex"
|
2016-03-08 15:59:04 +00:00
|
|
|
|
2017-09-27 08:37:20 +00:00
|
|
|
MockDocstoreApi = require './helpers/MockDocstoreApi'
|
|
|
|
MockDocUpdaterApi = require './helpers/MockDocUpdaterApi'
|
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
try_read_access = (user, project_id, test, callback) ->
|
2016-03-10 11:13:57 +00:00
|
|
|
async.series [
|
2016-03-09 12:31:46 +00:00
|
|
|
(cb) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
user.request.get "/project/#{project_id}", (error, response, body) ->
|
2016-03-09 12:31:46 +00:00
|
|
|
return cb(error) if error?
|
|
|
|
test(response, body)
|
|
|
|
cb()
|
|
|
|
(cb) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
user.request.get "/project/#{project_id}/download/zip", (error, response, body) ->
|
2016-03-09 12:31:46 +00:00
|
|
|
return cb(error) if error?
|
|
|
|
test(response, body)
|
|
|
|
cb()
|
|
|
|
], callback
|
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
try_settings_write_access = (user, project_id, test, callback) ->
|
2016-03-10 11:13:57 +00:00
|
|
|
async.series [
|
2016-03-09 12:31:46 +00:00
|
|
|
(cb) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
user.request.post {
|
2016-03-09 12:31:46 +00:00
|
|
|
uri: "/project/#{project_id}/settings"
|
|
|
|
json:
|
|
|
|
compiler: "latex"
|
|
|
|
}, (error, response, body) ->
|
|
|
|
return cb(error) if error?
|
|
|
|
test(response, body)
|
|
|
|
cb()
|
|
|
|
], callback
|
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
try_admin_access = (user, project_id, test, callback) ->
|
2016-03-10 11:13:57 +00:00
|
|
|
async.series [
|
2016-03-09 12:31:46 +00:00
|
|
|
(cb) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
user.request.post {
|
2016-03-09 12:31:46 +00:00
|
|
|
uri: "/project/#{project_id}/rename"
|
|
|
|
json:
|
|
|
|
newProjectName: "new-name"
|
|
|
|
}, (error, response, body) ->
|
|
|
|
return cb(error) if error?
|
|
|
|
test(response, body)
|
|
|
|
cb()
|
2016-03-10 11:13:57 +00:00
|
|
|
(cb) ->
|
|
|
|
user.request.post {
|
|
|
|
uri: "/project/#{project_id}/settings/admin"
|
|
|
|
json:
|
|
|
|
publicAccessLevel: "private"
|
|
|
|
}, (error, response, body) ->
|
|
|
|
return cb(error) if error?
|
|
|
|
test(response, body)
|
|
|
|
cb()
|
2016-03-09 12:31:46 +00:00
|
|
|
], callback
|
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
try_content_access = (user, project_id, test, callback) ->
|
|
|
|
# The real-time service calls this end point to determine the user's
|
|
|
|
# permissions.
|
2016-03-22 09:53:47 +00:00
|
|
|
if user.id?
|
|
|
|
user_id = user.id
|
|
|
|
else
|
|
|
|
user_id = "anonymous-user"
|
2016-03-09 16:26:18 +00:00
|
|
|
request.post {
|
|
|
|
url: "/project/#{project_id}/join"
|
2016-03-22 09:53:47 +00:00
|
|
|
qs: {user_id}
|
2016-03-09 16:26:18 +00:00
|
|
|
auth:
|
|
|
|
user: settings.apis.web.user
|
|
|
|
pass: settings.apis.web.pass
|
|
|
|
sendImmediately: true
|
|
|
|
json: true
|
|
|
|
jar: false
|
|
|
|
}, (error, response, body) ->
|
|
|
|
return callback(error) if error?
|
|
|
|
test(response, body)
|
|
|
|
callback()
|
|
|
|
|
|
|
|
expect_read_access = (user, project_id, callback) ->
|
|
|
|
async.series [
|
|
|
|
(cb) ->
|
|
|
|
try_read_access(user, project_id, (response, body) ->
|
|
|
|
expect(response.statusCode).to.be.oneOf [200, 204]
|
|
|
|
, cb)
|
|
|
|
(cb) ->
|
|
|
|
try_content_access(user, project_id, (response, body) ->
|
|
|
|
expect(body.privilegeLevel).to.be.oneOf ["owner", "readAndWrite", "readOnly"]
|
|
|
|
, cb)
|
|
|
|
], callback
|
|
|
|
|
|
|
|
expect_content_write_access = (user, project_id, callback) ->
|
|
|
|
try_content_access(user, project_id, (response, body) ->
|
|
|
|
expect(body.privilegeLevel).to.be.oneOf ["owner", "readAndWrite"]
|
2016-03-09 12:31:46 +00:00
|
|
|
, callback)
|
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_settings_write_access = (user, project_id, callback) ->
|
|
|
|
try_settings_write_access(user, project_id, (response, body) ->
|
2016-03-09 12:31:46 +00:00
|
|
|
expect(response.statusCode).to.be.oneOf [200, 204]
|
|
|
|
, callback)
|
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_admin_access = (user, project_id, callback) ->
|
|
|
|
try_admin_access(user, project_id, (response, body) ->
|
2016-03-09 12:31:46 +00:00
|
|
|
expect(response.statusCode).to.be.oneOf [200, 204]
|
|
|
|
, callback)
|
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_read_access = (user, project_id, options, callback) ->
|
|
|
|
async.series [
|
|
|
|
(cb) ->
|
|
|
|
try_read_access(user, project_id, (response, body) ->
|
|
|
|
expect(response.statusCode).to.equal 302
|
|
|
|
expect(response.headers.location).to.match new RegExp(options.redirect_to)
|
|
|
|
, cb)
|
|
|
|
(cb) ->
|
|
|
|
try_content_access(user, project_id, (response, body) ->
|
|
|
|
expect(body.privilegeLevel).to.be.equal false
|
|
|
|
, cb)
|
|
|
|
], callback
|
|
|
|
|
|
|
|
expect_no_content_write_access = (user, project_id, callback) ->
|
|
|
|
try_content_access(user, project_id, (response, body) ->
|
|
|
|
expect(body.privilegeLevel).to.be.oneOf [false, "readOnly"]
|
2016-03-09 12:31:46 +00:00
|
|
|
, callback)
|
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_settings_write_access = (user, project_id, options, callback) ->
|
|
|
|
try_settings_write_access(user, project_id, (response, body) ->
|
2016-03-09 12:31:46 +00:00
|
|
|
expect(response.statusCode).to.equal 302
|
2016-03-09 16:26:18 +00:00
|
|
|
expect(response.headers.location).to.match new RegExp(options.redirect_to)
|
2016-03-09 12:31:46 +00:00
|
|
|
, callback)
|
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_admin_access = (user, project_id, options, callback) ->
|
|
|
|
try_admin_access(user, project_id, (response, body) ->
|
2016-03-09 12:31:46 +00:00
|
|
|
expect(response.statusCode).to.equal 302
|
2016-03-09 16:26:18 +00:00
|
|
|
expect(response.headers.location).to.match new RegExp(options.redirect_to)
|
2016-03-09 12:31:46 +00:00
|
|
|
, callback)
|
|
|
|
|
2016-03-08 15:59:04 +00:00
|
|
|
describe "Authorization", ->
|
2016-03-09 12:31:46 +00:00
|
|
|
before (done) ->
|
2016-09-22 10:33:54 +00:00
|
|
|
@timeout(90000)
|
2016-03-09 12:31:46 +00:00
|
|
|
@owner = new User()
|
|
|
|
@other1 = new User()
|
|
|
|
@other2 = new User()
|
|
|
|
@anon = new User()
|
2016-03-21 17:03:31 +00:00
|
|
|
@site_admin = new User({email: "admin@example.com"})
|
|
|
|
async.parallel [
|
2016-03-09 12:31:46 +00:00
|
|
|
(cb) => @owner.login cb
|
|
|
|
(cb) => @other1.login cb
|
|
|
|
(cb) => @other2.login cb
|
|
|
|
(cb) => @anon.getCsrfToken cb
|
2016-03-21 17:03:31 +00:00
|
|
|
(cb) =>
|
|
|
|
@site_admin.login (err) =>
|
|
|
|
return cb(err) if error?
|
|
|
|
@site_admin.ensure_admin cb
|
2016-03-09 12:31:46 +00:00
|
|
|
], done
|
|
|
|
|
2016-03-08 15:59:04 +00:00
|
|
|
describe "private project", ->
|
|
|
|
before (done) ->
|
2016-03-09 12:31:46 +00:00
|
|
|
@owner.createProject "private-project", (error, project_id) =>
|
|
|
|
return done(error) if error?
|
|
|
|
@project_id = project_id
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should allow the owner read access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_read_access @owner, @project_id, done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
2016-03-21 17:03:31 +00:00
|
|
|
it "should allow the owner write access to its content", (done) ->
|
|
|
|
expect_content_write_access @owner, @project_id, done
|
|
|
|
|
2016-03-09 15:30:23 +00:00
|
|
|
it "should allow the owner write access to its settings", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_settings_write_access @owner, @project_id, done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
|
|
|
it "should allow the owner admin access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_admin_access @owner, @project_id, done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
it "should not allow another user read access to the project", (done) ->
|
|
|
|
expect_no_read_access @other1, @project_id, redirect_to: "/restricted", done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
2016-03-21 17:03:31 +00:00
|
|
|
it "should not allow another user write access to its content", (done) ->
|
|
|
|
expect_no_content_write_access @other1, @project_id, done
|
|
|
|
|
2016-03-09 15:30:23 +00:00
|
|
|
it "should not allow another user write access to its settings", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_settings_write_access @other1, @project_id, redirect_to: "/restricted", done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
|
|
|
it "should not allow another user admin access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_admin_access @other1, @project_id, redirect_to: "/restricted", done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
|
|
|
it "should not allow anonymous user read access to it", (done) ->
|
2016-03-14 17:06:57 +00:00
|
|
|
expect_no_read_access @anon, @project_id, redirect_to: "/restricted", done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
2016-03-21 17:03:31 +00:00
|
|
|
it "should not allow anonymous user write access to its content", (done) ->
|
|
|
|
expect_no_content_write_access @anon, @project_id, done
|
|
|
|
|
2016-03-09 15:30:23 +00:00
|
|
|
it "should not allow anonymous user write access to its settings", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_settings_write_access @anon, @project_id, redirect_to: "/restricted", done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
2016-03-09 15:30:23 +00:00
|
|
|
it "should not allow anonymous user admin access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_admin_access @anon, @project_id, redirect_to: "/restricted", done
|
2016-03-21 17:03:31 +00:00
|
|
|
|
|
|
|
it "should allow site admin users read access to it", (done) ->
|
|
|
|
expect_read_access @site_admin, @project_id, done
|
|
|
|
|
|
|
|
it "should allow site admin users write access to its content", (done) ->
|
|
|
|
expect_content_write_access @site_admin, @project_id, done
|
|
|
|
|
|
|
|
it "should allow site admin users write access to its settings", (done) ->
|
|
|
|
expect_settings_write_access @site_admin, @project_id, done
|
|
|
|
|
|
|
|
it "should allow site admin users admin access to it", (done) ->
|
|
|
|
expect_admin_access @site_admin, @project_id, done
|
|
|
|
|
2016-03-09 12:31:46 +00:00
|
|
|
|
|
|
|
describe "shared project", ->
|
|
|
|
before (done) ->
|
|
|
|
@rw_user = @other1
|
|
|
|
@ro_user = @other2
|
|
|
|
@owner.createProject "private-project", (error, project_id) =>
|
2016-03-08 15:59:04 +00:00
|
|
|
return done(error) if error?
|
2016-03-09 12:31:46 +00:00
|
|
|
@project_id = project_id
|
2017-09-21 10:43:16 +00:00
|
|
|
@owner.addUserToProject @project_id, @ro_user, "readOnly", (error) =>
|
2016-03-08 15:59:04 +00:00
|
|
|
return done(error) if error?
|
2017-09-21 10:43:16 +00:00
|
|
|
@owner.addUserToProject @project_id, @rw_user, "readAndWrite", (error) =>
|
2016-03-08 15:59:04 +00:00
|
|
|
return done(error) if error?
|
|
|
|
done()
|
2016-03-09 12:31:46 +00:00
|
|
|
|
|
|
|
it "should allow the read-only user read access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_read_access @ro_user, @project_id, done
|
|
|
|
|
|
|
|
it "should not allow the read-only user write access to its content", (done) ->
|
|
|
|
expect_no_content_write_access @ro_user, @project_id, done
|
2016-03-08 15:59:04 +00:00
|
|
|
|
2016-03-09 15:30:23 +00:00
|
|
|
it "should not allow the read-only user write access to its settings", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_settings_write_access @ro_user, @project_id, redirect_to: "/restricted", done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
|
|
|
it "should not allow the read-only user admin access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_admin_access @ro_user, @project_id, redirect_to: "/restricted", done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
|
|
|
it "should allow the read-write user read access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_read_access @rw_user, @project_id, done
|
|
|
|
|
|
|
|
it "should allow the read-write user write access to its content", (done) ->
|
|
|
|
expect_content_write_access @rw_user, @project_id, done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
2016-03-09 15:30:23 +00:00
|
|
|
it "should allow the read-write user write access to its settings", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_settings_write_access @rw_user, @project_id, done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
|
|
|
it "should not allow the read-write user admin access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_admin_access @rw_user, @project_id, redirect_to: "/restricted", done
|
2016-03-09 15:30:23 +00:00
|
|
|
|
|
|
|
describe "public read-write project", ->
|
|
|
|
before (done) ->
|
|
|
|
@owner.createProject "public-rw-project", (error, project_id) =>
|
|
|
|
return done(error) if error?
|
|
|
|
@project_id = project_id
|
|
|
|
@owner.makePublic @project_id, "readAndWrite", done
|
|
|
|
|
|
|
|
it "should allow a user read access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_read_access @other1, @project_id, done
|
|
|
|
|
|
|
|
it "should allow a user write access to its content", (done) ->
|
2016-03-09 16:28:46 +00:00
|
|
|
expect_content_write_access @other1, @project_id, done
|
2016-03-09 15:30:23 +00:00
|
|
|
|
2016-03-18 12:23:13 +00:00
|
|
|
it "should not allow a user write access to its settings", (done) ->
|
|
|
|
expect_no_settings_write_access @other1, @project_id, redirect_to: "/restricted", done
|
2016-03-09 15:30:23 +00:00
|
|
|
|
|
|
|
it "should not allow a user admin access to it", (done) ->
|
2016-03-09 16:26:18 +00:00
|
|
|
expect_no_admin_access @other1, @project_id, redirect_to: "/restricted", done
|
2016-03-09 12:31:46 +00:00
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
it "should allow an anonymous user read access to it", (done) ->
|
|
|
|
expect_read_access @anon, @project_id, done
|
2016-03-09 15:30:23 +00:00
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
it "should allow an anonymous user write access to its content", (done) ->
|
2016-03-09 16:28:46 +00:00
|
|
|
expect_content_write_access @anon, @project_id, done
|
2016-03-09 15:30:23 +00:00
|
|
|
|
2016-03-09 16:26:18 +00:00
|
|
|
it "should not allow an anonymous user write access to its settings", (done) ->
|
|
|
|
expect_no_settings_write_access @anon, @project_id, redirect_to: "/restricted", done
|
|
|
|
|
|
|
|
it "should not allow an anonymous user admin access to it", (done) ->
|
|
|
|
expect_no_admin_access @anon, @project_id, redirect_to: "/restricted", done
|
2016-03-09 16:28:46 +00:00
|
|
|
|
|
|
|
describe "public read-only project", ->
|
|
|
|
before (done) ->
|
|
|
|
@owner.createProject "public-ro-project", (error, project_id) =>
|
|
|
|
return done(error) if error?
|
|
|
|
@project_id = project_id
|
|
|
|
@owner.makePublic @project_id, "readOnly", done
|
|
|
|
|
|
|
|
it "should allow a user read access to it", (done) ->
|
|
|
|
expect_read_access @other1, @project_id, done
|
|
|
|
|
|
|
|
it "should not allow a user write access to its content", (done) ->
|
|
|
|
expect_no_content_write_access @other1, @project_id, done
|
|
|
|
|
2016-03-18 12:23:13 +00:00
|
|
|
it "should not allow a user write access to its settings", (done) ->
|
|
|
|
expect_no_settings_write_access @other1, @project_id, redirect_to: "/restricted", done
|
2016-03-09 16:28:46 +00:00
|
|
|
|
|
|
|
it "should not allow a user admin access to it", (done) ->
|
|
|
|
expect_no_admin_access @other1, @project_id, redirect_to: "/restricted", done
|
|
|
|
|
|
|
|
it "should allow an anonymous user read access to it", (done) ->
|
|
|
|
expect_read_access @anon, @project_id, done
|
|
|
|
|
|
|
|
it "should not allow an anonymous user write access to its content", (done) ->
|
|
|
|
expect_no_content_write_access @anon, @project_id, done
|
|
|
|
|
|
|
|
it "should not allow an anonymous user write access to its settings", (done) ->
|
|
|
|
expect_no_settings_write_access @anon, @project_id, redirect_to: "/restricted", done
|
|
|
|
|
|
|
|
it "should not allow an anonymous user admin access to it", (done) ->
|
2017-09-21 10:43:16 +00:00
|
|
|
expect_no_admin_access @anon, @project_id, redirect_to: "/restricted", done
|