예제 #1
0
        public void MatchingPermissionReturnsRight()
        {
            UserPermission assertion = new UserPermission("johndoe", SecurityRight.Inherit, SecurityRight.Inherit, SecurityRight.Allow, SecurityRight.Inherit);
            SecurityRight  result    = assertion.CheckPermission(null, SecurityPermission.ForceAbortBuild);

            Assert.AreEqual(SecurityRight.Allow, result);
        }
예제 #2
0
        public void DifferentPermissionReturnsInherited()
        {
            UserPermission assertion = new UserPermission("johndoe", SecurityRight.Inherit, SecurityRight.Inherit, SecurityRight.Allow, SecurityRight.Inherit);
            SecurityRight  result    = assertion.CheckPermission(null, SecurityPermission.SendMessage);

            Assert.AreEqual(SecurityRight.Inherit, result);
        }
예제 #3
0
        public void CorrectPermissionsReturnedStartProject()
        {
            UserPermission assertion = new UserPermission("johnDoe",
                                                          SecurityRight.Deny,
                                                          SecurityRight.Deny,
                                                          SecurityRight.Deny,
                                                          SecurityRight.Allow);
            SecurityRight right = assertion.CheckPermission(null, SecurityPermission.StartStopProject);

            Assert.AreEqual(SecurityRight.Allow, right);
        }
예제 #4
0
        public void CorrectPermissionsReturnedForceBuild()
        {
            UserPermission assertion = new UserPermission("johnDoe",
                                                          SecurityRight.Deny,
                                                          SecurityRight.Deny,
                                                          SecurityRight.Allow,
                                                          SecurityRight.Deny);
            SecurityRight right = assertion.CheckPermission(null, SecurityPermission.ForceAbortBuild);

            Assert.AreEqual(SecurityRight.Allow, right);
        }
예제 #5
0
        public void CorrectPermissionsReturnedSendMessage()
        {
            UserPermission assertion = new UserPermission("johnDoe",
                                                          SecurityRight.Deny,
                                                          SecurityRight.Allow,
                                                          SecurityRight.Deny,
                                                          SecurityRight.Deny);
            SecurityRight right = assertion.CheckPermission(null, SecurityPermission.SendMessage);

            Assert.AreEqual(SecurityRight.Allow, right);
        }
예제 #6
0
        public void CheckPermissionWithInvalidReference()
        {
            SecurityPermission permission   = SecurityPermission.ForceAbortBuild;
            string             badReference = "doesNotExist";
            ISecurityManager   manager      = mocks.Create <ISecurityManager>(MockBehavior.Strict).Object;

            Mock.Get(manager).Setup(_manager => _manager.RetrievePermission(badReference)).Returns((IPermission)null).Verifiable();

            UserPermission assertion = new UserPermission();

            assertion.RefId = badReference;
            Assert.That(delegate { assertion.CheckPermission(manager, permission); },
                        Throws.TypeOf <BadReferenceException>().With.Message.EqualTo("Reference 'doesNotExist' is either incorrect or missing."));
        }
예제 #7
0
        public void CheckPermissionWithInvalidReference()
        {
            SecurityPermission permission   = SecurityPermission.ForceAbortBuild;
            string             badReference = "doesNotExist";
            ISecurityManager   manager      = mocks.StrictMock <ISecurityManager>();

            Expect.Call(manager.RetrievePermission(badReference)).Return(null);

            mocks.ReplayAll();
            UserPermission assertion = new UserPermission();

            assertion.RefId = badReference;
            Assert.That(delegate { assertion.CheckPermission(manager, permission); },
                        Throws.TypeOf <BadReferenceException>().With.Message.EqualTo("Reference 'doesNotExist' is either incorrect or missing."));
        }
예제 #8
0
        public void CheckPermissionWithValidReference()
        {
            SecurityPermission permission    = SecurityPermission.ForceAbortBuild;
            string             goodReference = "doesExist";
            IPermission        goodAssertion = mocks.Create <IPermission>(MockBehavior.Strict).Object;
            ISecurityManager   manager       = mocks.Create <ISecurityManager>(MockBehavior.Strict).Object;

            Mock.Get(manager).Setup(_manager => _manager.RetrievePermission(goodReference)).Returns(goodAssertion).Verifiable();
            Mock.Get(goodAssertion).Setup(_goodAssertion => _goodAssertion.CheckPermission(manager, permission)).Returns(SecurityRight.Allow).Verifiable();

            UserPermission assertion = new UserPermission();

            assertion.RefId = goodReference;
            SecurityRight result = assertion.CheckPermission(manager, permission);

            Assert.AreEqual(SecurityRight.Allow, result);
            mocks.VerifyAll();
        }
예제 #9
0
        public void CheckPermissionWithValidReference()
        {
            SecurityPermission permission    = SecurityPermission.ForceAbortBuild;
            string             goodReference = "doesExist";
            IPermission        goodAssertion = mocks.StrictMock <IPermission>();
            ISecurityManager   manager       = mocks.StrictMock <ISecurityManager>();

            Expect.Call(manager.RetrievePermission(goodReference)).Return(goodAssertion);
            Expect.Call(goodAssertion.CheckPermission(manager, permission)).Return(SecurityRight.Allow);

            mocks.ReplayAll();
            UserPermission assertion = new UserPermission();

            assertion.RefId = goodReference;
            SecurityRight result = assertion.CheckPermission(manager, permission);

            Assert.AreEqual(SecurityRight.Allow, result);
            mocks.VerifyAll();
        }