2019-05-29 05:21:06 -04:00
|
|
|
const { expect } = require('chai')
|
|
|
|
const async = require('async')
|
|
|
|
const User = require('./helpers/User')
|
|
|
|
const request = require('./helpers/request')
|
|
|
|
const settings = require('settings-sharelatex')
|
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
require('./helpers/MockDocstoreApi')
|
|
|
|
require('./helpers/MockDocUpdaterApi')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function tryReadAccess(user, projectId, test, callback) {
|
2019-05-29 05:21:06 -04:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
cb =>
|
2019-09-30 09:21:49 -04:00
|
|
|
user.request.get(`/project/${projectId}`, (error, response, body) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (error != null) {
|
|
|
|
return cb(error)
|
|
|
|
}
|
|
|
|
test(response, body)
|
2019-09-30 09:21:49 -04:00
|
|
|
cb()
|
2019-05-29 05:21:06 -04:00
|
|
|
}),
|
|
|
|
cb =>
|
2019-08-07 10:04:04 -04:00
|
|
|
user.request.get(
|
2019-09-30 09:21:49 -04:00
|
|
|
`/project/${projectId}/download/zip`,
|
2019-08-07 10:04:04 -04:00
|
|
|
(error, response, body) => {
|
|
|
|
if (error != null) {
|
|
|
|
return cb(error)
|
|
|
|
}
|
|
|
|
test(response, body)
|
2019-09-30 09:21:49 -04:00
|
|
|
cb()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
],
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function trySettingsWriteAccess(user, projectId, test, callback) {
|
2019-05-29 05:21:06 -04:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
cb =>
|
|
|
|
user.request.post(
|
|
|
|
{
|
2019-09-30 09:21:49 -04:00
|
|
|
uri: `/project/${projectId}/settings`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
|
|
|
compiler: 'latex'
|
|
|
|
}
|
|
|
|
},
|
2019-08-07 10:04:04 -04:00
|
|
|
(error, response, body) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (error != null) {
|
|
|
|
return cb(error)
|
|
|
|
}
|
|
|
|
test(response, body)
|
2019-09-30 09:21:49 -04:00
|
|
|
cb()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
],
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function tryAdminAccess(user, projectId, test, callback) {
|
2019-05-29 05:21:06 -04:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
cb =>
|
|
|
|
user.request.post(
|
|
|
|
{
|
2019-09-30 09:21:49 -04:00
|
|
|
uri: `/project/${projectId}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
|
|
|
newProjectName: 'new-name'
|
|
|
|
}
|
|
|
|
},
|
2019-08-07 10:04:04 -04:00
|
|
|
(error, response, body) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (error != null) {
|
|
|
|
return cb(error)
|
|
|
|
}
|
|
|
|
test(response, body)
|
2019-09-30 09:21:49 -04:00
|
|
|
cb()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
),
|
|
|
|
cb =>
|
|
|
|
user.request.post(
|
|
|
|
{
|
2019-09-30 09:21:49 -04:00
|
|
|
uri: `/project/${projectId}/settings/admin`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
|
|
|
publicAccessLevel: 'private'
|
|
|
|
}
|
|
|
|
},
|
2019-08-07 10:04:04 -04:00
|
|
|
(error, response, body) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (error != null) {
|
|
|
|
return cb(error)
|
|
|
|
}
|
|
|
|
test(response, body)
|
2019-09-30 09:21:49 -04:00
|
|
|
cb()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
],
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function tryContentAccess(user, projectId, test, callback) {
|
2019-05-29 05:21:06 -04:00
|
|
|
// The real-time service calls this end point to determine the user's
|
|
|
|
// permissions.
|
2019-09-30 09:21:49 -04:00
|
|
|
let userId
|
2019-05-29 05:21:06 -04:00
|
|
|
if (user.id != null) {
|
2019-09-30 09:21:49 -04:00
|
|
|
userId = user.id
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
2019-09-30 09:21:49 -04:00
|
|
|
userId = 'anonymous-user'
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 09:21:49 -04:00
|
|
|
request.post(
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
2019-09-30 09:21:49 -04:00
|
|
|
url: `/project/${projectId}/join`,
|
|
|
|
qs: { user_id: userId },
|
2019-05-29 05:21:06 -04:00
|
|
|
auth: {
|
|
|
|
user: settings.apis.web.user,
|
|
|
|
pass: settings.apis.web.pass,
|
|
|
|
sendImmediately: true
|
|
|
|
},
|
|
|
|
json: true,
|
|
|
|
jar: false
|
|
|
|
},
|
2019-08-07 10:04:04 -04:00
|
|
|
(error, response, body) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
test(response, body)
|
2019-09-30 09:21:49 -04:00
|
|
|
callback()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function expectReadAccess(user, projectId, callback) {
|
2019-05-29 05:21:06 -04:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
cb =>
|
2019-09-30 09:21:49 -04:00
|
|
|
tryReadAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
(response, body) =>
|
|
|
|
expect(response.statusCode).to.be.oneOf([200, 204]),
|
|
|
|
cb
|
|
|
|
),
|
|
|
|
cb =>
|
2019-09-30 09:21:49 -04:00
|
|
|
tryContentAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
(response, body) =>
|
|
|
|
expect(body.privilegeLevel).to.be.oneOf([
|
|
|
|
'owner',
|
|
|
|
'readAndWrite',
|
|
|
|
'readOnly'
|
|
|
|
]),
|
|
|
|
cb
|
|
|
|
)
|
|
|
|
],
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function expectContentWriteAccess(user, projectId, callback) {
|
|
|
|
tryContentAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
(response, body) =>
|
|
|
|
expect(body.privilegeLevel).to.be.oneOf(['owner', 'readAndWrite']),
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function expectSettingsWriteAccess(user, projectId, callback) {
|
|
|
|
trySettingsWriteAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
(response, body) => expect(response.statusCode).to.be.oneOf([200, 204]),
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function expectAdminAccess(user, projectId, callback) {
|
|
|
|
tryAdminAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
(response, body) => expect(response.statusCode).to.be.oneOf([200, 204]),
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function expectNoReadAccess(user, projectId, options, callback) {
|
2019-05-29 05:21:06 -04:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
cb =>
|
2019-09-30 09:21:49 -04:00
|
|
|
tryReadAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
2019-08-07 10:04:04 -04:00
|
|
|
(response, body) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(response.statusCode).to.equal(302)
|
2019-09-30 09:21:49 -04:00
|
|
|
expect(response.headers.location).to.match(
|
2019-05-29 05:21:06 -04:00
|
|
|
new RegExp(options.redirect_to)
|
|
|
|
)
|
|
|
|
},
|
|
|
|
cb
|
|
|
|
),
|
|
|
|
cb =>
|
2019-09-30 09:21:49 -04:00
|
|
|
tryContentAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
(response, body) => expect(body.privilegeLevel).to.be.equal(false),
|
|
|
|
cb
|
|
|
|
)
|
|
|
|
],
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function expectNoContentWriteAccess(user, projectId, callback) {
|
|
|
|
tryContentAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
(response, body) =>
|
|
|
|
expect(body.privilegeLevel).to.be.oneOf([false, 'readOnly']),
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function expectNoSettingsWriteAccess(user, projectId, options, callback) {
|
|
|
|
trySettingsWriteAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
2019-08-07 10:04:04 -04:00
|
|
|
(response, body) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(response.statusCode).to.equal(302)
|
2019-09-30 09:21:49 -04:00
|
|
|
expect(response.headers.location).to.match(
|
2019-05-29 05:21:06 -04:00
|
|
|
new RegExp(options.redirect_to)
|
|
|
|
)
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 09:21:49 -04:00
|
|
|
function expectNoAdminAccess(user, projectId, callback) {
|
|
|
|
tryAdminAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
user,
|
2019-09-30 09:21:49 -04:00
|
|
|
projectId,
|
|
|
|
(response, body) => {
|
|
|
|
expect(response.statusCode).to.equal(403)
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectNoAnonymousAdminAccess(user, projectId, callback) {
|
|
|
|
tryAdminAccess(
|
|
|
|
user,
|
|
|
|
projectId,
|
2019-08-07 10:04:04 -04:00
|
|
|
(response, body) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(response.statusCode).to.equal(302)
|
2019-09-30 09:21:49 -04:00
|
|
|
expect(response.headers.location).to.match(/^\/login/)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
2019-09-30 09:21:49 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
describe('Authorization', function() {
|
2019-08-06 08:20:31 -04:00
|
|
|
beforeEach(function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.timeout(90000)
|
|
|
|
this.owner = new User()
|
|
|
|
this.other1 = new User()
|
|
|
|
this.other2 = new User()
|
|
|
|
this.anon = new User()
|
|
|
|
this.site_admin = new User({ email: 'admin@example.com' })
|
2019-09-30 09:21:49 -04:00
|
|
|
async.parallel(
|
2019-05-29 05:21:06 -04:00
|
|
|
[
|
|
|
|
cb => this.owner.login(cb),
|
|
|
|
cb => this.other1.login(cb),
|
|
|
|
cb => this.other2.login(cb),
|
|
|
|
cb => this.anon.getCsrfToken(cb),
|
|
|
|
cb => {
|
2019-09-30 09:21:49 -04:00
|
|
|
this.site_admin.login(err => {
|
|
|
|
if (err != null) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return cb(err)
|
|
|
|
}
|
2019-09-30 09:21:49 -04:00
|
|
|
this.site_admin.ensure_admin(cb)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
],
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('private project', function() {
|
2019-08-06 08:20:31 -04:00
|
|
|
beforeEach(function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
this.owner.createProject('private-project', (error, projectId) => {
|
|
|
|
if (error != null) {
|
|
|
|
return done(error)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId = projectId
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow the owner read access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectReadAccess(this.owner, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow the owner write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectContentWriteAccess(this.owner, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow the owner write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectSettingsWriteAccess(this.owner, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow the owner admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectAdminAccess(this.owner, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow another user read access to the project', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoReadAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.other1,
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{ redirect_to: '/restricted' },
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow another user write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoContentWriteAccess(this.other1, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow another user write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoSettingsWriteAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.other1,
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{ redirect_to: '/restricted' },
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow another user admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoAdminAccess(this.other1, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow anonymous user read access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoReadAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.anon,
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{ redirect_to: '/restricted' },
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow anonymous user write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoContentWriteAccess(this.anon, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow anonymous user write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoSettingsWriteAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.anon,
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{ redirect_to: '/restricted' },
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow anonymous user admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoAnonymousAdminAccess(this.anon, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow site admin users read access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectReadAccess(this.site_admin, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow site admin users write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectContentWriteAccess(this.site_admin, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow site admin users write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectSettingsWriteAccess(this.site_admin, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should allow site admin users admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectAdminAccess(this.site_admin, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('shared project', function() {
|
2019-08-06 08:20:31 -04:00
|
|
|
beforeEach(function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.rw_user = this.other1
|
|
|
|
this.ro_user = this.other2
|
2019-09-30 09:21:49 -04:00
|
|
|
this.owner.createProject('private-project', (error, projectId) => {
|
|
|
|
if (error != null) {
|
|
|
|
return done(error)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId = projectId
|
|
|
|
this.owner.addUserToProject(
|
|
|
|
this.projectId,
|
|
|
|
this.ro_user,
|
|
|
|
'readOnly',
|
|
|
|
error => {
|
|
|
|
if (error != null) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
this.owner.addUserToProject(
|
|
|
|
this.projectId,
|
|
|
|
this.rw_user,
|
|
|
|
'readAndWrite',
|
|
|
|
error => {
|
|
|
|
if (error != null) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow the read-only user read access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectReadAccess(this.ro_user, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow the read-only user write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoContentWriteAccess(this.ro_user, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow the read-only user write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoSettingsWriteAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.ro_user,
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{ redirect_to: '/restricted' },
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow the read-only user admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoAdminAccess(this.ro_user, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow the read-write user read access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectReadAccess(this.rw_user, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow the read-write user write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectContentWriteAccess(this.rw_user, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow the read-write user write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectSettingsWriteAccess(this.rw_user, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should not allow the read-write user admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoAdminAccess(this.rw_user, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('public read-write project', function() {
|
2019-08-06 08:20:31 -04:00
|
|
|
beforeEach(function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
this.owner.createProject('public-rw-project', (error, projectId) => {
|
|
|
|
if (error != null) {
|
|
|
|
return done(error)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId = projectId
|
|
|
|
this.owner.makePublic(this.projectId, 'readAndWrite', done)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow a user read access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectReadAccess(this.other1, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow a user write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectContentWriteAccess(this.other1, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow a user write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoSettingsWriteAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.other1,
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{ redirect_to: '/restricted' },
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow a user admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoAdminAccess(this.other1, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow an anonymous user read access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectReadAccess(this.anon, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow an anonymous user write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectContentWriteAccess(this.anon, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow an anonymous user write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoSettingsWriteAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.anon,
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{ redirect_to: '/restricted' },
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should not allow an anonymous user admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoAnonymousAdminAccess(this.anon, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('public read-only project', function() {
|
2019-08-06 08:20:31 -04:00
|
|
|
beforeEach(function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
this.owner.createProject('public-ro-project', (error, projectId) => {
|
|
|
|
if (error != null) {
|
|
|
|
return done(error)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId = projectId
|
|
|
|
this.owner.makePublic(this.projectId, 'readOnly', done)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow a user read access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectReadAccess(this.other1, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow a user write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoContentWriteAccess(this.other1, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow a user write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoSettingsWriteAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.other1,
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{ redirect_to: '/restricted' },
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow a user admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoAdminAccess(this.other1, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow an anonymous user read access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectReadAccess(this.anon, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow an anonymous user write access to its content', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoContentWriteAccess(this.anon, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not allow an anonymous user write access to its settings', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoSettingsWriteAccess(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.anon,
|
2019-09-30 09:21:49 -04:00
|
|
|
this.projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{ redirect_to: '/restricted' },
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should not allow an anonymous user admin access to it', function(done) {
|
2019-09-30 09:21:49 -04:00
|
|
|
expectNoAnonymousAdminAccess(this.anon, this.projectId, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|