Esempio n. 1
0
        public void OnProvidersExecuting_AddsAllowAnonymousFilter()
        {
            // Arrange
            var policyProvider       = new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions()));
            var autorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider);
            var context = GetApplicationProviderContext(typeof(PageWithAnonymousModel).GetTypeInfo());

            // Act
            autorizationProvider.OnProvidersExecuting(context);

            // Assert
            Assert.Collection(
                context.PageApplicationModel.Filters,
                f => Assert.IsType <PageHandlerPageFilter>(f),
                f => Assert.IsType <AllowAnonymousFilter>(f));
        }
        public void OnProvidersExecuting_IgnoresAttributesOnHandlerMethods()
        {
            // Arrange
            var policyProvider        = new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions()));
            var authorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider);
            var typeInfo = typeof(PageWithAuthorizeHandlers).GetTypeInfo();
            var context  = GetApplicationProviderContext(typeInfo);

            // Act
            authorizationProvider.OnProvidersExecuting(context);

            // Assert
            Assert.Collection(
                context.PageApplicationModel.Filters,
                f => Assert.IsType <PageHandlerPageFilter>(f));
        }
        public void OnProvidersExecuting_AddsAuthorizeFilter_IfModelHasAuthorizationAttributes()
        {
            // Arrange
            var policyProvider        = new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions()));
            var authorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider);
            var context = GetApplicationProviderContext(typeof(TestPage).GetTypeInfo());

            // Act
            authorizationProvider.OnProvidersExecuting(context);

            // Assert
            Assert.Collection(
                context.PageApplicationModel.Filters,
                f => Assert.IsType <PageHandlerPageFilter>(f),
                f => Assert.IsType <AuthorizeFilter>(f));
        }
        public void OnProvidersExecuting_CollatesAttributesFromInheritedTypes()
        {
            // Arrange
            var options = new TestOptionsManager <AuthorizationOptions>();

            options.Value.AddPolicy("Base", policy => policy.RequireClaim("Basic").RequireClaim("Basic2"));
            options.Value.AddPolicy("Derived", policy => policy.RequireClaim("Derived"));

            var policyProvider       = new DefaultAuthorizationPolicyProvider(options);
            var autorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider);

            var context = GetApplicationProviderContext(typeof(TestPageWithDerivedModel).GetTypeInfo());

            // Act
            autorizationProvider.OnProvidersExecuting(context);

            // Assert
            var authorizeFilter = Assert.IsType <AuthorizeFilter>(Assert.Single(context.PageApplicationModel.Filters));

            // Basic + Basic2 + Derived authorize
            Assert.Equal(3, authorizeFilter.Policy.Requirements.Count);
        }