| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- /* eslint-disable
- no-return-assign,
- no-unused-vars,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- const { expect } = require('chai')
- const sinon = require('sinon')
- const SandboxedModule = require('sandboxed-module')
- const path = require('path')
- const modulePath = '../../../app/js/AuthorizationManager'
- describe('AuthorizationManager', function () {
- beforeEach(function () {
- this.client = { ol_context: {} }
- return (this.AuthorizationManager = SandboxedModule.require(modulePath, {
- requires: {}
- }))
- })
- describe('assertClientCanViewProject', function () {
- it('should allow the readOnly privilegeLevel', function (done) {
- this.client.ol_context.privilege_level = 'readOnly'
- return this.AuthorizationManager.assertClientCanViewProject(
- this.client,
- (error) => {
- expect(error).to.be.null
- return done()
- }
- )
- })
- it('should allow the readAndWrite privilegeLevel', function (done) {
- this.client.ol_context.privilege_level = 'readAndWrite'
- return this.AuthorizationManager.assertClientCanViewProject(
- this.client,
- (error) => {
- expect(error).to.be.null
- return done()
- }
- )
- })
- it('should allow the owner privilegeLevel', function (done) {
- this.client.ol_context.privilege_level = 'owner'
- return this.AuthorizationManager.assertClientCanViewProject(
- this.client,
- (error) => {
- expect(error).to.be.null
- return done()
- }
- )
- })
- return it('should return an error with any other privilegeLevel', function (done) {
- this.client.ol_context.privilege_level = 'unknown'
- return this.AuthorizationManager.assertClientCanViewProject(
- this.client,
- (error) => {
- error.message.should.equal('not authorized')
- return done()
- }
- )
- })
- })
- describe('assertClientCanEditProject', function () {
- it('should not allow the readOnly privilegeLevel', function (done) {
- this.client.ol_context.privilege_level = 'readOnly'
- return this.AuthorizationManager.assertClientCanEditProject(
- this.client,
- (error) => {
- error.message.should.equal('not authorized')
- return done()
- }
- )
- })
- it('should allow the readAndWrite privilegeLevel', function (done) {
- this.client.ol_context.privilege_level = 'readAndWrite'
- return this.AuthorizationManager.assertClientCanEditProject(
- this.client,
- (error) => {
- expect(error).to.be.null
- return done()
- }
- )
- })
- it('should allow the owner privilegeLevel', function (done) {
- this.client.ol_context.privilege_level = 'owner'
- return this.AuthorizationManager.assertClientCanEditProject(
- this.client,
- (error) => {
- expect(error).to.be.null
- return done()
- }
- )
- })
- return it('should return an error with any other privilegeLevel', function (done) {
- this.client.ol_context.privilege_level = 'unknown'
- return this.AuthorizationManager.assertClientCanEditProject(
- this.client,
- (error) => {
- error.message.should.equal('not authorized')
- return done()
- }
- )
- })
- })
- // check doc access for project
- describe('assertClientCanViewProjectAndDoc', function () {
- beforeEach(function () {
- this.doc_id = '12345'
- this.callback = sinon.stub()
- return (this.client.ol_context = {})
- })
- describe('when not authorised at the project level', function () {
- beforeEach(function () {
- return (this.client.ol_context.privilege_level = 'unknown')
- })
- it('should not allow access', function () {
- return this.AuthorizationManager.assertClientCanViewProjectAndDoc(
- this.client,
- this.doc_id,
- (err) => err.message.should.equal('not authorized')
- )
- })
- return describe('even when authorised at the doc level', function () {
- beforeEach(function (done) {
- return this.AuthorizationManager.addAccessToDoc(
- this.client,
- this.doc_id,
- done
- )
- })
- return it('should not allow access', function () {
- return this.AuthorizationManager.assertClientCanViewProjectAndDoc(
- this.client,
- this.doc_id,
- (err) => err.message.should.equal('not authorized')
- )
- })
- })
- })
- return describe('when authorised at the project level', function () {
- beforeEach(function () {
- return (this.client.ol_context.privilege_level = 'readOnly')
- })
- describe('and not authorised at the document level', function () {
- return it('should not allow access', function () {
- return this.AuthorizationManager.assertClientCanViewProjectAndDoc(
- this.client,
- this.doc_id,
- (err) => err.message.should.equal('not authorized')
- )
- })
- })
- describe('and authorised at the document level', function () {
- beforeEach(function (done) {
- return this.AuthorizationManager.addAccessToDoc(
- this.client,
- this.doc_id,
- done
- )
- })
- return it('should allow access', function () {
- this.AuthorizationManager.assertClientCanViewProjectAndDoc(
- this.client,
- this.doc_id,
- this.callback
- )
- return this.callback.calledWith(null).should.equal(true)
- })
- })
- return describe('when document authorisation is added and then removed', function () {
- beforeEach(function (done) {
- return this.AuthorizationManager.addAccessToDoc(
- this.client,
- this.doc_id,
- () => {
- return this.AuthorizationManager.removeAccessToDoc(
- this.client,
- this.doc_id,
- done
- )
- }
- )
- })
- return it('should deny access', function () {
- return this.AuthorizationManager.assertClientCanViewProjectAndDoc(
- this.client,
- this.doc_id,
- (err) => err.message.should.equal('not authorized')
- )
- })
- })
- })
- })
- return describe('assertClientCanEditProjectAndDoc', function () {
- beforeEach(function () {
- this.doc_id = '12345'
- this.callback = sinon.stub()
- return (this.client.ol_context = {})
- })
- describe('when not authorised at the project level', function () {
- beforeEach(function () {
- return (this.client.ol_context.privilege_level = 'readOnly')
- })
- it('should not allow access', function () {
- return this.AuthorizationManager.assertClientCanEditProjectAndDoc(
- this.client,
- this.doc_id,
- (err) => err.message.should.equal('not authorized')
- )
- })
- return describe('even when authorised at the doc level', function () {
- beforeEach(function (done) {
- return this.AuthorizationManager.addAccessToDoc(
- this.client,
- this.doc_id,
- done
- )
- })
- return it('should not allow access', function () {
- return this.AuthorizationManager.assertClientCanEditProjectAndDoc(
- this.client,
- this.doc_id,
- (err) => err.message.should.equal('not authorized')
- )
- })
- })
- })
- return describe('when authorised at the project level', function () {
- beforeEach(function () {
- return (this.client.ol_context.privilege_level = 'readAndWrite')
- })
- describe('and not authorised at the document level', function () {
- return it('should not allow access', function () {
- return this.AuthorizationManager.assertClientCanEditProjectAndDoc(
- this.client,
- this.doc_id,
- (err) => err.message.should.equal('not authorized')
- )
- })
- })
- describe('and authorised at the document level', function () {
- beforeEach(function (done) {
- return this.AuthorizationManager.addAccessToDoc(
- this.client,
- this.doc_id,
- done
- )
- })
- return it('should allow access', function () {
- this.AuthorizationManager.assertClientCanEditProjectAndDoc(
- this.client,
- this.doc_id,
- this.callback
- )
- return this.callback.calledWith(null).should.equal(true)
- })
- })
- return describe('when document authorisation is added and then removed', function () {
- beforeEach(function (done) {
- return this.AuthorizationManager.addAccessToDoc(
- this.client,
- this.doc_id,
- () => {
- return this.AuthorizationManager.removeAccessToDoc(
- this.client,
- this.doc_id,
- done
- )
- }
- )
- })
- return it('should deny access', function () {
- return this.AuthorizationManager.assertClientCanEditProjectAndDoc(
- this.client,
- this.doc_id,
- (err) => err.message.should.equal('not authorized')
- )
- })
- })
- })
- })
- })
|