Skip to content

Commit

Permalink
Fix Saml2RedirectBindingTests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersAbel committed Mar 26, 2020
1 parent 3a97c86 commit a0011d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Sustainsys.Saml2/SAML2P/ISaml2MessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static string ToXml<TMessage>(this TMessage message, Action<TMessage, XDo
where TMessage : ISaml2Message
{
var xDocument = new XDocument(message.ToXElement());
xmlCreatedNotification(message, xDocument);

xmlCreatedNotification?.Invoke(message, xDocument);

return xDocument.ToStringWithXmlDeclaration();
}
Expand Down
35 changes: 12 additions & 23 deletions Tests/Tests.Shared/WebSSO/Saml2RedirectBindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,12 @@ public void Saml2RedirectBinding_Unbind_Nullcheck_Request()
.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("request");
}

// Example from http://en.wikipedia.org/wiki/SAML_2.0#HTTP_Redirect_Binding
private const string ExampleXmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
+ "<samlp:AuthnRequest\r\n"
+ " xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"\r\n"
+ " xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\"\r\n"
+ " ID=\"aaf23196-1773-2113-474a-fe114412ab72\"\r\n"
+ " Version=\"2.0\"\r\n"
+ " IssueInstant=\"2004-12-05T09:21:59Z\"\r\n"
+ " AssertionConsumerServiceIndex=\"0\"\r\n"
+ " AttributeConsumingServiceIndex=\"0\">\r\n"
+ " <saml:Issuer>https://sp.example.com/SAML2</saml:Issuer>\r\n"
+ " <samlp:NameIDPolicy\r\n"
+ " AllowCreate=\"true\"\r\n"
+ " Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:transient\"/>\r\n"
+ "</samlp:AuthnRequest>\r\n";

private const string ExampleSerializedData = "fZFfa8IwFMXfBb9DyXvaJtZ1BqsURRC2Mabbw95ivc5Am3TJrXPffmmLY3%2FA15Pzuyf33On8XJXBCaxTRmeEhTEJQBdmr%2FRbRp63K3pL5rPhYOpkVdYib%2FCon%2BC9AYfDQRB4WDvRvWWksVoY6ZQTWlbgBBZik9%2FfCR7GorYGTWFK8pu6DknnwKL%2FWEetlxmR8sBHbHJDWZqOKGdsRJM0kfQAjCUJ43KX8s78ctnIz%2Blp5xpYa4dSo1fjOKGM03i8jSeCMzGevHa2%2FBK5MNo1FdgN2JMqPLmHc0b6WTmiVbsGoTf5qv66Zq2t60x0wXZ2RKydiCJXh3CWVV1CWJgqanfl0%2Bin8xutxYOvZL18NKUqPlvZR5el%2BVhYkAgZQdsA6fWVsZXE63W2itrTQ2cVaKV2CjSSqL1v9P%2FAXv4C";
private const string ExampleXmlData = "<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"aaf23196-1773-2113-474a-fe114412ab72\" Version=\"2.0\" IssueInstant=\"2004-12-05T09:21:59Z\" AssertionConsumerServiceIndex=\"0\" AttributeConsumingServiceIndex=\"0\">\r\n"
+ " <saml:Issuer>https://sp.example.com/SAML2</saml:Issuer>\r\n"
+ " <samlp:NameIDPolicy AllowCreate=\"true\" Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:transient\" />\r\n"
+ "</samlp:AuthnRequest>";

private const string ExampleSerializedData = "fZFBSwMxEIXvgv8h5J7uJt26NHQLS4tQUBErHryl26kNbJI1M6v135ttUaqHXmfeN4%2F3ZobGtZ2ue9r7J3jvAYkdXOtRHxcV76PXwaBF7Y0D1NTodX1%2Fp9Uo110MFJrQ8jPkMmEQIZINnrPVsuLG7NRYTm%2BELMuxUFKORVEWRuxAyqKQymxKxdkLRExIxdOFxCH2sPJIxlMa5XkhpBL55DmfaiX1ZPrKWf1jswgeewdxDfHDNgnbwqHi6UpNFO2mJzgprH%2F7L5lfXzE2GyLpo2Wc74k61FmG3QgOxnUtjJrgsiGcmmXnyl%2B00w%2Bpg9XyMbS2%2BWJ124bPRQRDUHGKPXB2G6IzdLm1YWK3YneUaorGowVPnGXJ6eT894Xzbw%3D%3D";

private static string DeflateBase64EncodedData(string input)
{
Expand Down Expand Up @@ -144,7 +133,7 @@ public void Saml2RedirectBinding_Bind()
var expected = new CommandResult()
{
Location = new Uri("http://www.example.com/sso?SAMLRequest=" + ExampleSerializedData),
HttpStatusCode = System.Net.HttpStatusCode.SeeOther,
HttpStatusCode = HttpStatusCode.SeeOther,
};

CompareCommandResults(result, expected);
Expand Down Expand Up @@ -206,17 +195,17 @@ public void Saml2RedirectBinding_Bind_With_RelayState()
{
var message = new Saml2MessageImplementation
{
XmlData = "Data",
XmlData = "<xml />",
RelayState = "SomeState that needs escaping #%=3",
DestinationUrl = new Uri("http://host"),
MessageName = "SAMLRequest"
};

var expected = new CommandResult()
{
Location = new Uri("http://host?SAMLRequest=c0ksSQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA%3D%3D"
Location = new Uri("http://host?SAMLRequest=s6nIzVHQtwMA"
+ "&RelayState=" + Uri.EscapeDataString(message.RelayState)),
HttpStatusCode = System.Net.HttpStatusCode.SeeOther
HttpStatusCode = HttpStatusCode.SeeOther
};

var result = Saml2Binding.Get(Saml2BindingType.HttpRedirect).Bind(message);
Expand Down Expand Up @@ -418,13 +407,13 @@ public void Saml2RedirectBinding_Bind_WritesLogIfLoggerNotNull()
var message = new Saml2MessageImplementation()
{
DestinationUrl = new Uri("http://destination"),
XmlData = "<xml/>"
XmlData = "<xml />"
};
var logger = Substitute.For<ILoggerAdapter>();

Saml2Binding.Get(Saml2BindingType.HttpRedirect).Bind(message, logger);

logger.Received().WriteVerbose("Sending message over Http Redirect Binding\n<xml/>");
logger.Received().WriteVerbose("Sending message over Http Redirect Binding\n<xml />");
}
}
}

0 comments on commit a0011d5

Please sign in to comment.