| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- chai = require "chai"
- chai.should()
- expect = chai.expect
- sinon = require("sinon")
- SandboxedModule = require('sandboxed-module')
- path = require "path"
- modulePath = '../../../app/js/AuthorizationManager'
- describe 'AuthorizationManager', ->
- beforeEach ->
- @client =
- params: {}
- get: (param, cb) ->
- cb null, @params[param]
- set: (param, value, cb) ->
- @params[param] = value
- cb()
- del: (param, cb) ->
- delete @params[param]
- cb()
- @AuthorizationManager = SandboxedModule.require modulePath, requires: {}
- describe "assertClientCanViewProject", ->
- it "should allow the readOnly privilegeLevel", (done) ->
- @client.params.privilege_level = "readOnly"
- @AuthorizationManager.assertClientCanViewProject @client, (error) ->
- expect(error).to.be.null
- done()
-
- it "should allow the readAndWrite privilegeLevel", (done) ->
- @client.params.privilege_level = "readAndWrite"
- @AuthorizationManager.assertClientCanViewProject @client, (error) ->
- expect(error).to.be.null
- done()
-
- it "should allow the owner privilegeLevel", (done) ->
- @client.params.privilege_level = "owner"
- @AuthorizationManager.assertClientCanViewProject @client, (error) ->
- expect(error).to.be.null
- done()
-
- it "should return an error with any other privilegeLevel", (done) ->
- @client.params.privilege_level = "unknown"
- @AuthorizationManager.assertClientCanViewProject @client, (error) ->
- error.message.should.equal "not authorized"
- done()
- describe "assertClientCanEditProject", ->
- it "should not allow the readOnly privilegeLevel", (done) ->
- @client.params.privilege_level = "readOnly"
- @AuthorizationManager.assertClientCanEditProject @client, (error) ->
- error.message.should.equal "not authorized"
- done()
-
- it "should allow the readAndWrite privilegeLevel", (done) ->
- @client.params.privilege_level = "readAndWrite"
- @AuthorizationManager.assertClientCanEditProject @client, (error) ->
- expect(error).to.be.null
- done()
-
- it "should allow the owner privilegeLevel", (done) ->
- @client.params.privilege_level = "owner"
- @AuthorizationManager.assertClientCanEditProject @client, (error) ->
- expect(error).to.be.null
- done()
-
- it "should return an error with any other privilegeLevel", (done) ->
- @client.params.privilege_level = "unknown"
- @AuthorizationManager.assertClientCanEditProject @client, (error) ->
- error.message.should.equal "not authorized"
- done()
- # check doc access for project
- describe "assertClientCanViewProjectAndDoc", ->
- beforeEach () ->
- @doc_id = "12345"
- @callback = sinon.stub()
- @client.params = {}
- describe "when not authorised at the project level", ->
- beforeEach () ->
- @client.params.privilege_level = "unknown"
- it "should not allow access", () ->
- @AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(new Error("not authorised"))
- .should.equal true
- describe "even when authorised at the doc level", ->
- beforeEach (done) ->
- @AuthorizationManager.addAccessToDoc @client, @doc_id, done
- it "should not allow access", () ->
- @AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(new Error("not authorised"))
- .should.equal true
- describe "when authorised at the project level", ->
- beforeEach () ->
- @client.params.privilege_level = "readOnly"
- describe "and not authorised at the document level", ->
- it "should not allow access", () ->
- @AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(new Error("not authorised"))
- .should.equal true
- describe "and authorised at the document level", ->
- beforeEach (done) ->
- @AuthorizationManager.addAccessToDoc @client, @doc_id, done
- it "should allow access", () ->
- @AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(null)
- .should.equal true
- describe "when document authorisation is added and then removed", ->
- beforeEach (done) ->
- @AuthorizationManager.addAccessToDoc @client, @doc_id, () =>
- @AuthorizationManager.removeAccessToDoc @client, @doc_id, done
- it "should deny access", () ->
- @AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(new Error("not authorised"))
- .should.equal true
- describe "assertClientCanEditProjectAndDoc", ->
- beforeEach () ->
- @doc_id = "12345"
- @callback = sinon.stub()
- @client.params = {}
- describe "when not authorised at the project level", ->
- beforeEach () ->
- @client.params.privilege_level = "readOnly"
- it "should not allow access", () ->
- @AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(new Error("not authorised"))
- .should.equal true
- describe "even when authorised at the doc level", ->
- beforeEach (done) ->
- @AuthorizationManager.addAccessToDoc @client, @doc_id, done
- it "should not allow access", () ->
- @AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(new Error("not authorised"))
- .should.equal true
- describe "when authorised at the project level", ->
- beforeEach () ->
- @client.params.privilege_level = "readAndWrite"
- describe "and not authorised at the document level", ->
- it "should not allow access", () ->
- @AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(new Error("not authorised"))
- .should.equal true
- describe "and authorised at the document level", ->
- beforeEach (done) ->
- @AuthorizationManager.addAccessToDoc @client, @doc_id, done
- it "should allow access", () ->
- @AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(null)
- .should.equal true
- describe "when document authorisation is added and then removed", ->
- beforeEach (done) ->
- @AuthorizationManager.addAccessToDoc @client, @doc_id, () =>
- @AuthorizationManager.removeAccessToDoc @client, @doc_id, done
- it "should deny access", () ->
- @AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback
- @callback
- .calledWith(new Error("not authorised"))
- .should.equal true
|