public void OnProvidersExecuting_CollatesAttributesFromInheritedTypes() { // Arrange var options = Options.Create(new 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 authorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider); var context = GetApplicationProviderContext(typeof(TestPageWithDerivedModel).GetTypeInfo()); // Act authorizationProvider.OnProvidersExecuting(context); // Assert AuthorizeFilter authorizeFilter = null; Assert.Collection( context.PageApplicationModel.Filters, f => Assert.IsType <PageHandlerPageFilter>(f), f => Assert.IsType <HandleOptionsRequestsPageFilter>(f), f => authorizeFilter = Assert.IsType <AuthorizeFilter>(f)); // Basic + Basic2 + Derived authorize Assert.Equal(3, authorizeFilter.Policy.Requirements.Count); }
public void OnProvidersExecuting_IgnoresAttributesOnHandlerMethods() { // Arrange var policyProvider = new DefaultAuthorizationPolicyProvider(new TestOptionsManager <AuthorizationOptions>()); var autorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider); var typeInfo = typeof(PageWithAuthorizeHandlers).GetTypeInfo(); var context = GetApplicationProviderContext(typeInfo); // Act autorizationProvider.OnProvidersExecuting(context); // Assert Assert.Empty(context.PageApplicationModel.Filters); }
public void OnProvidersExecuting_AddsAuthorizeFilter_IfModelHasAuthorizationAttributes() { // Arrange var policyProvider = new DefaultAuthorizationPolicyProvider(new TestOptionsManager <AuthorizationOptions>()); var autorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider); var context = GetApplicationProviderContext(typeof(TestPage).GetTypeInfo()); // Act autorizationProvider.OnProvidersExecuting(context); // Assert Assert.Collection( context.PageApplicationModel.Filters, f => Assert.IsType <AuthorizeFilter>(f)); }
public void OnProvidersExecuting_AddsAllowAnonymousFilter() { // Arrange var policyProvider = new DefaultAuthorizationPolicyProvider(new TestOptionsManager <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 <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_AddsAllowAnonymousFilter() { // Arrange var policyProvider = new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions())); var authorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider); var context = GetApplicationProviderContext(typeof(PageWithAnonymousModel).GetTypeInfo()); // Act authorizationProvider.OnProvidersExecuting(context); // Assert Assert.Collection( context.PageApplicationModel.Filters, f => Assert.IsType <PageHandlerPageFilter>(f), f => Assert.IsType <HandleOptionsRequestsPageFilter>(f), f => Assert.IsType <AllowAnonymousFilter>(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); }