Permalink
Browse files

Merge branch 'release-2.0-alpha4'

  • Loading branch information...
2 parents 89e45ef + 5974644 commit 363f7e5903117da64400497af723cae7aa889d54 Kristoffer Ahl committed Dec 5, 2012
Showing with 3,428 additions and 1,853 deletions.
  1. +2 −1 .gitignore
  2. +1 −1 Build/Scripts/Build.build
  3. +11 −0 Documents/Release-notes.md
  4. +0 −4 FluentSecurity.SampleApplication.Tests/packages.config
  5. +1 −1 FluentSecurity.Specification/AssemblyScannerAssemblySpecification.cs
  6. +1 −1 FluentSecurity.Specification/AssemblyScannerBaseSpecification.cs
  7. +108 −34 FluentSecurity.Specification/Configuration/AdvancedConfigurationSpec.cs
  8. +41 −1 FluentSecurity.Specification/Configuration/DefaultPolicyAppenderSpec.cs
  9. +80 −0 FluentSecurity.Specification/Configuration/PolicyContainerConfigurationWrapperSpec.cs
  10. +35 −0 FluentSecurity.Specification/Configuration/SecurityProfileSpec.cs
  11. +18 −18 FluentSecurity.Specification/Configuration/ViolationConfigurationSpec.cs
  12. +19 −13 FluentSecurity.Specification/Configuration/ViolationHandlerConfigurationSpec.cs
  13. +101 −42 FluentSecurity.Specification/ConfigurationExpressionSpec.cs
  14. +5 −6 FluentSecurity.Specification/ConventionPolicyContainerSpec.cs
  15. +11 −1 FluentSecurity.Specification/FluentSecurity.Specification.csproj
  16. +5 −1 FluentSecurity.Specification/Helpers/MockSecurityContext.cs
  17. +25 −2 FluentSecurity.Specification/Helpers/TestDataFactory.cs
  18. +32 −0 FluentSecurity.Specification/Policy/Contexts/SecurityContextWrapperSpec.cs
  19. +15 −0 FluentSecurity.Specification/Policy/LazySecurityPolicySpec.cs
  20. +1 −1 FluentSecurity.Specification/Policy/RequireAllRolesPolicySpec.cs
  21. +304 −0 FluentSecurity.Specification/Policy/RequireAnyRolePolicySpec.cs
  22. +2 −0 FluentSecurity.Specification/Policy/SecurityPolicyBaseSpec.cs
  23. +2 −2 ...ion/Policy/ViolationHandlers/Conventions/FindDefaultPolicyViolationHandlerByNameConventionSpec.cs
  24. +24 −3 ...ty.Specification/Policy/ViolationHandlers/Conventions/PolicyViolationHandlerTypeConventionSpec.cs
  25. +4 −3 FluentSecurity.Specification/Policy/ViolationHandlers/DelegatePolicyViolationHandlerSpec.cs
  26. +40 −0 FluentSecurity.Specification/Policy/ViolationHandlers/HttpUnauthorizedPolicyViolationHandlerSpec.cs
  27. +4 −4 FluentSecurity.Specification/Policy/ViolationHandlers/PolicyViolationHandlerSelectorSpec.cs
  28. +20 −1 FluentSecurity.Specification/PolicyContainerExtensionsSpec.cs
  29. +53 −47 FluentSecurity.Specification/PolicyContainerSpec.cs
  30. +4 −1 FluentSecurity.Specification/PolicyViolationExceptionSpec.cs
  31. +63 −0 FluentSecurity.Specification/Scanning/AssemblyScannerSpec.cs
  32. +54 −0 FluentSecurity.Specification/Scanning/ProfileScannerSpec.cs
  33. +132 −0 FluentSecurity.Specification/Scanning/ScannerContextSpec.cs
  34. +2 −3 FluentSecurity.Specification/Scanning/{ → TypeScanners}/ControllerTypeScannerSpec.cs
  35. +4 −5 FluentSecurity.Specification/SecurityConfigurationSpec.cs
  36. +2 −2 FluentSecurity.Specification/SecurityConfiguratorSpec.cs
  37. +2 −0 FluentSecurity.Specification/SecurityContextSpec.cs
  38. +6 −6 FluentSecurity.Specification/SecurityHandlerSpec.cs
  39. +55 −0 FluentSecurity.Specification/SecurityModelSpec.cs
  40. +105 −0 FluentSecurity.Specification/SecurityRuntimeSpec.cs
  41. +12 −12 FluentSecurity.TestHelper.Specification/ExpectationGroupSpec.cs
  42. +4 −4 FluentSecurity.TestHelper.Specification/SecurityConfigurationExtensionsSpec.cs
  43. +5 −5 FluentSecurity.TestHelper.Specification/TestData/FluentSecurityFactory.cs
  44. +2 −2 FluentSecurity.sln
  45. +25 −19 FluentSecurity/Configuration/AdvancedConfiguration.cs
  46. +35 −0 FluentSecurity/Configuration/ConventionConfiguration.cs
  47. +1 −1 FluentSecurity/Configuration/DefaultPolicyAppender.cs
  48. +20 −0 FluentSecurity/Configuration/ProfileImport.cs
  49. +10 −0 FluentSecurity/Configuration/RootConfiguration.cs
  50. +20 −0 FluentSecurity/Configuration/SecurityProfile.cs
  51. +10 −11 FluentSecurity/Configuration/ViolationConfiguration.cs
  52. +55 −43 FluentSecurity/ConfigurationExpression.cs
  53. +1 −1 FluentSecurity/Diagnostics/DefaultWhatDoIHaveBuilder.cs
  54. +1 −1 FluentSecurity/Extensions.cs
  55. +13 −4 FluentSecurity/FluentSecurity.csproj
  56. +0 −14 FluentSecurity/IAdvanced.cs
  57. +1 −2 FluentSecurity/ISecurityConfiguration.cs
  58. +1 −0 FluentSecurity/ISecurityContext.cs
  59. +19 −0 FluentSecurity/ISecurityRuntime.cs
  60. +0 −6 FluentSecurity/Internals/Conventions.cs
  61. +5 −0 FluentSecurity/Policy/Contexts/SecurityContextWrapper.cs
  62. +3 −3 FluentSecurity/Policy/LazySecurityPolicy.cs
  63. +102 −0 FluentSecurity/Policy/RequireAnyRolePolicy.cs
  64. +3 −95 FluentSecurity/Policy/RequireRolePolicy.cs
  65. +15 −0 FluentSecurity/Policy/ViolationHandlers/HttpUnauthorizedPolicyViolationHandler.cs
  66. +1 −3 FluentSecurity/PolicyContainer.cs
  67. +7 −0 FluentSecurity/PolicyContainerExtensions.cs
  68. +3 −1 FluentSecurity/PolicyViolationException.cs
  69. +50 −11 FluentSecurity/Scanning/AssemblyScanner.cs
  70. +12 −0 FluentSecurity/Scanning/ProfileScanner.cs
  71. +49 −0 FluentSecurity/Scanning/ScannerContext.cs
  72. +37 −37 FluentSecurity/Scanning/{ → TypeScanners}/ControllerTypeScanner.cs
  73. +10 −10 FluentSecurity/Scanning/{ → TypeScanners}/ITypeScanner.cs
  74. +28 −0 FluentSecurity/Scanning/TypeScanners/ProfileTypeScanner.cs
  75. +8 −11 FluentSecurity/SecurityConfiguration.cs
  76. +15 −19 FluentSecurity/SecurityContext.cs
  77. +4 −4 FluentSecurity/SecurityHandler.cs
  78. +76 −0 FluentSecurity/SecurityRuntime.cs
  79. +2 −2 FluentSecurity/ServiceLocation/ServiceLocator.cs
  80. +1 −1 Packages/repositories.config
  81. +126 −124 ...Application}/FluentSecurity.SampleApplication.Tests/FluentSecurity.SampleApplication.Tests.csproj
  82. +78 −78 ...cs → SampleApplication/FluentSecurity.SampleApplication.Tests/SecurityConfigurationTestsStyle1.cs
  83. +51 −51 ...cs → SampleApplication/FluentSecurity.SampleApplication.Tests/SecurityConfigurationTestsStyle2.cs
  84. +4 −0 SampleApplication/FluentSecurity.SampleApplication.Tests/packages.config
  85. +15 −15 { → SampleApplication}/FluentSecurity.SampleApplication/AdministratorPolicy.cs
  86. 0 ...mpleApplication}/FluentSecurity.SampleApplication/Areas/ExampleArea/Controllers/HomeController.cs
  87. +1 −1 ...pleApplication}/FluentSecurity.SampleApplication/Areas/ExampleArea/ExampleAreaAreaRegistration.cs
  88. +15 −0 SampleApplication/FluentSecurity.SampleApplication/Areas/ExampleArea/ExampleAreaProfile.cs
  89. 0 ...pplication}/FluentSecurity.SampleApplication/Areas/ExampleArea/Views/Home/AdministratorsOnly.aspx
  90. 0 { → SampleApplication}/FluentSecurity.SampleApplication/Areas/ExampleArea/Views/Home/Index.aspx
  91. 0 ...pleApplication}/FluentSecurity.SampleApplication/Areas/ExampleArea/Views/Home/PublishersOnly.aspx
  92. 0 { → SampleApplication}/FluentSecurity.SampleApplication/Areas/ExampleArea/Views/Web.config
  93. +48 −47 { → SampleApplication}/FluentSecurity.SampleApplication/Bootstrapper.cs
  94. +42 −42 { → SampleApplication}/FluentSecurity.SampleApplication/Controllers/AccountController.cs
  95. +27 −27 { → SampleApplication}/FluentSecurity.SampleApplication/Controllers/AdminController.cs
  96. 0 { → SampleApplication}/FluentSecurity.SampleApplication/Controllers/BlogPostController.cs
  97. 0 { → SampleApplication}/FluentSecurity.SampleApplication/Controllers/CrudController.cs
  98. +31 −31 { → SampleApplication}/FluentSecurity.SampleApplication/Controllers/ExampleController.cs
  99. +16 −16 { → SampleApplication}/FluentSecurity.SampleApplication/Controllers/HomeController.cs
  100. +18 −0 SampleApplication/FluentSecurity.SampleApplication/CrudControllerProfile.cs
  101. +1 −1 { → SampleApplication}/FluentSecurity.SampleApplication/Default.aspx
  102. +21 −21 { → SampleApplication}/FluentSecurity.SampleApplication/Default.aspx.cs
  103. +13 −13 { → SampleApplication}/FluentSecurity.SampleApplication/DefaultPolicyViolationHandler.cs
  104. +163 −162 { → SampleApplication}/FluentSecurity.SampleApplication/FluentSecurity.SampleApplication.csproj
  105. +1 −1 { → SampleApplication}/FluentSecurity.SampleApplication/Global.asax
  106. +47 −47 { → SampleApplication}/FluentSecurity.SampleApplication/Global.asax.cs
  107. +79 −79 { → SampleApplication}/FluentSecurity.SampleApplication/Helpers/HtmlExtensions.cs
  108. +22 −22 { → SampleApplication}/FluentSecurity.SampleApplication/Helpers/MvcExtensions.cs
  109. +32 −32 { → SampleApplication}/FluentSecurity.SampleApplication/Helpers/SecurityHelper.cs
  110. +19 −19 { → SampleApplication}/FluentSecurity.SampleApplication/Helpers/TagBuilderExtensions.cs
  111. +43 −43 { → SampleApplication}/FluentSecurity.SampleApplication/Helpers/UrlExtensions.cs
  112. +6 −6 { → SampleApplication}/FluentSecurity.SampleApplication/IRouteRegistrar.cs
  113. +6 −6 { → SampleApplication}/FluentSecurity.SampleApplication/Models/HomeView.cs
  114. +8 −8 { → SampleApplication}/FluentSecurity.SampleApplication/Models/IUser.cs
  115. +13 −13 { → SampleApplication}/FluentSecurity.SampleApplication/Models/User.cs
  116. +7 −7 { → SampleApplication}/FluentSecurity.SampleApplication/Models/UserRole.cs
  117. +26 −26 { → SampleApplication}/FluentSecurity.SampleApplication/RouteRegistrar.cs
  118. +20 −20 { → SampleApplication}/FluentSecurity.SampleApplication/SessionContext.cs
  119. +140 −140 { → SampleApplication}/FluentSecurity.SampleApplication/Skins/Default/Styles/Main.css
  120. +11 −11 { → SampleApplication}/FluentSecurity.SampleApplication/Views/Example/DenyAnonymousAccess.aspx
  121. +11 −11 { → SampleApplication}/FluentSecurity.SampleApplication/Views/Example/DenyAuthenticatedAccess.aspx
  122. +8 −8 { → SampleApplication}/FluentSecurity.SampleApplication/Views/Example/MissingConfiguration.aspx
  123. +11 −11 { → SampleApplication}/FluentSecurity.SampleApplication/Views/Example/RequireAdministratorRole.aspx
  124. +11 −11 { → SampleApplication}/FluentSecurity.SampleApplication/Views/Example/RequirePublisherRole.aspx
  125. +31 −31 { → SampleApplication}/FluentSecurity.SampleApplication/Views/Home/Index.aspx
  126. +6 −6 { → SampleApplication}/FluentSecurity.SampleApplication/Views/Shared/AccessDenied.aspx
  127. +30 −30 { → SampleApplication}/FluentSecurity.SampleApplication/Views/Shared/Site.Master
  128. +33 −33 { → SampleApplication}/FluentSecurity.SampleApplication/Views/Web.config
  129. +77 −77 { → SampleApplication}/FluentSecurity.SampleApplication/Web.config
