Skip to content

Commit

Permalink
Set content-type on SOAP requests
Browse files Browse the repository at this point in the history
- Fixes #1120
  • Loading branch information
AndersAbel committed Mar 17, 2020
1 parent ad25b7f commit 0859e67
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Sustainsys.Saml2/SAML2P/Saml2SoapBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ public static XmlElement SendSoapRequest(string payload, Uri destination)

using (var client = new ClientCertificateWebClient(clientCertificates))
{
client.Headers.Add("SOAPAction", "http://www.oasis-open.org/committees/security");
client.Headers.Add("SOAPAction", "\"http://www.oasis-open.org/committees/security\"");
client.Encoding = Encoding.UTF8;
client.Headers.Add(HttpRequestHeader.ContentType, "text/xml; charset=\"utf-8\"");

var response = client.UploadString(destination, message);

Expand Down
3 changes: 3 additions & 0 deletions Tests/Tests.Shared/Helpers/StubServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ public static void Start(TestContext testContext)
private static async Task ArtifactResolutionService(HttpContext ctx)
{
LastArtifactResolutionSoapActionHeader = ctx.Request.Headers["SOAPAction"];
LastArtifactResolutionContentType = ctx.Request.Headers["Content-Type"];

using (var reader = new StreamReader(ctx.Request.Body))
{
Expand Down Expand Up @@ -452,6 +453,8 @@ private static async Task ArtifactResolutionService(HttpContext ctx)

public static string LastArtifactResolutionSoapActionHeader { get; set; }

public static string LastArtifactResolutionContentType { get; set; }

public static bool LastArtifactResolutionWasSigned { get; set; }

[AssemblyCleanup]
Expand Down
11 changes: 2 additions & 9 deletions Tests/Tests.Shared/WebSSO/Saml2ArtifactBindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public void Saml2ArtifactBinding_Unbind_FromGet()

result.Should().BeEquivalentTo(expected);
StubServer.LastArtifactResolutionSoapActionHeader.Should().Be(
"http://www.oasis-open.org/committees/security");
"\"http://www.oasis-open.org/committees/security\"");
StubServer.LastArtifactResolutionContentType.Should().Be("text/xml; charset=\"utf-8\"");
StubServer.LastArtifactResolutionWasSigned.Should().BeFalse();
}

Expand Down Expand Up @@ -148,8 +149,6 @@ public void Saml2ArtifactBinding_Unbind_FromGet_ArtifactIsntHashOfEntityId()
var expected = new UnbindResult(xmlDocument.DocumentElement, relayState, TrustLevel.None);

result.Should().BeEquivalentTo(expected);
StubServer.LastArtifactResolutionSoapActionHeader.Should().Be(
"http://www.oasis-open.org/committees/security");
StubServer.LastArtifactResolutionWasSigned.Should().BeFalse();
}

Expand Down Expand Up @@ -198,8 +197,6 @@ public void Saml2ArtifactBinding_Unbind_FromGetWithoutRelayState()
var expected = new UnbindResult(xmlDocument.DocumentElement, null, TrustLevel.None);

result.Should().BeEquivalentTo(expected);
StubServer.LastArtifactResolutionSoapActionHeader.Should().Be(
"http://www.oasis-open.org/committees/security");
}

[TestMethod]
Expand Down Expand Up @@ -232,8 +229,6 @@ public void Saml2ArtifactBinding_Unbind_FromPost()
var expected = new UnbindResult(xmlDocument.DocumentElement, relayState, TrustLevel.None);

result.Should().BeEquivalentTo(expected);
StubServer.LastArtifactResolutionSoapActionHeader.Should().Be(
"http://www.oasis-open.org/committees/security");
}

[TestMethod]
Expand Down Expand Up @@ -264,8 +259,6 @@ public void Saml2ArtifactBinding_Unbind_FromPostWithoutRelayState()
var expected = new UnbindResult(xmlDocument.DocumentElement, null, TrustLevel.None);

result.Should().BeEquivalentTo(expected);
StubServer.LastArtifactResolutionSoapActionHeader.Should().Be(
"http://www.oasis-open.org/committees/security");
}

[TestMethod]
Expand Down

0 comments on commit 0859e67

Please sign in to comment.