public void GetAccessTypeFromEnum() { AccessType accessType = AccessType.Get(EnumWrapper.Get(TestAccessTypes.First)); Assert.That(accessType.Value, Is.EqualTo(EnumWrapper.Get(TestAccessTypes.First))); }
public void Equals_False_WithNull() { Assert.That(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second)).Equals(null), Is.False); }
public void GetHashCode_IsSameForEqualValues() { Assert.That(AccessType.Get(TestAccessTypes.Second).GetHashCode(), Is.EqualTo(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second)).GetHashCode())); }
public void Test_WithSecurityStrategyIsNull() { _testHelper.ReplayAll(); _securityClient.CheckAccess(new SecurableObject(null), (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) }); _testHelper.VerifyAll(); }
public void HasAccess_WithReEntrancyOnSameGuard_ThrowsInvalidOperationException() { var objectSecurityStrategyStub = MockRepository.GenerateStub <IObjectSecurityStrategy>(); var guard = new InstanceBasedReEntrancyGuardedObjectSecurityStrategyDecorator(objectSecurityStrategyStub); var accessTypesOnFirstCall = new[] { AccessType.Get(GeneralAccessTypes.Find) }; bool isExceptionThrownBySecondHasAccess = false; objectSecurityStrategyStub .Stub(_ => _.HasAccess(_securityProviderStub, _principalStub, accessTypesOnFirstCall)) .Return(false) .WhenCalled( mi => { var exception = Assert.Throws <InvalidOperationException> ( () => guard.HasAccess(_securityProviderStub, _principalStub, new[] { AccessType.Get(GeneralAccessTypes.Read) })); isExceptionThrownBySecondHasAccess = true; throw exception; }); Assert.That( () => guard.HasAccess(_securityProviderStub, _principalStub, accessTypesOnFirstCall), Throws.InvalidOperationException .With.Message.StartsWith( "Multiple reentrancies on InstanceBasedReEntrancyGuardedObjectSecurityStrategyDecorator.HasAccess(...) are not allowed as they can indicate a possible infinite recursion.")); Assert.That(isExceptionThrownBySecondHasAccess, Is.True); }
public void Equatable_Equals_False() { Assert.That(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second)).Equals(AccessType.Get(TestAccessTypes.Fourth)), Is.False); }
public void Test_AccessGranted() { _testHelper.ExpectFunctionalSecurityStrategyHasAccess(TestAccessTypes.First, true); _testHelper.ReplayAll(); _securityClient.CheckStatelessAccess(typeof(SecurableObject), (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) }); _testHelper.VerifyAll(); }
public void Test_WithParamsArray_AndSecurityPrincipal() { _testHelper.ReplayAll(); var securityPrincipal = _securityClient.PrincipalProvider.GetPrincipal(); bool hasAccess = _securityClient.HasAccess(_testHelper.SecurableObject, securityPrincipal, AccessType.Get(TestAccessTypes.First)); _testHelper.VerifyAll(); Assert.That(hasAccess, Is.EqualTo(true)); }
public void Test_WithParamsArray_AndSecurityPrincipal() { _testHelper.ReplayAll(); var securityPrincipal = _securityClient.PrincipalProvider.GetPrincipal(); _securityClient.CheckAccess(_testHelper.SecurableObject, securityPrincipal, AccessType.Get(TestAccessTypes.First)); _testHelper.VerifyAll(); }
public void IsReadonly_PropertyWithDefaultPermission_False() { var securityContextStub = MockRepository.GenerateStub <ISecurityContext> (); var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory> (); securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(securityContextStub); _securityProviderStub.Stub(mock => mock.GetAccess(securityContextStub, _securityPrincipalStub)).Return(new[] { AccessType.Get(GeneralAccessTypes.Edit) }); IBusinessObject bindableSecurableObject; using (SecurityFreeSection.Activate()) { bindableSecurableObject = CreateBindableSecurableObject(securityContextFactoryStub); } var businessObjectClass = bindableSecurableObject.BusinessObjectClass; var property = businessObjectClass.GetPropertyDefinition("PropertyWithDefaultPermission"); Assert.That(property.IsReadOnly(bindableSecurableObject), Is.False); }
private AccessType ConvertToAccessType(AccessTypeDefinition accessTypeDefinition) { return(AccessType.Get(EnumWrapper.Get(accessTypeDefinition.Name))); }
public void IsAccessible_CustomPermissionMixedProperty_True() { var securityContextStub = MockRepository.GenerateStub <ISecurityContext> (); var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory> (); securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(securityContextStub); _securityProviderStub.Stub(mock => mock.GetAccess(securityContextStub, _securityPrincipalStub)).Return(new[] { AccessType.Get(TestAccessTypes.First) }); IBusinessObject bindableSecurableObject; using (SecurityFreeSection.Activate()) { bindableSecurableObject = CreateBindableSecurableObject(securityContextFactoryStub); } var businessObjectClass = bindableSecurableObject.BusinessObjectClass; var property = businessObjectClass.GetPropertyDefinition("CustomPermissionMixedProperty"); Assert.That(property.IsAccessible(bindableSecurableObject), Is.True); }
public void NoTest_DerivedReadOnlyProperty_IsNotAccessible() { var securityContextStub = MockRepository.GenerateStub <ISecurityContext> (); var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory> (); securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(securityContextStub); _securityProviderStub.Stub(mock => mock.GetAccess(securityContextStub, _securityPrincipalStub)).Return(new[] { AccessType.Get(TestAccessTypes.First) }); IBusinessObject bindableSecurableObject; using (SecurityFreeSection.Activate()) { bindableSecurableObject = CreateDerivedBindableSecurableObject(securityContextFactoryStub); } var businessObjectClass = bindableSecurableObject.BusinessObjectClass; var property = businessObjectClass.GetPropertyDefinition("PropertyToOverride"); Assert.That(property.IsAccessible(bindableSecurableObject), Is.False); }
public void Test_AccessDenied_ShouldThrowPermissionDeniedException() { _testHelper.ExpectFunctionalSecurityStrategyHasAccess(TestAccessTypes.First, false); _testHelper.ReplayAll(); _securityClient.CheckStatelessAccess(typeof(SecurableObject), (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) }); _testHelper.VerifyAll(); }
public void GetAccessTypeFromEnumWithoutAccessTypeAttribute() { AccessType.Get(TestAccessTypesWithoutAccessTypeAttribute.First); }
public void Test_AccessGranted() { _testHelper.ReplayAll(); _securityClient.CheckAccess(_testHelper.SecurableObject, (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) }); _testHelper.VerifyAll(); }
public void GetFromCache() { Assert.That(AccessType.Get(TestAccessTypes.First), Is.EqualTo(AccessType.Get(TestAccessTypes.First))); Assert.That(AccessType.Get(TestAccessTypes.Second), Is.EqualTo(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second)))); Assert.That(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Third)), Is.EqualTo(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Third)))); }
public void Test_WithinSecurityFreeSection_AccessGranted() { _testHelper.ReplayAll(); using (SecurityFreeSection.Activate()) { _securityClient.CheckAccess(_testHelper.SecurableObject, (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) }); } _testHelper.VerifyAll(); }
public void Equals_True() { Assert.That(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second)).Equals((object)AccessType.Get(TestAccessTypes.Second)), Is.True); }
public void Test_WithParamsArray_AndSecurityPrincipal() { _testHelper.ExpectFunctionalSecurityStrategyHasAccess(TestAccessTypes.First, true); _testHelper.ReplayAll(); var securityPrincipal = _securityClient.PrincipalProvider.GetPrincipal(); _securityClient.CheckStatelessAccess(typeof(SecurableObject), securityPrincipal, AccessType.Get(TestAccessTypes.First)); _testHelper.VerifyAll(); }