public void TestThatAuthorizeThrowsSecurityExceptionWhenServiceTypeHasRequiredClaimTypeAttributesAndClaimSetsDoesNotHaveRequiredClaimTypes() { var fixture = new Fixture(); var claimSetStub = MockRepository.GenerateStub <ClaimSet>(); claimSetStub.Stub(m => m.FindClaims(Arg <string> .Is.Equal(FoodWasteClaimTypes.SystemManagement), Arg <string> .Is.Anything)) .Return(new List <Claim>(0)) .Repeat.Any(); claimSetStub.Stub(m => m.FindClaims(Arg <string> .Is.Equal(FoodWasteClaimTypes.HouseHoldManagement), Arg <string> .Is.Anything)) .Return(new List <Claim>(0)) .Repeat.Any(); claimSetStub.Stub(m => m.FindClaims(Arg <string> .Is.Equal(FoodWasteClaimTypes.ValidatedUser), Arg <string> .Is.Anything)) .Return(new List <Claim> { new Claim(FoodWasteClaimTypes.ValidatedUser, fixture.Create <object>(), Rights.PossessProperty) }) .Repeat.Any(); var authorizationHandler = new AuthorizationHandler(); Assert.That(authorizationHandler, Is.Not.Null); var exception = Assert.Throws <SecurityException>(() => authorizationHandler.Authorize(new List <ClaimSet> { claimSetStub }, typeof(MySecuredService))); Assert.That(exception, Is.Not.Null); Assert.That(exception.Message, Is.Not.Null); Assert.That(exception.Message, Is.Not.Empty); Assert.That(exception.Message, Is.EqualTo(Resource.GetExceptionMessage(ExceptionMessage.MissingClaimTypeForIdentity))); Assert.That(exception.InnerException, Is.Null); }
public void TestThatAuthorizeReturnWhenServiceTypeHasRequiredClaimTypeAttributesAndClaimSetsHasRequiredClaimTypes() { var fixture = new Fixture(); var claimSetStub = MockRepository.GenerateStub <ClaimSet>(); claimSetStub.Stub(m => m.FindClaims(Arg <string> .Is.Equal(FoodWasteClaimTypes.SystemManagement), Arg <string> .Is.Anything)) .Return(new List <Claim> { new Claim(FoodWasteClaimTypes.SystemManagement, fixture.Create <object>(), Rights.PossessProperty) }) .Repeat.Any(); claimSetStub.Stub(m => m.FindClaims(Arg <string> .Is.Equal(FoodWasteClaimTypes.HouseHoldManagement), Arg <string> .Is.Anything)) .Return(new List <Claim> { new Claim(FoodWasteClaimTypes.HouseHoldManagement, fixture.Create <object>(), Rights.PossessProperty) }) .Repeat.Any(); claimSetStub.Stub(m => m.FindClaims(Arg <string> .Is.Equal(FoodWasteClaimTypes.ValidatedUser), Arg <string> .Is.Anything)) .Return(new List <Claim> { new Claim(FoodWasteClaimTypes.ValidatedUser, fixture.Create <object>(), Rights.PossessProperty) }) .Repeat.Any(); var authorizationHandler = new AuthorizationHandler(); Assert.That(authorizationHandler, Is.Not.Null); authorizationHandler.Authorize(new List <ClaimSet> { claimSetStub }, typeof(MySecuredService)); claimSetStub.AssertWasCalled(m => m.FindClaims(Arg <string> .Is.Equal(FoodWasteClaimTypes.SystemManagement), Arg <string> .Is.Equal(Rights.PossessProperty))); claimSetStub.AssertWasCalled(m => m.FindClaims(Arg <string> .Is.Equal(FoodWasteClaimTypes.HouseHoldManagement), Arg <string> .Is.Equal(Rights.PossessProperty))); claimSetStub.AssertWasCalled(m => m.FindClaims(Arg <string> .Is.Equal(FoodWasteClaimTypes.ValidatedUser), Arg <string> .Is.Equal(Rights.PossessProperty))); }
public void TestThatAuthorizeReturnWhenServiceTypeDoesNotHaveAnyRequiredClaimTypeAttributes() { var authorizationHandler = new AuthorizationHandler(); Assert.That(authorizationHandler, Is.Not.Null); authorizationHandler.Authorize(new List <ClaimSet>(0), typeof(MyUnsecuredService)); }
public void TestThatAuthorizeThrowsSecurityExceptionWhenClaimSetIsEmptyAndServiceTypeHasRequiredClaimTypes() { var authorizationHandler = new AuthorizationHandler(); Assert.That(authorizationHandler, Is.Not.Null); var exception = Assert.Throws <SecurityException>(() => authorizationHandler.Authorize(new List <ClaimSet>(0), typeof(MySecuredService))); Assert.That(exception, Is.Not.Null); Assert.That(exception.Message, Is.Not.Null); Assert.That(exception.Message, Is.Not.Empty); Assert.That(exception.Message, Is.EqualTo(Resource.GetExceptionMessage(ExceptionMessage.NoClaimsWasFound))); Assert.That(exception.InnerException, Is.Null); }
public void TestThatAuthorizeThrowsArgumentNullExceptionWhenServiceTypeIsNull() { var authorizationHandler = new AuthorizationHandler(); Assert.That(authorizationHandler, Is.Not.Null); var exception = Assert.Throws <ArgumentNullException>(() => authorizationHandler.Authorize(new List <ClaimSet>(0), null)); Assert.That(exception, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Empty); Assert.That(exception.ParamName, Is.EqualTo("serviceType")); Assert.That(exception.InnerException, Is.Null); }
public void TestThatAuthorizeThrowsArgumentNullExceptionWhenClaimSetsIsNull() { var authorizationHandler = new AuthorizationHandler(); Assert.That(authorizationHandler, Is.Not.Null); var exception = Assert.Throws <ArgumentNullException>(() => authorizationHandler.Authorize(null, typeof(MyUnsecuredService))); Assert.That(exception, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Empty); Assert.That(exception.ParamName, Is.EqualTo("claimSets")); Assert.That(exception.InnerException, Is.Null); }