public void CreateControllerModel_CustomCorsFilter_ReplacesHttpConstraints() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var context = GetProviderContext(typeof(CustomCorsFilterController)); // Act corsProvider.OnProvidersExecuting(context); // Assert var controller = Assert.Single(context.Result.Controllers); var action = Assert.Single(controller.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); }
public void CreateControllerModel_CorsNotInUseDoesNotOverrideHttpConstraints() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var context = GetProviderContext(typeof(RegularController)); // Act corsProvider.OnProvidersExecuting(context); // Assert var model = Assert.Single(context.Result.Controllers); var action = Assert.Single(model.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsNotType <CorsHttpMethodActionConstraint>(constraint); }
public void CreateControllerModel_DisableCorsAttributeAddsDisableCorsAuthorizationFilter() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager <MvcOptions>()); var context = new ApplicationModelProviderContext(new[] { typeof(DisableCorsController).GetTypeInfo() }); defaultProvider.OnProvidersExecuting(context); // Act corsProvider.OnProvidersExecuting(context); // Assert var model = Assert.Single(context.Result.Controllers); Assert.Single(model.Filters, f => f is DisableCorsAuthorizationFilter); }
public void BuildActionModel_EnableCorsAttributeAddsCorsAuthorizationFilterFactory() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var context = GetProviderContext(typeof(EnableCorsController)); // Act corsProvider.OnProvidersExecuting(context); // Assert var controller = Assert.Single(context.Result.Controllers); var action = Assert.Single(controller.Actions); Assert.Single(action.Filters, f => f is CorsAuthorizationFilterFactory); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); }
public void CreateControllerModel_DisableCorsGloballyReplacesHttpMethodConstraints() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var context = GetProviderContext(typeof(RegularController)); context.Result.Filters.Add(new DisableCorsAuthorizationFilter()); // Act corsProvider.OnProvidersExecuting(context); // Assert var model = Assert.Single(context.Result.Controllers); var action = Assert.Single(model.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); }
public void BuildActionModel_EnableCorsAttributeAddsCorsAuthorizationFilterFactory() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager <MvcOptions>()); var context = new ApplicationModelProviderContext(new[] { typeof(EnableCorsController).GetTypeInfo() }); defaultProvider.OnProvidersExecuting(context); // Act corsProvider.OnProvidersExecuting(context); // Assert var controller = Assert.Single(context.Result.Controllers); var action = Assert.Single(controller.Actions); Assert.Single(action.Filters, f => f is CorsAuthorizationFilterFactory); }
public void CreateControllerModel_CustomCorsFilter_EnablesCorsPreflight() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var context = GetProviderContext(typeof(CustomCorsFilterController)); // Act corsProvider.OnProvidersExecuting(context); // Assert var controller = Assert.Single(context.Result.Controllers); var action = Assert.Single(controller.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); var httpMethodMetadata = Assert.Single(selector.EndpointMetadata.OfType <HttpMethodMetadata>()); Assert.True(httpMethodMetadata.AcceptCorsPreflight); }
public void BuildActionModel_CustomCorsAuthorizationFilterOnAction_ReplacesHttpConstraints() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions())); var context = new ApplicationModelProviderContext(new[] { typeof(CustomCorsFilterOnActionController).GetTypeInfo() }); defaultProvider.OnProvidersExecuting(context); // Act corsProvider.OnProvidersExecuting(context); // Assert var controller = Assert.Single(context.Result.Controllers); var action = Assert.Single(controller.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); }
public void CreateControllerModel_CorsNotInUseDoesNotOverrideHttpConstraints() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager <MvcOptions>()); var context = new ApplicationModelProviderContext(new[] { typeof(RegularController).GetTypeInfo() }); defaultProvider.OnProvidersExecuting(context); // Act corsProvider.OnProvidersExecuting(context); // Assert var model = Assert.Single(context.Result.Controllers); var action = Assert.Single(model.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsNotType <CorsHttpMethodActionConstraint>(constraint); }
public void CreateControllerModel_CustomCorsFilterGloballyReplacesHttpMethodConstraints() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions())); var context = new ApplicationModelProviderContext(new[] { typeof(RegularController).GetTypeInfo() }); context.Result.Filters.Add(new CustomCorsFilterAttribute()); defaultProvider.OnProvidersExecuting(context); // Act corsProvider.OnProvidersExecuting(context); // Assert var model = Assert.Single(context.Result.Controllers); var action = Assert.Single(model.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); }
public void CreateControllerModel_EnableCorsGloballyReplacesHttpMethodConstraints() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager <MvcOptions>()); var context = new ApplicationModelProviderContext(new[] { typeof(RegularController).GetTypeInfo() }); context.Result.Filters.Add(new CorsAuthorizationFilter(Mock.Of <ICorsService>(), Mock.Of <ICorsPolicyProvider>())); defaultProvider.OnProvidersExecuting(context); // Act corsProvider.OnProvidersExecuting(context); // Assert var model = Assert.Single(context.Result.Controllers); var action = Assert.Single(model.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); }
public void CreateControllerModel_DisableCorsAttributeAddsDisableCorsAuthorizationFilter() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var context = GetProviderContext(typeof(DisableCorsController)); // Act corsProvider.OnProvidersExecuting(context); // Assert var model = Assert.Single(context.Result.Controllers); Assert.Single(model.Filters, f => f is DisableCorsAuthorizationFilter); var action = Assert.Single(model.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); var httpMethodMetadata = Assert.Single(selector.EndpointMetadata.OfType <HttpMethodMetadata>()); Assert.True(httpMethodMetadata.AcceptCorsPreflight); }
public void CreateControllerModel_DisableCorsAttributeAddsDisableCorsAuthorizationFilter() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var defaultProvider = new DefaultApplicationModelProvider(Options.Create(new MvcOptions())); var context = new ApplicationModelProviderContext(new[] { typeof(DisableCorsController).GetTypeInfo() }); defaultProvider.OnProvidersExecuting(context); // Act corsProvider.OnProvidersExecuting(context); // Assert var model = Assert.Single(context.Result.Controllers); Assert.Single(model.Filters, f => f is DisableCorsAuthorizationFilter); var action = Assert.Single(model.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); }
public void BuildActionModel_DisableCorsAttributeAddsDisableCorsAuthorizationFilter() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager <MvcOptions>()); var context = new ApplicationModelProviderContext(new[] { typeof(DisableCorsActionController).GetTypeInfo() }); defaultProvider.OnProvidersExecuting(context); // Act corsProvider.OnProvidersExecuting(context); // Assert var controller = Assert.Single(context.Result.Controllers); var action = Assert.Single(controller.Actions); Assert.True(action.Filters.Any(f => f is DisableCorsAuthorizationFilter)); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); }
public void CreateControllerModel_EnableCorsGloballyEnablesCorsPreflight() { // Arrange var corsProvider = new CorsApplicationModelProvider(); var context = GetProviderContext(typeof(RegularController)); context.Result.Filters.Add( new CorsAuthorizationFilter(Mock.Of <ICorsService>(), Mock.Of <ICorsPolicyProvider>(), Mock.Of <ILoggerFactory>())); // Act corsProvider.OnProvidersExecuting(context); // Assert var model = Assert.Single(context.Result.Controllers); var action = Assert.Single(model.Actions); var selector = Assert.Single(action.Selectors); var constraint = Assert.Single(selector.ActionConstraints, c => c is HttpMethodActionConstraint); Assert.IsType <CorsHttpMethodActionConstraint>(constraint); var httpMethodMetadata = Assert.Single(selector.EndpointMetadata.OfType <HttpMethodMetadata>()); Assert.True(httpMethodMetadata.AcceptCorsPreflight); }