AuthorizationManagerTests.coffee 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. chai = require "chai"
  2. chai.should()
  3. expect = chai.expect
  4. sinon = require("sinon")
  5. SandboxedModule = require('sandboxed-module')
  6. path = require "path"
  7. modulePath = '../../../app/js/AuthorizationManager'
  8. describe 'AuthorizationManager', ->
  9. beforeEach ->
  10. @client =
  11. params: {}
  12. get: (param, cb) -> cb null, @params[param]
  13. @AuthorizationManager = SandboxedModule.require modulePath, requires: {}
  14. describe "assertClientCanViewProject", ->
  15. it "should allow the readOnly privilegeLevel", (done) ->
  16. @client.params.privilege_level = "readOnly"
  17. @AuthorizationManager.assertClientCanViewProject @client, (error) ->
  18. expect(error).to.be.null
  19. done()
  20. it "should allow the readAndWrite privilegeLevel", (done) ->
  21. @client.params.privilege_level = "readAndWrite"
  22. @AuthorizationManager.assertClientCanViewProject @client, (error) ->
  23. expect(error).to.be.null
  24. done()
  25. it "should allow the owner privilegeLevel", (done) ->
  26. @client.params.privilege_level = "owner"
  27. @AuthorizationManager.assertClientCanViewProject @client, (error) ->
  28. expect(error).to.be.null
  29. done()
  30. it "should return an error with any other privilegeLevel", (done) ->
  31. @client.params.privilege_level = "unknown"
  32. @AuthorizationManager.assertClientCanViewProject @client, (error) ->
  33. error.message.should.equal "not authorized"
  34. done()
  35. describe "assertClientCanEditProject", ->
  36. it "should not allow the readOnly privilegeLevel", (done) ->
  37. @client.params.privilege_level = "readOnly"
  38. @AuthorizationManager.assertClientCanEditProject @client, (error) ->
  39. error.message.should.equal "not authorized"
  40. done()
  41. it "should allow the readAndWrite privilegeLevel", (done) ->
  42. @client.params.privilege_level = "readAndWrite"
  43. @AuthorizationManager.assertClientCanEditProject @client, (error) ->
  44. expect(error).to.be.null
  45. done()
  46. it "should allow the owner privilegeLevel", (done) ->
  47. @client.params.privilege_level = "owner"
  48. @AuthorizationManager.assertClientCanEditProject @client, (error) ->
  49. expect(error).to.be.null
  50. done()
  51. it "should return an error with any other privilegeLevel", (done) ->
  52. @client.params.privilege_level = "unknown"
  53. @AuthorizationManager.assertClientCanEditProject @client, (error) ->
  54. error.message.should.equal "not authorized"
  55. done()