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()); }
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); }
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()); }
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()); }
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); }