Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Updated specs to use RequireAnyRolePolicy instead of RequireRolePol…

…icy.
  • Loading branch information...
commit 6b54e852e1736f5b1d9e2a676b90a4c22533b75c 1 parent 35dccc1
Kristoffer Ahl authored
View
4 FluentSecurity.Specification/Configuration/DefaultPolicyAppenderSpec.cs
@@ -225,7 +225,7 @@ public void Should_remove_all_existing_policies()
}
[Test]
- public void Should_add_RequireRolePolicy()
+ public void Should_add_RequireAnyRolePolicy()
{
// Act
PolicyAppender.UpdatePolicies(_requireAnyRolePolicy, Policies);
@@ -265,7 +265,7 @@ public void Should_remove_all_existing_policies()
}
[Test]
- public void Should_add_RequireRolePolicy()
+ public void Should_add_RequireAllRolesPolicy()
{
// Act
PolicyAppender.UpdatePolicies(_requireAllRolesPolicy, Policies);
View
11 FluentSecurity.Specification/ConventionPolicyContainerSpec.cs
@@ -5,7 +5,6 @@
using FluentSecurity.Configuration;
using FluentSecurity.Policy;
using FluentSecurity.Specification.Helpers;
-using FluentSecurity.Specification.TestData;
using FluentSecurity.Specification.TestData.Controllers;
using Moq;
using NUnit.Framework;
@@ -97,7 +96,7 @@ public void Should_delegate_work_to_policycontainers()
var policyContainer2 = new Mock<IPolicyContainerConfiguration>();
var policyContainer3 = new Mock<IPolicyContainerConfiguration>();
- var policyContainers = new List<IPolicyContainerConfiguration>()
+ var policyContainers = new List<IPolicyContainerConfiguration>
{
policyContainer1.Object,
policyContainer2.Object,
@@ -186,7 +185,7 @@ public void Should_add_policyresult_cache_strategy_to_policycontainers()
conventionPolicyContainer.Cache<DenyAnonymousAccessPolicy>(expectedLifecycle, expectedLevel);
// Assert
- var containers = policyContainers.Cast<PolicyContainer>().ToList();
+ var containers = policyContainers.ToList();
Assert.That(containers[0].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
Assert.That(containers[0].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
Assert.That(containers[0].CacheStrategies.Single().CacheLevel, Is.EqualTo(expectedLevel));
@@ -215,7 +214,7 @@ public void Should_clear_all_cache_strategies()
};
var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers.Cast<IPolicyContainerConfiguration>().ToList());
- conventionPolicyContainer.Cache<RequireRolePolicy>(Cache.PerHttpRequest);
+ conventionPolicyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest);
// Act
conventionPolicyContainer.ClearCacheStrategies();
@@ -239,11 +238,11 @@ public void Should_clear_all_cache_strategies_for_policy()
};
var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers.Cast<IPolicyContainerConfiguration>().ToList());
- conventionPolicyContainer.Cache<RequireRolePolicy>(Cache.PerHttpRequest);
+ conventionPolicyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest);
conventionPolicyContainer.Cache<RequireAllRolesPolicy>(Cache.PerHttpRequest);
// Act
- conventionPolicyContainer.ClearCacheStrategyFor<RequireRolePolicy>();
+ conventionPolicyContainer.ClearCacheStrategyFor<RequireAnyRolePolicy>();
// Assert
var containers = policyContainers.ToList();
View
2  FluentSecurity.Specification/Policy/RequireAllRolesPolicySpec.cs
@@ -297,7 +297,7 @@ public void Should_not_be_the_same_when_roles_count_differ()
[Test]
public void Should_not_be_the_same_when_types_differ()
{
- var instance1 = new RequireRolePolicy("Editor", "Writer");
+ var instance1 = new RequireAnyRolePolicy("Editor", "Writer");
var instance2 = new RequireAllRolesPolicy("Editor", "Writer");
Assert.That(instance1.GetHashCode(), Is.Not.EqualTo(instance2.GetHashCode()));
}
View
4 ...cification/Policy/ViolationHandlers/Conventions/FindDefaultPolicyViolationHandlerByNameConventionSpec.cs
@@ -29,14 +29,14 @@ public void Should_return_null_when_no_handler_is_a_match()
}
[Test]
- public void Should_return_DefaultPolicyViolationHandler_for_RequireRolePolicy()
+ public void Should_return_DefaultPolicyViolationHandler_for_RequireAnyRolePolicy()
{
// Arrange
var convention = new FindDefaultPolicyViolationHandlerByNameConvention
{
PolicyViolationHandlerProvider = () => TestDataFactory.CreatePolicyViolationHandlers()
};
- var exception = TestDataFactory.CreateExceptionFor(new RequireRolePolicy("Role"));
+ var exception = TestDataFactory.CreateExceptionFor(new RequireAnyRolePolicy("Role"));
// Act
var handler = convention.GetHandlerFor(exception);
View
64 FluentSecurity.Specification/PolicyContainerSpec.cs
@@ -865,7 +865,7 @@ public void Should_return_the_same_results()
public class When_setting_the_cache_lifecycle
{
[Test]
- public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_lifecycle_set_to_DoNotCache()
+ public void Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_lifecycle_set_to_DoNotCache()
{
const Cache expectedLifecycle = Cache.DoNotCache;
const string expectedControllerName = "Controller1";
@@ -874,13 +874,13 @@ public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_li
var policyContainer = new PolicyContainer(expectedControllerName, expectedActionName, TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.Cache<RequireRolePolicy>(expectedLifecycle);
+ policyContainer.Cache<RequireAnyRolePolicy>(expectedLifecycle);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
Assert.That(policyResultCacheStrategy.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(policyResultCacheStrategy.ActionName, Is.EqualTo(expectedActionName));
- Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(expectedLifecycle));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(By.ControllerAction));
}
@@ -895,19 +895,19 @@ public void Should_add_policyresult_cache_strategy_for_Policy_T_with_lifecycle_s
var policyContainer = new PolicyContainer(expectedControllerName, expectedActionName, TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.AddPolicy<RequireRolePolicy>().DoNotCache();
+ policyContainer.AddPolicy<RequireAnyRolePolicy>().DoNotCache();
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
Assert.That(policyResultCacheStrategy.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(policyResultCacheStrategy.ActionName, Is.EqualTo(expectedActionName));
- Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(expectedLifecycle));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(By.ControllerAction));
}
[Test]
- public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_lifecycle_set_to_PerHttpRequest()
+ public void Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_lifecycle_set_to_PerHttpRequest()
{
const Cache expectedLifecycle = Cache.PerHttpRequest;
const string expectedControllerName = "Controller2";
@@ -916,13 +916,13 @@ public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_li
var policyContainer = new PolicyContainer(expectedControllerName, expectedActionName, TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.Cache<RequireRolePolicy>(expectedLifecycle);
+ policyContainer.Cache<RequireAnyRolePolicy>(expectedLifecycle);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
Assert.That(policyResultCacheStrategy.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(policyResultCacheStrategy.ActionName, Is.EqualTo(expectedActionName));
- Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(expectedLifecycle));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(By.ControllerAction));
}
@@ -937,19 +937,19 @@ public void Should_add_policyresult_cache_strategy_for_Policy_T_with_lifecycle_s
var policyContainer = new PolicyContainer(expectedControllerName, expectedActionName, TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.AddPolicy<RequireRolePolicy>().CachePerHttpRequest();
+ policyContainer.AddPolicy<RequireAnyRolePolicy>().CachePerHttpRequest();
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
Assert.That(policyResultCacheStrategy.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(policyResultCacheStrategy.ActionName, Is.EqualTo(expectedActionName));
- Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(expectedLifecycle));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(By.ControllerAction));
}
[Test]
- public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_lifecycle_set_to_PerHttpSession()
+ public void Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_lifecycle_set_to_PerHttpSession()
{
const Cache expectedLifecycle = Cache.PerHttpSession;
const string expectedControllerName = "Controller3";
@@ -958,13 +958,13 @@ public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_li
var policyContainer = new PolicyContainer(expectedControllerName, expectedActionName, TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.Cache<RequireRolePolicy>(expectedLifecycle);
+ policyContainer.Cache<RequireAnyRolePolicy>(expectedLifecycle);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
Assert.That(policyResultCacheStrategy.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(policyResultCacheStrategy.ActionName, Is.EqualTo(expectedActionName));
- Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(expectedLifecycle));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(By.ControllerAction));
}
@@ -979,13 +979,13 @@ public void Should_add_policyresult_cache_strategy_for_Policy_T_with_lifecycle_s
var policyContainer = new PolicyContainer(expectedControllerName, expectedActionName, TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.AddPolicy<RequireRolePolicy>().CachePerHttpSession();
+ policyContainer.AddPolicy<RequireAnyRolePolicy>().CachePerHttpSession();
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
Assert.That(policyResultCacheStrategy.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(policyResultCacheStrategy.ActionName, Is.EqualTo(expectedActionName));
- Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(expectedLifecycle));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(By.ControllerAction));
}
@@ -1022,7 +1022,7 @@ public void Should_add_policyresult_cache_strategies_for_each_policy_type()
// Act
policyContainer
.Cache<RequireAllRolesPolicy>(Cache.PerHttpRequest)
- .Cache<RequireRolePolicy>(Cache.PerHttpSession);
+ .Cache<RequireAnyRolePolicy>(Cache.PerHttpSession);
// Assert
Assert.That(policyContainer.CacheStrategies.Count, Is.EqualTo(2));
@@ -1037,7 +1037,7 @@ public void Should_add_policyresult_cache_strategies_for_each_policy_type()
var strategy2 = policyContainer.CacheStrategies.Last();
Assert.That(strategy2.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(strategy2.ActionName, Is.EqualTo(expectedActionName));
- Assert.That(strategy2.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(strategy2.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(strategy2.CacheLifecycle, Is.EqualTo(Cache.PerHttpSession));
Assert.That(strategy2.CacheLevel, Is.EqualTo(By.ControllerAction));
}
@@ -1071,13 +1071,13 @@ public void Should_update_existing_policyresult_cache_strategies()
public class When_setting_the_cache_lifecycle_and_cache_level
{
[Test]
- public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_level_set_to_ControllerAction()
+ public void Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_level_set_to_ControllerAction()
{
const By expectedLevel = By.ControllerAction;
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.Cache<RequireRolePolicy>(Cache.PerHttpRequest, expectedLevel);
+ policyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest, expectedLevel);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
@@ -1085,13 +1085,13 @@ public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_le
}
[Test]
- public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_level_set_to_Controller()
+ public void Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_level_set_to_Controller()
{
const By expectedLevel = By.Controller;
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.Cache<RequireRolePolicy>(Cache.PerHttpRequest, expectedLevel);
+ policyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest, expectedLevel);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
@@ -1099,13 +1099,13 @@ public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_le
}
[Test]
- public void Should_add_policyresult_cache_strategy_for_RequireRolePolicy_with_level_set_to_Policy()
+ public void Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_level_set_to_Policy()
{
const By expectedLevel = By.Policy;
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.Cache<RequireRolePolicy>(Cache.PerHttpRequest, expectedLevel);
+ policyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest, expectedLevel);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
@@ -1119,11 +1119,11 @@ public void Should_add_policyresult_cache_strategy_for_Policy_T_with_lifecycle_s
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.AddPolicy<RequireRolePolicy>().DoNotCache(expectedLevel);
+ policyContainer.AddPolicy<RequireAnyRolePolicy>().DoNotCache(expectedLevel);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
- Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(Cache.DoNotCache));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(expectedLevel));
}
@@ -1135,11 +1135,11 @@ public void Should_add_policyresult_cache_strategy_for_Policy_T_with_lifecycle_s
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.AddPolicy<RequireRolePolicy>().CachePerHttpRequest(expectedLevel);
+ policyContainer.AddPolicy<RequireAnyRolePolicy>().CachePerHttpRequest(expectedLevel);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
- Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(Cache.PerHttpRequest));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(expectedLevel));
}
@@ -1151,11 +1151,11 @@ public void Should_add_policyresult_cache_strategy_for_Policy_T_with_lifecycle_s
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
// Act
- policyContainer.AddPolicy<RequireRolePolicy>().CachePerHttpSession(expectedLevel);
+ policyContainer.AddPolicy<RequireAnyRolePolicy>().CachePerHttpSession(expectedLevel);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
- Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(Cache.PerHttpSession));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(expectedLevel));
}
@@ -1192,7 +1192,7 @@ public class When_clearing_the_cache_strategy
public void Should_clear_all_cache_strategies()
{
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
- policyContainer.Cache<RequireRolePolicy>(Cache.PerHttpRequest);
+ policyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest);
// Act
policyContainer.ClearCacheStrategies();
@@ -1205,11 +1205,11 @@ public void Should_clear_all_cache_strategies()
public void Should_clear_all_cache_strategies_for_policy()
{
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
- policyContainer.Cache<RequireRolePolicy>(Cache.PerHttpRequest);
+ policyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest);
policyContainer.Cache<RequireAllRolesPolicy>(Cache.PerHttpRequest);
// Act
- policyContainer.ClearCacheStrategyFor<RequireRolePolicy>();
+ policyContainer.ClearCacheStrategyFor<RequireAnyRolePolicy>();
// Assert
Assert.That(policyContainer.CacheStrategies.Single().PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
View
5 FluentSecurity.Specification/SecurityConfigurationSpec.cs
@@ -1,5 +1,4 @@
using System;
-using System.IO;
using System.Linq;
using FluentSecurity.Specification.Helpers;
using FluentSecurity.Specification.TestData;
@@ -77,7 +76,7 @@ public void Should_return_the_current_configuration()
------------------------------------------------------------------------------------
FluentSecurity.Specification.TestData.BlogController > DeletePost
- FluentSecurity.Policy.RequireRolePolicy (Owner or Publisher)
+ FluentSecurity.Policy.RequireAnyRolePolicy (Owner or Publisher)
FluentSecurity.Specification.TestData.BlogController > Index
FluentSecurity.Policy.DenyAnonymousAccessPolicy
@@ -88,7 +87,7 @@ public void Should_return_the_current_configuration()
{
configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
configuration.Advanced.IgnoreMissingConfiguration();
- configuration.For<BlogController>(x => x.DeletePost(0)).DenyAnonymousAccess().RequireRole(UserRole.Owner, UserRole.Publisher);
+ configuration.For<BlogController>(x => x.DeletePost(0)).DenyAnonymousAccess().RequireAnyRole(UserRole.Owner, UserRole.Publisher);
configuration.For<BlogController>(x => x.Index()).DenyAnonymousAccess();
});
View
4 FluentSecurity.Specification/SecurityConfiguratorSpec.cs
@@ -124,7 +124,7 @@ public void SetUp()
configuration.GetRolesFrom(StaticHelper.GetRolesExcludingOwner);
configuration.For<BlogController>(x => x.Index()).DenyAnonymousAccess();
- configuration.For<BlogController>(x => x.AddPost()).RequireRole(UserRole.Writer, UserRole.Publisher, UserRole.Owner);
+ configuration.For<BlogController>(x => x.AddPost()).RequireAnyRole(UserRole.Writer, UserRole.Publisher, UserRole.Owner);
});
_policyContainers = SecurityConfiguration.Current.PolicyContainers;
@@ -153,7 +153,7 @@ public void Should_have_policycontainer_for_Blog_AddPost()
Assert.That(container.ControllerName, Is.EqualTo(_controllerName));
Assert.That(container.ActionName, Is.EqualTo(AddPostActionName));
Assert.That(container.GetPolicies().Count(), Is.EqualTo(1));
- Assert.That(container.GetPolicies().First().GetType(), Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(container.GetPolicies().First().GetType(), Is.EqualTo(typeof(RequireAnyRolePolicy)));
}
}
View
12 FluentSecurity.Specification/SecurityHandlerSpec.cs
@@ -150,7 +150,7 @@ public void Should_throw_when_the_user_is_anonymous()
[TestFixture]
[Category("SecurityHandlerSpec")]
- public class When_handling_security_for_a_controlleraction_with_RequireRole_Owner
+ public class When_handling_security_for_a_controlleraction_with_RequireAnyRole_Owner
{
[SetUp]
public void SetUp()
@@ -166,7 +166,7 @@ public void Should_not_throw_exception_when_the_user_is_authenticated_with_role_
{
policy.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsTrue);
policy.GetRolesFrom(StaticHelper.GetRolesIncludingOwner);
- policy.For<BlogController>(x => x.DeletePost(0)).RequireRole(UserRole.Owner);
+ policy.For<BlogController>(x => x.DeletePost(0)).RequireAnyRole(UserRole.Owner);
});
var securityHandler = new SecurityHandler();
@@ -183,7 +183,7 @@ public void Should_throw_when_the_user_is_anonymous()
{
policy.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
policy.GetRolesFrom(StaticHelper.GetRolesExcludingOwner);
- policy.For<BlogController>(x => x.DeletePost(0)).RequireRole(UserRole.Owner);
+ policy.For<BlogController>(x => x.DeletePost(0)).RequireAnyRole(UserRole.Owner);
});
var securityHandler = new SecurityHandler();
@@ -192,7 +192,7 @@ public void Should_throw_when_the_user_is_anonymous()
var exception = Assert.Throws<PolicyViolationException>(() => securityHandler.HandleSecurityFor(NameHelper.Controller<BlogController>(), "DeletePost", SecurityContext.Current));
// Assert
- Assert.That(exception.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(exception.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(exception.Message, Is.StringContaining("Anonymous access denied"));
}
@@ -204,7 +204,7 @@ public void Should_throw_when_the_user_does_not_have_the_role_Owner()
{
policy.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsTrue);
policy.GetRolesFrom(StaticHelper.GetRolesExcludingOwner);
- policy.For<BlogController>(x => x.DeletePost(0)).RequireRole(UserRole.Owner);
+ policy.For<BlogController>(x => x.DeletePost(0)).RequireAnyRole(UserRole.Owner);
});
var securityHandler = new SecurityHandler();
@@ -213,7 +213,7 @@ public void Should_throw_when_the_user_does_not_have_the_role_Owner()
var exception = Assert.Throws<PolicyViolationException>(() => securityHandler.HandleSecurityFor(NameHelper.Controller<BlogController>(), "DeletePost", SecurityContext.Current));
// Assert
- Assert.That(exception.PolicyType, Is.EqualTo(typeof(RequireRolePolicy)));
+ Assert.That(exception.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(exception.Message, Is.StringContaining("Access requires one of the following roles: Owner."));
}
}
View
24 FluentSecurity.TestHelper.Specification/ExpectationGroupSpec.cs
@@ -154,8 +154,8 @@ public void Should_have_1_expecation_when_expecations_have_same_type_for_does_no
public void Should_have_1_expecation_when_expecations_have_same_instance_for_HasInstanceExpectation()
{
// Arrange
- var expectation1 = new HasInstanceExpectation(new RequireRolePolicy("Editor"));
- var expectation2 = new HasInstanceExpectation(new RequireRolePolicy("Editor"));
+ var expectation1 = new HasInstanceExpectation(new RequireAnyRolePolicy("Editor"));
+ var expectation2 = new HasInstanceExpectation(new RequireAnyRolePolicy("Editor"));
// Act
_expectationGroup.ApplyExpectation(expectation1);
@@ -169,8 +169,8 @@ public void Should_have_1_expecation_when_expecations_have_same_instance_for_Has
public void Should_have_2_expecation_when_expecations_have_different_instances_for_HasInstanceExpectation()
{
// Arrange
- var expectation1 = new HasInstanceExpectation(new RequireRolePolicy("Editor"));
- var expectation2 = new HasInstanceExpectation(new RequireRolePolicy("Editor", "Writer"));
+ var expectation1 = new HasInstanceExpectation(new RequireAnyRolePolicy("Editor"));
+ var expectation2 = new HasInstanceExpectation(new RequireAnyRolePolicy("Editor", "Writer"));
// Act
_expectationGroup.ApplyExpectation(expectation1);
@@ -184,8 +184,8 @@ public void Should_have_2_expecation_when_expecations_have_different_instances_f
public void Should_have_1_expecation_when_expecations_have_same_instance_for_DoesNotHaveInstanceExpectation()
{
// Arrange
- var expectation1 = new DoesNotHaveInstanceExpectation(new RequireRolePolicy("Editor"));
- var expectation2 = new DoesNotHaveInstanceExpectation(new RequireRolePolicy("Editor"));
+ var expectation1 = new DoesNotHaveInstanceExpectation(new RequireAnyRolePolicy("Editor"));
+ var expectation2 = new DoesNotHaveInstanceExpectation(new RequireAnyRolePolicy("Editor"));
// Act
_expectationGroup.ApplyExpectation(expectation1);
@@ -199,8 +199,8 @@ public void Should_have_1_expecation_when_expecations_have_same_instance_for_Doe
public void Should_have_2_expecation_when_expecations_have_different_instances_for_DoesNotHaveInstanceExpectation()
{
// Arrange
- var expectation1 = new DoesNotHaveInstanceExpectation(new RequireRolePolicy("Editor"));
- var expectation2 = new DoesNotHaveInstanceExpectation(new RequireRolePolicy("Editor", "Writer"));
+ var expectation1 = new DoesNotHaveInstanceExpectation(new RequireAnyRolePolicy("Editor"));
+ var expectation2 = new DoesNotHaveInstanceExpectation(new RequireAnyRolePolicy("Editor", "Writer"));
// Act
_expectationGroup.ApplyExpectation(expectation1);
@@ -214,8 +214,8 @@ public void Should_have_2_expecation_when_expecations_have_different_instances_f
public void Should_have_1_expecation_when_expecations_have_same_instance_for_has_and_does_not_have()
{
// Arrange
- var expectation1 = new HasInstanceExpectation(new RequireRolePolicy("Editor"));
- var expectation2 = new DoesNotHaveInstanceExpectation(new RequireRolePolicy("Editor"));
+ var expectation1 = new HasInstanceExpectation(new RequireAnyRolePolicy("Editor"));
+ var expectation2 = new DoesNotHaveInstanceExpectation(new RequireAnyRolePolicy("Editor"));
// Act
_expectationGroup.ApplyExpectation(expectation1);
@@ -229,8 +229,8 @@ public void Should_have_1_expecation_when_expecations_have_same_instance_for_has
public void Should_have_1_expecation_when_expecations_have_same_instance_for_does_not_have_and_has()
{
// Arrange
- var expectation1 = new DoesNotHaveInstanceExpectation(new RequireRolePolicy("Editor"));
- var expectation2 = new HasInstanceExpectation(new RequireRolePolicy("Editor"));
+ var expectation1 = new DoesNotHaveInstanceExpectation(new RequireAnyRolePolicy("Editor"));
+ var expectation2 = new HasInstanceExpectation(new RequireAnyRolePolicy("Editor"));
// Act
_expectationGroup.ApplyExpectation(expectation1);
View
8 FluentSecurity.TestHelper.Specification/SecurityConfigurationExtensionsSpec.cs
@@ -51,8 +51,8 @@ public void Should_verify_expectations()
expectations.Expect<AdminController>(x => x.Login()).DoesNotHave<DenyAnonymousAccessPolicy>().Has<DenyAuthenticatedAccessPolicy>();
expectations.Expect<AdminController>(x => x.NewUser())
.DoesNotHave<DenyAnonymousAccessPolicy>()
- .DoesNotHave<RequireRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserViewer))
- .Has<RequireRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserEditor));
+ .DoesNotHave<RequireAnyRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserViewer))
+ .Has<RequireAnyRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserEditor));
});
Assert.That(results.All(x => x.ExpectationsMet), results.ErrorMessages());
@@ -128,8 +128,8 @@ public void Should_verify_expectations()
expectations.Expect(x => x.Login()).DoesNotHave<DenyAnonymousAccessPolicy>().Has<DenyAuthenticatedAccessPolicy>();
expectations.Expect(x => x.NewUser())
.DoesNotHave<DenyAnonymousAccessPolicy>()
- .DoesNotHave<RequireRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserViewer))
- .Has<RequireRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserEditor));
+ .DoesNotHave<RequireAnyRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserViewer))
+ .Has<RequireAnyRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserEditor));
});
Assert.That(results.All(x => x.ExpectationsMet), results.ErrorMessages());
View
10 FluentSecurity.TestHelper.Specification/TestData/FluentSecurityFactory.cs
@@ -14,11 +14,11 @@ public static ISecurityConfiguration CreateSecurityConfiguration()
configuration.For<SampleController>(x => x.Index()).DenyAuthenticatedAccess();
configuration.For<SampleController>(x => x.List()).DenyAnonymousAccess();
- configuration.For<SampleController>(x => x.New()).RequireRole("Editor").AddPolicy(new DenyInternetExplorerPolicy());
+ configuration.For<SampleController>(x => x.New()).RequireAnyRole("Editor").AddPolicy(new DenyInternetExplorerPolicy());
configuration.For<AdminController>().DenyAnonymousAccess();
configuration.For<AdminController>(x => x.Login()).DenyAuthenticatedAccess();
- configuration.For<AdminController>(x => x.NewUser()).RequireRole(UserRole.UserEditor);
+ configuration.For<AdminController>(x => x.NewUser()).RequireAnyRole(UserRole.UserEditor);
configuration.For<IgnoreController>().Ignore();
});
@@ -46,7 +46,7 @@ public static ISecurityConfiguration CreateSecurityConfigurationWithTwoExpectati
configuration.For<SampleController>(x => x.Index());
configuration.For<SampleController>(x => x.List());
- configuration.For<SampleController>(x => x.New()).RequireRole("Writer");
+ configuration.For<SampleController>(x => x.New()).RequireAnyRole("Writer");
configuration.For<AdminController>();
configuration.For<AdminController>(x => x.Login());
@@ -65,7 +65,7 @@ public static PolicyExpectations CreatePolicyExpectations()
policyExpectations.For<SampleController>(x => x.Index()).Has<DenyAuthenticatedAccessPolicy>();
policyExpectations.For<SampleController>(x => x.List()).Has<DenyAnonymousAccessPolicy>();
- policyExpectations.For<SampleController>(x => x.New()).Has(new RequireRolePolicy("Editor")).DoesNotHave(new RequireRolePolicy("Writer")).Has<DenyInternetExplorerPolicy>();
+ policyExpectations.For<SampleController>(x => x.New()).Has(new RequireAnyRolePolicy("Editor")).DoesNotHave(new RequireAnyRolePolicy("Writer")).Has<DenyInternetExplorerPolicy>();
policyExpectations.For<AdminController>().Has<DenyAnonymousAccessPolicy>();
policyExpectations.For<AdminController>(x => x.Login())
@@ -73,7 +73,7 @@ public static PolicyExpectations CreatePolicyExpectations()
.Has<DenyAuthenticatedAccessPolicy>();
policyExpectations.For<AdminController>(x => x.NewUser())
.DoesNotHave<DenyAnonymousAccessPolicy>()
- .Has<RequireRolePolicy>();
+ .Has<RequireAnyRolePolicy>();
policyExpectations.For<IgnoreController>().Has<IgnorePolicy>();
Please sign in to comment.
Something went wrong with that request. Please try again.