public void LogoutCommand_Run_HandlesLogoutResponse_InPost() { var relayState = "TestState"; var response = new Saml2LogoutResponse(Saml2StatusCode.Success) { DestinationUrl = new Uri("http://sp.example.com/path/Saml2/logout"), Issuer = new EntityId("https://idp.example.com"), InResponseTo = new Saml2Id(), SigningCertificate = SignedXmlHelper.TestCert }; var xml = XmlHelpers.XmlDocumentFromString(response.ToXml()); xml.Sign(SignedXmlHelper.TestCert); var responseData = Convert.ToBase64String(Encoding.UTF8.GetBytes(xml.OuterXml)); var httpRequest = new HttpRequestData( "POST", new Uri("http://something"), "/path", new KeyValuePair <string, IEnumerable <string> >[] { new KeyValuePair <string, IEnumerable <string> >("SAMLResponse", new[] { responseData }), new KeyValuePair <string, IEnumerable <string> >("RelayState", new[] { relayState }) }, Enumerable.Empty <KeyValuePair <string, string> >(), null) { StoredRequestState = new StoredRequestState(null, new Uri("http://loggedout.example.com"), null, null) }; var options = StubFactory.CreateOptions(); options.SPOptions.ServiceCertificates.Add(SignedXmlHelper.TestCert); var actual = CommandFactory.GetCommand(CommandFactory.LogoutCommandName) .Run(httpRequest, options); var expected = new CommandResult { Location = new Uri("http://loggedout.example.com"), HttpStatusCode = HttpStatusCode.SeeOther, ClearCookieName = StoredRequestState.CookieNameBase + relayState, }; actual.Should().BeEquivalentTo(expected); }
public void Saml2LogoutResponse_ToXml() { var subject = new Saml2LogoutResponse(Saml2StatusCode.Requester) { Issuer = new EntityId("https://ServiceProvider.com/SAML"), DestinationUrl = new Uri("https://IdentityProvider.com/Logout"), InResponseTo = new Saml2Id() }; var xmlDoc = XmlHelpers.CreateSafeXmlDocument(); subject.AppendTo(xmlDoc); var expected = xmlDoc.OuterXml; subject.ToXml().Should().Be(expected); }