View
@@ -27,4 +27,5 @@ _ReSharper*/
*.resharper
[Tt]est[Rr]esult*
NCover*.lic
-FluentSecurity.*.dotCover
+*.*.dotCover
+*.DotSettings
@@ -38,7 +38,7 @@
-->
<property name="build.number" value="0" />
<property name="project.version.number" value="2.0.0.${build.number}" />
- <property name="project.version.label" value="2.0.0-alpha3" /><!-- Example: 1.0.0-beta1 -->
+ <property name="project.version.label" value="2.0.0-alpha4" /><!-- Example: 1.0.0-beta1 -->
<property name="project.version.label" value="${project.version.label}-build${build.number}" if="${build.number != '0'}" />
<property name="project.config" value="release" />
View
@@ -9,6 +9,8 @@
- ( **Removed** ) Removed PolicyViolationException\<TSecurityPolicy\> as exceptions should be created based on PolicyResult.
- ( **Removed** ) Removed PolicyExecutionMode and changed the default policy execution behavior to "stop on first violation".
- ( **Removed** ) Removed PolicyAppender property from IPolicyContainer interface as it's not really useful to anyone.
+- ( **Change** ) Created RequireAnyRolePolicy and marked RequireRolePolicy as deprecated.
+- ( **Change** ) Created RequireAnyRole extension and marked RequireRole extension as deprecated.
- ( **Change** ) Moved IgnoreMissingConfiguration option to Advanced property.
- ( **Change** ) Method HandleSecurityFor on ISecurityHandler now takes an instance of ISecurityContext as the last parameter.
- ( **Change** ) Moved SecurityContextWrapper to the FluentSecurity.Policy.Contexts namespace.
@@ -19,12 +21,21 @@
- ( **Change** ) Changed policy extensions so that they extend IPolicyContainerConfiguration instead of IPolicyContainer and IConventionPolicyContainer.
- ( **Change** ) Moved IWhatDoIHaveBuilder and DefaultWhatDoIHaveBuilder to Diagnostics namespace.
- ( **Change** ) Moved DefaultPolicyAppender to Configuration namespace.
+- ( **Change** ) Moved ITypeScanner interface to Scanning.TypeScanners namespace.
+- ( **Change** ) Added ISecurityRuntime property to ISecurityContext.
- ( **New** ) Added support for using AllowAny to add an IgnorePolicy.
- ( **New** ) Added support for using ActionNameAttribute (thanks to Chandu).
+- ( **New** ) Added HttpUnauthorizedPolicyViolationHandler for returning standard mvc HttpUnauthorizedResult.
- ( **New** ) Added support for securing controllers based on inheritance - Base controllers (thanks to Ridermansb).
- ( **New** ) Added support for securing controllers based on action name and controller type.
+- ( **New** ) Made ISecurityContext available for violation handlers through the SecurityContext property of PolicyViolationException.
- ( **New** ) Exposed conventions through Conventions property on IAdvancedConfiguration and AdvancedConfiguration.
+## Areas/Profiles
+- ( **New** ) Added support for creating profiles to help manage large/area configurations by inheriting from SecurityProfile.
+- ( **New** ) Added support for applying profiles using ApplyProfile\<TSecurityProfile\>.
+- ( **New** ) Added support for scanning for profiles using the Scan method and LookForProfiles.
+
## Caching
- ( **New** ) Added support for changing the default cache lifecycle of policy results using the Advanced.SetDefaultResultsCacheLifecycle option.
- ( **New** ) Added support for providing custom cache keys for policies using the ICacheKeyProvider interface.
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
- <package id="NUnit" version="2.6.0.12054" />
-</packages>
@@ -22,7 +22,7 @@ protected static void Because(Action<ConfigurationExpression> configurationExpre
private static void AssertAllControllerActionsHasContainer(ConfigurationExpression configurationExpression)
{
- var policyContainers = configurationExpression.PolicyContainers;
+ var policyContainers = configurationExpression.Runtime.PolicyContainers;
Assert.That(policyContainers.Count(), Is.EqualTo(21));
var blog = NameHelper.Controller<BlogController>();
@@ -13,7 +13,7 @@ protected static void Because(Action<ConfigurationExpression> configurationExpre
PolicyContainers = Enumerable.Empty<IPolicyContainer>();
var expression = TestDataFactory.CreateValidConfigurationExpression();
configurationExpression(expression);
- PolicyContainers = expression.PolicyContainers;
+ PolicyContainers = expression.Runtime.PolicyContainers;
}
protected static IEnumerable<IPolicyContainer> PolicyContainers { get; private set; }
@@ -14,36 +14,41 @@ namespace FluentSecurity.Specification.Configuration
[Category("AdvancedConfigurationSpec")]
public class When_creating_a_new_advanced_configuration
{
- private AdvancedConfiguration _advancedConfiguration;
-
- [SetUp]
- public void SetUp()
- {
- _advancedConfiguration = new AdvancedConfiguration();
- }
-
[Test]
- public void Should_not_ignore_missing_configurations()
+ public void Should_throw_when_model_is_null()
{
- Assert.That(_advancedConfiguration.ShouldIgnoreMissingConfiguration, Is.False);
+ Assert.Throws<ArgumentNullException>(() => new AdvancedConfiguration(null));
}
[Test]
- public void Should_have_default_policy_cache_lifecycle_set_to_DoNotCache()
+ public void Should_have_conventions_for_default_PolicyViolationHandler_applied()
{
- Assert.That(_advancedConfiguration.DefaultResultsCacheLifecycle, Is.EqualTo(Cache.DoNotCache));
- }
+ // Arrange
+ var securityModel = new SecurityRuntime();
- [Test]
- public void Should_not_have_a_security_context_modifyer()
- {
- Assert.That(_advancedConfiguration.SecurityContextModifyer, Is.Null);
+ // Act
+ new AdvancedConfiguration(securityModel);
+
+ // Assert
+ var conventions = securityModel.Conventions.OfType<IPolicyViolationHandlerConvention>().ToList();
+ Assert.That(conventions.Count(), Is.EqualTo(2));
+ Assert.That(conventions.ElementAtOrDefault(0), Is.TypeOf<FindByPolicyNameConvention>());
+ Assert.That(conventions.ElementAtOrDefault(1), Is.TypeOf<FindDefaultPolicyViolationHandlerByNameConvention>());
}
[Test]
- public void Should_have_conventions_for_default_PolicyViolationHandler_applied()
+ public void Should_not_add_duplicate_conventions()
{
- var conventions = _advancedConfiguration.Conventions.OfType<IPolicyViolationHandlerConvention>().ToList();
+ // Arrange
+ var securityModel = new SecurityRuntime();
+ new AdvancedConfiguration(securityModel);
+
+ // Act
+ new AdvancedConfiguration(securityModel);
+
+ // Assert
+ var conventions = securityModel.Conventions.OfType<IPolicyViolationHandlerConvention>().ToList();
+ Assert.That(conventions.Count(), Is.EqualTo(2));
Assert.That(conventions.ElementAtOrDefault(0), Is.TypeOf<FindByPolicyNameConvention>());
Assert.That(conventions.ElementAtOrDefault(1), Is.TypeOf<FindDefaultPolicyViolationHandlerByNameConvention>());
}
@@ -57,13 +62,14 @@ public class When_ignoring_missing_configuration
public void Should_ignore_missing_configurations()
{
// Arrange
- var advancedConfiguration = new AdvancedConfiguration();
+ var model = new SecurityRuntime();
+ var advancedConfiguration = new AdvancedConfiguration(model);
// Act
advancedConfiguration.IgnoreMissingConfiguration();
// Assert
- Assert.That(advancedConfiguration.ShouldIgnoreMissingConfiguration, Is.True);
+ Assert.That(model.ShouldIgnoreMissingConfiguration, Is.True);
}
}
@@ -75,39 +81,105 @@ public class When_setting_the_default_policy_results_cache_lifecycle
public void Should_have_default_policy_cache_lifecycle_set_to_PerHttpSession()
{
// Arrange
- var advancedConfiguration = new AdvancedConfiguration();
+ var model = new SecurityRuntime();
+ var advancedConfiguration = new AdvancedConfiguration(model);
// Act
advancedConfiguration.SetDefaultResultsCacheLifecycle(Cache.PerHttpSession);
// Assert
- Assert.That(advancedConfiguration.DefaultResultsCacheLifecycle, Is.EqualTo(Cache.PerHttpSession));
+ Assert.That(model.DefaultResultsCacheLifecycle, Is.EqualTo(Cache.PerHttpSession));
}
[Test]
public void Should_have_default_policy_cache_lifecycle_set_to_PerHttpRequest()
{
// Arrange
- var advancedConfiguration = new AdvancedConfiguration();
+ var model = new SecurityRuntime();
+ var advancedConfiguration = new AdvancedConfiguration(model);
// Act
advancedConfiguration.SetDefaultResultsCacheLifecycle(Cache.PerHttpRequest);
// Assert
- Assert.That(advancedConfiguration.DefaultResultsCacheLifecycle, Is.EqualTo(Cache.PerHttpRequest));
+ Assert.That(model.DefaultResultsCacheLifecycle, Is.EqualTo(Cache.PerHttpRequest));
}
[Test]
public void Should_have_default_policy_cache_lifecycle_set_to_DoNotCache()
{
// Arrange
- var advancedConfiguration = new AdvancedConfiguration();
+ var model = new SecurityRuntime();
+ var advancedConfiguration = new AdvancedConfiguration(model);
// Act
advancedConfiguration.SetDefaultResultsCacheLifecycle(Cache.DoNotCache);
// Assert
- Assert.That(advancedConfiguration.DefaultResultsCacheLifecycle, Is.EqualTo(Cache.DoNotCache));
+ Assert.That(model.DefaultResultsCacheLifecycle, Is.EqualTo(Cache.DoNotCache));
+ }
+ }
+
+ [TestFixture]
+ [Category("AdvancedConfigurationSpec")]
+ public class When_modifying_conventions_using_advanced_configuration
+ {
+ [Test]
+ public void Should_throw_when_action_is_null()
+ {
+ // Arrange
+ var model = new SecurityRuntime();
+ var advancedConfiguration = new AdvancedConfiguration(model);
+
+ // Act & Assert
+ Assert.Throws<ArgumentNullException>(() => advancedConfiguration.Conventions(null));
+ }
+
+ [Test]
+ public void Should_add_convention()
+ {
+ // Arrange
+ var model = new SecurityRuntime();
+ var advancedConfiguration = new AdvancedConfiguration(model);
+ var expectedConvention = new MockConvention();
+
+ // Act
+ advancedConfiguration.Conventions(conventions => conventions.Add(expectedConvention));
+
+ // Assert
+ Assert.That(model.Conventions.Contains(expectedConvention), Is.True);
+ }
+
+ [Test]
+ public void Should_remove_convention()
+ {
+ // Arrange
+ var model = new SecurityRuntime();
+ var advancedConfiguration = new AdvancedConfiguration(model);
+ var convention = new MockConvention();
+ advancedConfiguration.Conventions(conventions => conventions.Add(convention));
+ Assert.That(model.Conventions.Contains(convention), Is.True);
+
+ // Act
+ advancedConfiguration.Conventions(conventions => conventions.Remove(convention));
+
+ // Assert
+ Assert.That(model.Conventions.Contains(convention), Is.False);
+ }
+
+ [Test]
+ public void Should_remove_matching_convention()
+ {
+ // Arrange
+ var model = new SecurityRuntime();
+ var advancedConfiguration = new AdvancedConfiguration(model);
+ Assert.That(model.Conventions.Any(c => c is FindByPolicyNameConvention), Is.True);
+
+ // Act
+ advancedConfiguration.Conventions(conventions => conventions.RemoveAll(c => c is FindByPolicyNameConvention));
+
+ // Assert
+ Assert.That(model.Conventions.Any(c => c is FindByPolicyNameConvention), Is.False);
}
}
@@ -138,7 +210,7 @@ public void SetUp()
[Test]
public void Should_set_the_modifyer()
{
- Assert.That(SecurityConfiguration.Current.Advanced.SecurityContextModifyer, Is.EqualTo(_expectedModifyer));
+ Assert.That(SecurityConfiguration.Current.Runtime.SecurityContextModifyer, Is.EqualTo(_expectedModifyer));
}
[Test]
@@ -161,12 +233,14 @@ public void Should_modify_context_on_creation()
[Category("AdvancedConfigurationSpec")]
public class When_specifying_how_violations_are_handled
{
+ private SecurityRuntime _runtime;
private AdvancedConfiguration _advancedConfiguration;
[SetUp]
public void SetUp()
{
- _advancedConfiguration = new AdvancedConfiguration();
+ _runtime = new SecurityRuntime();
+ _advancedConfiguration = new AdvancedConfiguration(_runtime);
}
[Test]
@@ -187,9 +261,9 @@ public void Should_always_add_conventions_at_the_first_position_to_support_casca
});
// Assert
- Assert.That(_advancedConfiguration.Conventions.ElementAt(0).As<Convention>().ExpectedIndex, Is.EqualTo(0));
- Assert.That(_advancedConfiguration.Conventions.ElementAt(1).As<Convention>().ExpectedIndex, Is.EqualTo(1));
- Assert.That(_advancedConfiguration.Conventions.ElementAt(2).As<Convention>().ExpectedIndex, Is.EqualTo(2));
+ Assert.That(_runtime.Conventions.ElementAt(0).As<Convention>().ExpectedIndex, Is.EqualTo(0));
+ Assert.That(_runtime.Conventions.ElementAt(1).As<Convention>().ExpectedIndex, Is.EqualTo(1));
+ Assert.That(_runtime.Conventions.ElementAt(2).As<Convention>().ExpectedIndex, Is.EqualTo(2));
}
[Test]
@@ -199,7 +273,7 @@ public void Should_add_convention_for_IgnorePolicy_and_Handler1()
_advancedConfiguration.Violations(violations => violations.Of<IgnorePolicy>().IsHandledBy<Handler1>());
// Assert
- Assert.That(_advancedConfiguration.Conventions.First(), Is.InstanceOf<PolicyTypeToPolicyViolationHandlerTypeConvention<IgnorePolicy, Handler1>>());
+ Assert.That(_runtime.Conventions.First(), Is.InstanceOf<PolicyTypeToPolicyViolationHandlerTypeConvention<IgnorePolicy, Handler1>>());
}
[Test]
@@ -209,7 +283,7 @@ public void Should_add_convention_for_IgnorePolicy_and_Handler2()
_advancedConfiguration.Violations(violations => violations.Of<IgnorePolicy>().IsHandledBy(() => new Handler2()));
// Assert
- Assert.That(_advancedConfiguration.Conventions.First(), Is.InstanceOf<PolicyTypeToPolicyViolationHandlerInstanceConvention<IgnorePolicy, Handler2>>());
+ Assert.That(_runtime.Conventions.First(), Is.InstanceOf<PolicyTypeToPolicyViolationHandlerInstanceConvention<IgnorePolicy, Handler2>>());
}
public class Convention : IPolicyViolationHandlerConvention
@@ -197,6 +197,46 @@ public void Should_add_RequireRolePolicy()
[TestFixture]
[Category("DefaultPolicyAppenderSpec")]
+ public class When_updating_policies_with_a_RequireAnyRolePolicy : with_DefaultPolicyAppender
+ {
+ private RequireAnyRolePolicy _requireAnyRolePolicy;
+ private DenyAnonymousAccessPolicy _denyAnonymousAccessPolicy;
+
+ protected override void Context()
+ {
+ // Arrange
+ _requireAnyRolePolicy = new RequireAnyRolePolicy("Administrator");
+ _denyAnonymousAccessPolicy = new DenyAnonymousAccessPolicy();
+ Policies = new List<ISecurityPolicy>
+ {
+ _denyAnonymousAccessPolicy
+ };
+ }
+
+ [Test]
+ public void Should_remove_all_existing_policies()
+ {
+ // Act
+ PolicyAppender.UpdatePolicies(_requireAnyRolePolicy, Policies);
+
+ // Assert
+ Assert.That(Policies.Contains(_denyAnonymousAccessPolicy), Is.False);
+ Assert.That(Policies.Count, Is.EqualTo(1));
+ }
+
+ [Test]
+ public void Should_add_RequireAnyRolePolicy()
+ {
+ // Act
+ PolicyAppender.UpdatePolicies(_requireAnyRolePolicy, Policies);
+
+ // Assert
+ Assert.That(Policies.Contains(_requireAnyRolePolicy), Is.True);
+ }
+ }
+
+ [TestFixture]
+ [Category("DefaultPolicyAppenderSpec")]
public class When_updating_policies_with_a_RequireAllRolesPolicy : with_DefaultPolicyAppender
{
private RequireAllRolesPolicy _requireAllRolesPolicy;
@@ -225,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);
Oops, something went wrong.

0 comments on commit 363f7e5

Please sign in to comment.