|
|
@ -8,19 +8,26 @@ namespace NzbDrone.Integration.Test
|
|
|
|
[TestFixture]
|
|
|
|
[TestFixture]
|
|
|
|
public class CorsFixture : IntegrationTest
|
|
|
|
public class CorsFixture : IntegrationTest
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private RestRequest BuildRequest()
|
|
|
|
private RestRequest BuildGet(string route = "series")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var request = new RestRequest("series");
|
|
|
|
var request = new RestRequest(route, Method.GET);
|
|
|
|
request.AddHeader(AccessControlHeaders.RequestMethod, "POST");
|
|
|
|
request.AddHeader(AccessControlHeaders.RequestMethod, "POST");
|
|
|
|
|
|
|
|
|
|
|
|
return request;
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private RestRequest BuildOptions(string route = "series")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var request = new RestRequest(route, Method.OPTIONS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return request;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_not_have_allow_headers_in_response_when_not_included_in_the_request()
|
|
|
|
public void should_not_have_allow_headers_in_response_when_not_included_in_the_request()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var request = BuildRequest();
|
|
|
|
var request = BuildOptions();
|
|
|
|
var response = RestClient.Get(request);
|
|
|
|
var response = RestClient.Execute(request);
|
|
|
|
|
|
|
|
|
|
|
|
response.Headers.Should().NotContain(h => h.Name == AccessControlHeaders.AllowHeaders);
|
|
|
|
response.Headers.Should().NotContain(h => h.Name == AccessControlHeaders.AllowHeaders);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -28,10 +35,10 @@ namespace NzbDrone.Integration.Test
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_have_allow_headers_in_response_when_included_in_the_request()
|
|
|
|
public void should_have_allow_headers_in_response_when_included_in_the_request()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var request = BuildRequest();
|
|
|
|
var request = BuildOptions();
|
|
|
|
request.AddHeader(AccessControlHeaders.RequestHeaders, "X-Test");
|
|
|
|
request.AddHeader(AccessControlHeaders.RequestHeaders, "X-Test");
|
|
|
|
|
|
|
|
|
|
|
|
var response = RestClient.Get(request);
|
|
|
|
var response = RestClient.Execute(request);
|
|
|
|
|
|
|
|
|
|
|
|
response.Headers.Should().Contain(h => h.Name == AccessControlHeaders.AllowHeaders);
|
|
|
|
response.Headers.Should().Contain(h => h.Name == AccessControlHeaders.AllowHeaders);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -39,8 +46,8 @@ namespace NzbDrone.Integration.Test
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_have_allow_origin_in_response()
|
|
|
|
public void should_have_allow_origin_in_response()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var request = BuildRequest();
|
|
|
|
var request = BuildOptions();
|
|
|
|
var response = RestClient.Get(request);
|
|
|
|
var response = RestClient.Execute(request);
|
|
|
|
|
|
|
|
|
|
|
|
response.Headers.Should().Contain(h => h.Name == AccessControlHeaders.AllowOrigin);
|
|
|
|
response.Headers.Should().Contain(h => h.Name == AccessControlHeaders.AllowOrigin);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -48,10 +55,37 @@ namespace NzbDrone.Integration.Test
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_have_allow_methods_in_response()
|
|
|
|
public void should_have_allow_methods_in_response()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var request = BuildRequest();
|
|
|
|
var request = BuildOptions();
|
|
|
|
var response = RestClient.Get(request);
|
|
|
|
var response = RestClient.Execute(request);
|
|
|
|
|
|
|
|
|
|
|
|
response.Headers.Should().Contain(h => h.Name == AccessControlHeaders.AllowMethods);
|
|
|
|
response.Headers.Should().Contain(h => h.Name == AccessControlHeaders.AllowMethods);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_not_have_allow_methods_in_non_options_request()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var request = BuildGet();
|
|
|
|
|
|
|
|
var response = RestClient.Execute(request);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.Headers.Should().NotContain(h => h.Name == AccessControlHeaders.AllowMethods);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_have_allow_origin_in_non_options_request()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var request = BuildGet();
|
|
|
|
|
|
|
|
var response = RestClient.Execute(request);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.Headers.Should().Contain(h => h.Name == AccessControlHeaders.AllowOrigin);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_not_have_allow_origin_in_non_api_request()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var request = BuildGet("../abc");
|
|
|
|
|
|
|
|
var response = RestClient.Execute(request);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.Headers.Should().NotContain(h => h.Name == AccessControlHeaders.AllowOrigin);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|