Exemplo n.º 1
0
        public async void ReturnsFalseForCancelledRequest()
        {
            var context = new ApiRequestContext
            {
                RequestAborted = new CancellationToken(true)
            };

            var processed = await context.ProcessHttpRequestCrossOriginResourceSharingPreflight(null, null, null).ConfigureAwait(false);

            processed.Should().BeFalse();

            context.Response.Should().NotBeNull();
            context.Response.ResponseObject.Should().BeNull();
        }
Exemplo n.º 2
0
        public async void pipeline_preflight__returns_true_and_correct_headers_for_preflight_request(int statusCode)
        {
            var context = new ApiRequestContext
            {
                RequestAborted = new CancellationToken(false),
                Request        = new ApiRequestInfo
                {
                    Method             = "options",
                    CrossOriginRequest = new CrossOriginRequestValues
                    {
                        Origin = "http://ron.vecchi.net",
                        AccessControlRequestMethod  = "POST",
                        AccessControlRequestHeaders = "Content-Type, X-Header"
                    }
                },
                Routing = new ApiRoutingInfo
                {
                    Template = new ApiRoutingTemplate("/test")
                },

                Response = new ApiResponseInfo
                {
                    StatusCode = statusCode
                },
                Configuration = new DeepSleepRequestConfiguration
                {
                    CrossOriginConfig = new ApiCrossOriginConfiguration
                    {
                        AllowedHeaders = new string[] { "Content-Type" }
                    }
                }
            };

            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: "POST"));

            var processed = await context.ProcessHttpRequestCrossOriginResourceSharingPreflight(null, null, null).ConfigureAwait(false);

            processed.Should().BeFalse();
            context.Response.Should().NotBeNull();
            context.Response.ResponseObject.Should().BeNull();
            context.Response.StatusCode.Should().Be(200);

            context.Response.Headers.Should().NotBeNull();
            context.Response.Headers.Should().HaveCount(2);
            context.Response.Headers[0].Name.Should().Be("Access-Control-Allow-Methods");
            context.Response.Headers[0].Value.Should().Be("POST");
            context.Response.Headers[1].Name.Should().Be("Access-Control-Allow-Headers");
            context.Response.Headers[1].Value.Should().Be("Content-Type");
        }
Exemplo n.º 3
0
        public async void pipeline_preflight__returns_true_for_non_options_preflight_request_method(string method)
        {
            var context = new ApiRequestContext
            {
                RequestAborted = new CancellationToken(false),
                Request        = new ApiRequestInfo
                {
                    Method = method
                }
            };

            var processed = await context.ProcessHttpRequestCrossOriginResourceSharingPreflight(null, null, null).ConfigureAwait(false);

            processed.Should().BeTrue();
            context.Response.Should().NotBeNull();
            context.Response.ResponseObject.Should().BeNull();
        }
Exemplo n.º 4
0
        public async void pipeline_preflight__returns_correct_matched_route_templates_allow_methods_for_preflight_request_method(string requestMethod)
        {
            var context = new ApiRequestContext
            {
                RequestAborted = new CancellationToken(false),
                Request        = new ApiRequestInfo
                {
                    Method             = "options",
                    CrossOriginRequest = new CrossOriginRequestValues
                    {
                        Origin = "http://ron.vecchi.net",
                        AccessControlRequestMethod = requestMethod
                    }
                },
                Routing = new ApiRoutingInfo
                {
                    Template = new ApiRoutingTemplate("/test")
                }
            };

            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: "POST"));
            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: "PUT"));
            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: "PUT"));
            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: "PATCH"));
            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: null));
            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: "get"));
            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: "DelEte"));
            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: " "));
            context.Routing.Template.Locations.Add(new ApiEndpointLocation(controller: null, methodInfo: null, httpMethod: ""));


            var processed = await context.ProcessHttpRequestCrossOriginResourceSharingPreflight(null, null, null).ConfigureAwait(false);

            processed.Should().BeFalse();
            context.Response.Should().NotBeNull();
            context.Response.ResponseObject.Should().BeNull();
            context.Response.StatusCode.Should().Be(200);

            context.Response.Headers.Should().NotBeNull();
            context.Response.Headers.Should().HaveCount(1);
            context.Response.Headers[0].Name.Should().Be("Access-Control-Allow-Methods");
            context.Response.Headers[0].Value.Should().Be("POST, PUT, PATCH, GET, DELETE");
        }
Exemplo n.º 5
0
        public async void pipeline_preflight__returns_true_for_no_request_method_preflight_request_method(string requestMethod)
        {
            var context = new ApiRequestContext
            {
                RequestAborted = new CancellationToken(false),
                Request        = new ApiRequestInfo
                {
                    Method             = "options",
                    CrossOriginRequest = new CrossOriginRequestValues
                    {
                        Origin = "http://ron.vecchi.net",
                        AccessControlRequestMethod = requestMethod
                    }
                }
            };

            var processed = await context.ProcessHttpRequestCrossOriginResourceSharingPreflight(null, null, null).ConfigureAwait(false);

            processed.Should().BeTrue();
            context.Response.Should().NotBeNull();
            context.Response.ResponseObject.Should().BeNull();
        }