|
|
@@ -10,7 +10,15 @@ describe 'AuthorizationManager', ->
|
|
|
beforeEach ->
|
|
|
@client =
|
|
|
params: {}
|
|
|
- get: (param, cb) -> cb null, @params[param]
|
|
|
+ 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", ->
|
|
|
@@ -61,4 +69,122 @@ describe 'AuthorizationManager', ->
|
|
|
@client.params.privilege_level = "unknown"
|
|
|
@AuthorizationManager.assertClientCanEditProject @client, (error) ->
|
|
|
error.message.should.equal "not authorized"
|
|
|
- done()
|
|
|
+ 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
|