|
|
@@ -3,7 +3,7 @@ const { expect } = require('chai')
|
|
|
const User = require('./helpers/User').promises
|
|
|
|
|
|
describe('AdminPrivilegeAvailable', function () {
|
|
|
- let adminUser
|
|
|
+ let adminUser, otherUser
|
|
|
const flagBefore = Settings.adminPrivilegeAvailable
|
|
|
after(function () {
|
|
|
Settings.adminPrivilegeAvailable = flagBefore
|
|
|
@@ -16,16 +16,21 @@ describe('AdminPrivilegeAvailable', function () {
|
|
|
await adminUser.login()
|
|
|
})
|
|
|
|
|
|
- let projectIdOwned, otherUsersProjectId
|
|
|
+ let projectIdOwned, otherUsersProjectId, otherUsersProjectTokenAccessURL
|
|
|
beforeEach('create owned project', async function () {
|
|
|
projectIdOwned = await adminUser.createProject('owned project')
|
|
|
})
|
|
|
|
|
|
beforeEach('create other user and project', async function () {
|
|
|
- const otherUser = new User()
|
|
|
+ otherUser = new User()
|
|
|
await otherUser.login()
|
|
|
|
|
|
otherUsersProjectId = await otherUser.createProject('other users project')
|
|
|
+ await otherUser.makeTokenBased(otherUsersProjectId)
|
|
|
+ const {
|
|
|
+ tokens: { readOnly: readOnlyToken },
|
|
|
+ } = await otherUser.getProject(otherUsersProjectId)
|
|
|
+ otherUsersProjectTokenAccessURL = `/read/${readOnlyToken}`
|
|
|
})
|
|
|
|
|
|
async function hasAccess(projectId) {
|
|
|
@@ -36,6 +41,15 @@ describe('AdminPrivilegeAvailable', function () {
|
|
|
return response.statusCode === 200
|
|
|
}
|
|
|
|
|
|
+ async function displayTokenAccessPage(user) {
|
|
|
+ const { response } = await user.doRequest(
|
|
|
+ 'GET',
|
|
|
+ otherUsersProjectTokenAccessURL
|
|
|
+ )
|
|
|
+ expect(response.statusCode).to.equal(200)
|
|
|
+ expect(response.body).to.include(otherUsersProjectTokenAccessURL)
|
|
|
+ }
|
|
|
+
|
|
|
describe('adminPrivilegeAvailable=true', function () {
|
|
|
beforeEach(function () {
|
|
|
Settings.adminPrivilegeAvailable = true
|
|
|
@@ -46,6 +60,12 @@ describe('AdminPrivilegeAvailable', function () {
|
|
|
it('should grant the admin access to non-owned project', async function () {
|
|
|
expect(await hasAccess(otherUsersProjectId)).to.equal(true)
|
|
|
})
|
|
|
+ it('should display token access page for admin', async function () {
|
|
|
+ await displayTokenAccessPage(adminUser)
|
|
|
+ })
|
|
|
+ it('should display token access page for regular user', async function () {
|
|
|
+ await displayTokenAccessPage(otherUser)
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('adminPrivilegeAvailable=false', function () {
|
|
|
@@ -58,5 +78,18 @@ describe('AdminPrivilegeAvailable', function () {
|
|
|
it('should block the admin from non-owned project', async function () {
|
|
|
expect(await hasAccess(otherUsersProjectId)).to.equal(false)
|
|
|
})
|
|
|
+ it('should redirect a token access request to admin panel', async function () {
|
|
|
+ const { response } = await adminUser.doRequest(
|
|
|
+ 'GET',
|
|
|
+ otherUsersProjectTokenAccessURL
|
|
|
+ )
|
|
|
+ expect(response.statusCode).to.equal(302)
|
|
|
+ expect(response.headers.location).to.equal(
|
|
|
+ Settings.adminUrl + otherUsersProjectTokenAccessURL
|
|
|
+ )
|
|
|
+ })
|
|
|
+ it('should display token access page for regular user', async function () {
|
|
|
+ await displayTokenAccessPage(otherUser)
|
|
|
+ })
|
|
|
})
|
|
|
})
|