Exemplo n.º 1
0
        public void Should_return_the_current_configuration()
        {
            const string expectedOutput = @"Ignore missing configuration: True

------------------------------------------------------------------------------------

FluentSecurity.Specification.TestData.BlogController > DeletePost
	FluentSecurity.Policy.RequireAnyRolePolicy (Owner or Publisher)

FluentSecurity.Specification.TestData.BlogController > Index
	FluentSecurity.Policy.DenyAnonymousAccessPolicy

------------------------------------------------------------------------------------";

            var securityConfiguration = new SecurityConfiguration(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                configuration.Advanced.IgnoreMissingConfiguration();
                configuration.For <BlogController>(x => x.DeletePost(0)).DenyAnonymousAccess().RequireAnyRole(UserRole.Owner, UserRole.Publisher);
                configuration.For <BlogController>(x => x.Index()).DenyAnonymousAccess();
            });

            SecurityConfigurator.SetConfiguration(securityConfiguration);

            // Act
            var whatIHave = securityConfiguration.WhatDoIHave();

            // Assert
            Assert.That(whatIHave, Is.EqualTo(expectedOutput));
        }
Exemplo n.º 2
0
        public void Should_return_the_current_configuration()
        {
            var baseDirectory  = AppDomain.CurrentDomain.BaseDirectory;
            var fullFilePath   = Path.Combine(baseDirectory, "TestData", "DiagnosticsOutputExample.txt");
            var expectedOutput = File.ReadAllText(fullFilePath);

            var securityConfiguration = new SecurityConfiguration(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                configuration.IgnoreMissingConfiguration();
                configuration.For <BlogController>(x => x.DeletePost(0)).DenyAnonymousAccess().RequireRole(UserRole.Owner, UserRole.Publisher);
                configuration.For <BlogController>(x => x.Index()).DenyAnonymousAccess();
            });

            SecurityConfigurator.SetConfiguration(securityConfiguration);

            // Act
            var whatIHave = securityConfiguration.WhatDoIHave();

            // Assert
            Assert.That(whatIHave, Is.EqualTo(expectedOutput));
        }
        public void Should_return_the_current_configuration()
        {
            var securityConfiguration = new SecurityConfiguration(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                configuration.IgnoreMissingConfiguration();
                configuration.For<BlogController>(x => x.DeletePost(0)).DenyAnonymousAccess().RequireRole(UserRole.Owner, UserRole.Publisher);
                configuration.For<BlogController>(x => x.Index()).DenyAnonymousAccess();
            });

            // Act
            var whatIHave = securityConfiguration.WhatDoIHave();

            // Assert
            Assert.That(whatIHave.Replace("\r\n", "|").Replace("\t", "%"), Is.EqualTo("Ignore missing configuration: True||------------------------------------------------------------------------------------|BlogController > DeletePost|%FluentSecurity.Policy.RequireRolePolicy (Owner or Publisher)|BlogController > Index|%FluentSecurity.Policy.DenyAnonymousAccessPolicy|------------------------------------------------------------------------------------"));
        }
        public void Should_return_the_current_configuration()
        {
            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var fullFilePath = Path.Combine(baseDirectory, "TestData", "DiagnosticsOutputExample.txt");
            var expectedOutput = File.ReadAllText(fullFilePath);

            var securityConfiguration = new SecurityConfiguration(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                configuration.IgnoreMissingConfiguration();
                configuration.For<BlogController>(x => x.DeletePost(0)).DenyAnonymousAccess().RequireRole(UserRole.Owner, UserRole.Publisher);
                configuration.For<BlogController>(x => x.Index()).DenyAnonymousAccess();
            });

            SecurityConfigurator.SetConfiguration(securityConfiguration);

            // Act
            var whatIHave = securityConfiguration.WhatDoIHave();

            // Assert
            Assert.That(whatIHave, Is.EqualTo(expectedOutput));
        }
        public void Should_return_the_current_configuration()
        {
            const string expectedOutput = @"Ignore missing configuration: True

            ------------------------------------------------------------------------------------

            FluentSecurity.Specification.TestData.BlogController > DeletePost
            FluentSecurity.Policy.RequireAnyRolePolicy (Owner or Publisher)

            FluentSecurity.Specification.TestData.BlogController > Index
            FluentSecurity.Policy.DenyAnonymousAccessPolicy

            ------------------------------------------------------------------------------------";

            var securityConfiguration = new SecurityConfiguration(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                configuration.Advanced.IgnoreMissingConfiguration();
                configuration.For<BlogController>(x => x.DeletePost(0)).DenyAnonymousAccess().RequireAnyRole(UserRole.Owner, UserRole.Publisher);
                configuration.For<BlogController>(x => x.Index()).DenyAnonymousAccess();
            });

            SecurityConfigurator.SetConfiguration(securityConfiguration);

            // Act
            var whatIHave = securityConfiguration.WhatDoIHave();

            // Assert
            Assert.That(whatIHave, Is.EqualTo(expectedOutput));
        }