|
|
@@ -18,6 +18,7 @@ describe "UserMembershipAuthorization", ->
|
|
|
getSessionUser: sinon.stub().returns(@user)
|
|
|
@UserMembershipHandler =
|
|
|
getEntity: sinon.stub().yields(null, @subscription)
|
|
|
+ getEntityWithoutAuthorizationCheck: sinon.stub().yields(null, @subscription)
|
|
|
@AuthorizationMiddlewear =
|
|
|
redirectToRestricted: sinon.stub().yields()
|
|
|
@UserMembershipAuthorization = SandboxedModule.require modulePath, requires:
|
|
|
@@ -45,15 +46,42 @@ describe "UserMembershipAuthorization", ->
|
|
|
expect(@req.entityConfig).to.exist
|
|
|
done()
|
|
|
|
|
|
- it 'handle entity not found', (done) ->
|
|
|
+ it 'handle entity not found as non-admin', (done) ->
|
|
|
@UserMembershipHandler.getEntity.yields(null, null)
|
|
|
+ @UserMembershipHandler.getEntityWithoutAuthorizationCheck.yields(null, null)
|
|
|
@UserMembershipAuthorization.requireGroupAccess @req, null, (error) =>
|
|
|
expect(error).to.extist
|
|
|
- sinon.assert.called(@AuthorizationMiddlewear.redirectToRestricted)
|
|
|
+ expect(error).to.be.instanceof(Error)
|
|
|
+ expect(error.constructor.name).to.equal('NotFoundError')
|
|
|
sinon.assert.called(@UserMembershipHandler.getEntity)
|
|
|
expect(@req.entity).to.not.exist
|
|
|
done()
|
|
|
|
|
|
+ it 'handle entity not found an admin can create', (done) ->
|
|
|
+ @user.isAdmin = true
|
|
|
+ @UserMembershipHandler.getEntity.yields(null, null)
|
|
|
+ @UserMembershipHandler.getEntityWithoutAuthorizationCheck.yields(null, null)
|
|
|
+ @UserMembershipAuthorization.requirePublisherAccess @req, redirect: (path) =>
|
|
|
+ expect(path).to.extist
|
|
|
+ expect(path).to.match /create/
|
|
|
+ done()
|
|
|
+
|
|
|
+ it 'handle entity not found an admin cannot create', (done) ->
|
|
|
+ @user.isAdmin = true
|
|
|
+ @UserMembershipHandler.getEntity.yields(null, null)
|
|
|
+ @UserMembershipHandler.getEntityWithoutAuthorizationCheck.yields(null, null)
|
|
|
+ @UserMembershipAuthorization.requireGroupAccess @req, null, (error) =>
|
|
|
+ expect(error).to.extist
|
|
|
+ expect(error).to.be.instanceof(Error)
|
|
|
+ expect(error.constructor.name).to.equal('NotFoundError')
|
|
|
+ done()
|
|
|
+
|
|
|
+ it 'handle entity no access', (done) ->
|
|
|
+ @UserMembershipHandler.getEntity.yields(null, null)
|
|
|
+ @UserMembershipAuthorization.requireGroupAccess @req, null, (error) =>
|
|
|
+ sinon.assert.called(@AuthorizationMiddlewear.redirectToRestricted)
|
|
|
+ done()
|
|
|
+
|
|
|
it 'handle anonymous user', (done) ->
|
|
|
@AuthenticationController.getSessionUser.returns(null)
|
|
|
@UserMembershipAuthorization.requireGroupAccess @req, null, (error) =>
|