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),
                f => Assert.IsType <HandleOptionsRequestsPageFilter>(f));
        }
Ejemplo n.º 2
0
        public void OnProvidersExecuting_AddsAuthorizeFilter_IfModelHasAuthorizationAttributes()
        {
            // Arrange
            var policyProvider        = new DefaultAuthorizationPolicyProvider(Options.Create(new AuthorizationOptions()));
            var authorizationProvider = new AuthorizationPageApplicationModelProvider(policyProvider, OptionsWithoutEndpointRouting);
            var context = GetApplicationProviderContext(typeof(TestPage).GetTypeInfo());

            // Act
            authorizationProvider.OnProvidersExecuting(context);

            // Assert
            Assert.Collection(
                context.PageApplicationModel.Filters,
                f => Assert.IsType <PageHandlerPageFilter>(f),
                f => Assert.IsType <HandleOptionsRequestsPageFilter>(f),
                f => Assert.IsType <AuthorizeFilter>(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));
        }