Skip to content

Commit

Permalink
Merge pull request #678 from microsoft/personal/yazanal/fix-cors-tests
Browse files Browse the repository at this point in the history
Fix cors tests
  • Loading branch information
YazanMSFT authored Oct 4, 2019
2 parents a0d8c86 + 3a8db37 commit b615509
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/CorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@ public CorsTests(HttpIntegrationTestFixture fixture)
[Trait(Traits.Priority, Priority.One)]
public async Task WhenGettingOptions_GivenAppropriateHeaders_TheServerShouldReturnTheAppropriateCorsHeaders()
{
var message = new HttpRequestMessage
{
Method = HttpMethod.Options,
};
var message = new HttpRequestMessage(HttpMethod.Options, "patient");

message.Headers.Add(HeaderNames.Origin, "https://localhost:6001");
message.Headers.Add(HeaderNames.AccessControlRequestMethod, "PUT");
message.Headers.Add(HeaderNames.AccessControlRequestHeaders, "authorization");
message.Headers.Add(HeaderNames.AccessControlRequestHeaders, "content-type");
message.RequestUri = new Uri(_client.HttpClient.BaseAddress, "/patient");

HttpResponseMessage response = await _client.HttpClient.SendAsync(message);

Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
Assert.Contains("https://localhost:6001", response.Headers.GetValues(HeaderNames.AccessControlAllowOrigin));

Assert.Contains("PUT", response.Headers.GetValues(HeaderNames.AccessControlAllowMethods));
var allowMethods = response.Headers.GetValues(HeaderNames.AccessControlAllowMethods);
#pragma warning disable xUnit2012 // Do not use Enumerable.Any() to check if a value exists in a collection

// The response can be in a single comma separated string, we want to check that it exists in any of them.
Assert.True(allowMethods.Any(x => x.Contains("PUT")));
#pragma warning restore xUnit2012 // Do not use Enumerable.Any() to check if a value exists in a collection

Assert.Contains("authorization,content-type", response.Headers.GetValues(HeaderNames.AccessControlAllowHeaders));

Expand Down

0 comments on commit b615509

Please sign in to comment.