Пример #1
0
        public void WriteCorsHeaders_WritesAllowCredentials()
        {
            HttpResponseMessage response   = new HttpResponseMessage();
            CorsResult          corsResult = new CorsResult
            {
                SupportsCredentials = true
            };

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            Assert.Equal("true", headers.GetValues("Access-Control-Allow-Credentials").FirstOrDefault());
        }
Пример #2
0
        public void WriteCorsHeaders_WritesAllowExposedHeaders()
        {
            HttpResponseMessage response   = new HttpResponseMessage();
            CorsResult          corsResult = new CorsResult();

            corsResult.AllowedExposedHeaders.Add("baz");

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            string[] exposedHeaders = headers.GetValues("Access-Control-Expose-Headers").FirstOrDefault().Split(',');
            Assert.Contains("baz", exposedHeaders);
        }
Пример #3
0
        public void WriteCorsHeaders_WritesPreflightMaxAge()
        {
            HttpResponseMessage response   = new HttpResponseMessage();
            CorsResult          corsResult = new CorsResult
            {
                PreflightMaxAge = 10
            };

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            Assert.Equal("10", headers.GetValues("Access-Control-Max-Age").FirstOrDefault());
        }
Пример #4
0
        public void WriteCorsHeaders_WritesAllowOrigin()
        {
            HttpResponseMessage response   = new HttpResponseMessage();
            CorsResult          corsResult = new CorsResult
            {
                AllowedOrigin = "*"
            };

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            Assert.Equal("*", headers.GetValues("Access-Control-Allow-Origin").FirstOrDefault());
        }
Пример #5
0
        public void WriteCorsHeaders_WritesAllowMethods()
        {
            HttpResponseMessage response   = new HttpResponseMessage();
            CorsResult          corsResult = new CorsResult();

            corsResult.AllowedMethods.Add("DELETE");
            corsResult.AllowedMethods.Add("PUT");

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            string[] allowMethods = headers.GetValues("Access-Control-Allow-Methods").FirstOrDefault().Split(',');
            Assert.Contains("DELETE", allowMethods);
            Assert.Contains("PUT", allowMethods);
        }