Skip to content

Commit

Permalink
Merge pull request #922 from DigDes/develop
Browse files Browse the repository at this point in the history
v1.1.0.35
  • Loading branch information
kotovaleksandr authored Nov 7, 2022
2 parents 42b3fdf + 9745057 commit 73a3d4e
Show file tree
Hide file tree
Showing 8 changed files with 1,329 additions and 1,203 deletions.
3 changes: 2 additions & 1 deletion src/SoapCore.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -317,7 +318,7 @@ private ITestService CreateClientASMX(bool caseInsensitivePath = false)
private ITestService CreateSoap12Client()
{
var transport = new HttpTransportBindingElement();
var textencoding = new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, System.Text.Encoding.UTF8);
var textencoding = new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, Encoding.UTF8);
var binding = new CustomBinding(textencoding, transport);
var endpoint = new EndpointAddress(new Uri(string.Format("http://{0}:5050/Service.svc", "localhost")));
var channelFactory = new ChannelFactory<ITestService>(binding, endpoint);
Expand Down
312 changes: 186 additions & 126 deletions src/SoapCore.Tests/RawRequestSoap11Tests.cs
Original file line number Diff line number Diff line change
@@ -1,126 +1,186 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SoapCore.Tests
{
[TestClass]
public class RawRequestSoap11Tests
{
[TestMethod]
public async Task Soap11EmptyArgs()
{
const string body = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
<soapenv:Header/>
<soapenv:Body/>
</soapenv:Envelope>
";

using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.UTF8, "text/xml"))
using (var res = host.CreateRequest("/Service.svc").AddHeader("SOAPAction", @"""EmptyArgs""").And(msg => msg.Content = content).PostAsync().Result)
{
res.EnsureSuccessStatusCode();

var response = await res.Content.ReadAsStringAsync();
Assert.IsTrue(response.Contains("EmptyArgs"));
}
}

[TestMethod]
public async Task Soap11Ping()
{
var pingValue = "abc";
var body = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
<soapenv:Body>
<Ping xmlns=""http://tempuri.org/"">
<s>{pingValue}</s>
</Ping>
</soapenv:Body>
</soapenv:Envelope>
";
using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.UTF8, "text/xml"))
using (var res = host.CreateRequest("/Service.svc").AddHeader("SOAPAction", @"""Ping""").And(msg => msg.Content = content).PostAsync().Result)
{
res.EnsureSuccessStatusCode();

var response = await res.Content.ReadAsStringAsync();
Assert.IsTrue(response.Contains(pingValue));
}
}

[TestMethod]
public void Soap11PingWithMixedNamespacing()
{
var pingValue = "Lorem ipsum";
var body = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1=""http://www.w3.org/2001/XMLSchema""
xmlns:SOAPSDK2=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:SOAPSDK3=""http://schemas.xmlsoap.org/soap/encoding/""
xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"">
<SOAP-ENV:Body SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">
<SOAPSDK4:Ping xmlns:SOAPSDK4=""http://tempuri.org/"">
<s>{pingValue}</s>
</SOAPSDK4:Ping>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
";
using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.UTF8, "text/xml"))
using (var res = host.CreateRequest("/Service.svc").AddHeader("SOAPAction", @"""Ping""").And(msg => msg.Content = content).PostAsync().Result)
{
res.EnsureSuccessStatusCode();

var response = res.Content.ReadAsStringAsync().Result;
Assert.IsTrue(response.Contains(pingValue));
}
}

[TestMethod]
public async Task Soap11PingInMultipart()
{
var pingValue = "abc";
var soapBody = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
<soapenv:Body>
<Ping xmlns=""http://tempuri.org/"">
<s>{pingValue}</s>
</Ping>
</soapenv:Body>
</soapenv:Envelope>";

using var host = CreateTestHost();
using var client = host.CreateClient();
using var multipartContent = new MultipartContent("related");
multipartContent.Headers.ContentType!.Parameters.Add(new NameValueHeaderValue("type", "\"text/xml\""));

using var soapContent = new StringContent(soapBody, Encoding.UTF8, "text/xml");
soapContent.Headers.Add("SOAPAction", @"""Ping""");

using var extraContent = new StringContent("some text payload", Encoding.UTF8, "text/plain");

multipartContent.Add(soapContent);
multipartContent.Add(extraContent);

using var res = await host.CreateRequest("/Service.svc").And(msg => msg.Content = multipartContent).PostAsync();

res.EnsureSuccessStatusCode();
var response = await res.Content.ReadAsStringAsync();
Assert.IsTrue(response.Contains(pingValue));
}

private TestServer CreateTestHost()
{
var webHostBuilder = new WebHostBuilder()
.UseStartup<Startup>();
return new TestServer(webHostBuilder);
}
}
}
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SoapCore.Tests
{
[TestClass]
public class RawRequestSoap11Tests
{
[TestMethod]
public async Task Soap11EmptyArgs()
{
const string body = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
<soapenv:Header/>
<soapenv:Body/>
</soapenv:Envelope>
";

using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.UTF8, "text/xml"))
using (var res = host.CreateRequest("/Service.svc").AddHeader("SOAPAction", @"""EmptyArgs""").And(msg => msg.Content = content).PostAsync().Result)
{
res.EnsureSuccessStatusCode();

var response = await res.Content.ReadAsStringAsync();
Assert.IsTrue(response.Contains("EmptyArgs"));
}
}

[TestMethod]
public async Task Soap11Ping()
{
var pingValue = "abc";
var body = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
<soapenv:Body>
<Ping xmlns=""http://tempuri.org/"">
<s>{pingValue}</s>
</Ping>
</soapenv:Body>
</soapenv:Envelope>
";
using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.UTF8, "text/xml"))
using (var res = host.CreateRequest("/Service.svc").AddHeader("SOAPAction", @"""Ping""").And(msg => msg.Content = content).PostAsync().Result)
{
res.EnsureSuccessStatusCode();

var response = await res.Content.ReadAsStringAsync();
Assert.IsTrue(response.Contains(pingValue));
}
}

[TestMethod]
public void Soap11PingWithMixedNamespacing()
{
var pingValue = "Lorem ipsum";
var body = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1=""http://www.w3.org/2001/XMLSchema""
xmlns:SOAPSDK2=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:SOAPSDK3=""http://schemas.xmlsoap.org/soap/encoding/""
xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"">
<SOAP-ENV:Body SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">
<SOAPSDK4:Ping xmlns:SOAPSDK4=""http://tempuri.org/"">
<s>{pingValue}</s>
</SOAPSDK4:Ping>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
";
using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.UTF8, "text/xml"))
using (var res = host.CreateRequest("/Service.svc").AddHeader("SOAPAction", @"""Ping""").And(msg => msg.Content = content).PostAsync().Result)
{
res.EnsureSuccessStatusCode();

var response = res.Content.ReadAsStringAsync().Result;
Assert.IsTrue(response.Contains(pingValue));
}
}

[TestMethod]
public async Task Soap11PingInMultipart()
{
var pingValue = "abc";
var soapBody = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
<soapenv:Body>
<Ping xmlns=""http://tempuri.org/"">
<s>{pingValue}</s>
</Ping>
</soapenv:Body>
</soapenv:Envelope>";

using var host = CreateTestHost();
using var client = host.CreateClient();
using var multipartContent = new MultipartContent("related");
multipartContent.Headers.ContentType!.Parameters.Add(new NameValueHeaderValue("type", "\"text/xml\""));

using var soapContent = new StringContent(soapBody, Encoding.UTF8, "text/xml");
soapContent.Headers.Add("SOAPAction", @"""Ping""");

using var extraContent = new StringContent("some text payload", Encoding.UTF8, "text/plain");

multipartContent.Add(soapContent);
multipartContent.Add(extraContent);

using var res = await host.CreateRequest("/Service.svc").And(msg => msg.Content = multipartContent).PostAsync();

res.EnsureSuccessStatusCode();
var response = await res.Content.ReadAsStringAsync();
Assert.IsTrue(response.Contains(pingValue));
}

[TestMethod]
public async Task Soap11PingResponseBodyEncodingSameAsWriteEncoding()
{
var pingValue = "abc";
var body = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
<soapenv:Body>
<Ping xmlns=""http://tempuri.org/"">
<s>{pingValue}</s>
</Ping>
</soapenv:Body>
</soapenv:Envelope>
";
using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.GetEncoding("ISO-8859-1"), "text/xml"))
{
var requestBuilder = host.CreateRequest("/ServiceWithDifferentEncodings.asmx").AddHeader("SOAPAction", @"""Ping""").And(msg => msg.Content = content);
using (var res = requestBuilder.PostAsync().Result)
{
res.EnsureSuccessStatusCode();

var response = await res.Content.ReadAsStringAsync();

Assert.IsTrue(response.Contains(pingValue));
Assert.IsTrue(response.Contains("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
}
}
}

[TestMethod]
public async Task Soap11PingWithOverwrittenContentType()
{
var pingValue = "abc";
var body = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
<soapenv:Body>
<Ping xmlns=""http://tempuri.org/"">
<s>{pingValue}</s>
</Ping>
</soapenv:Body>
</soapenv:Envelope>
";
using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.GetEncoding("ISO-8859-1"), "text/xml"))
{
var requestBuilder = host.CreateRequest("/ServiceWithOverwrittenContentType.asmx").AddHeader("SOAPAction", @"""Ping""").And(msg => msg.Content = content);
using (var res = requestBuilder.PostAsync().Result)
{
res.EnsureSuccessStatusCode();

var response = await res.Content.ReadAsStringAsync();
var requestContentType = res.RequestMessage.Content.Headers.ContentType.ToString();
var responseContentType = res.Content.Headers.ContentType.ToString();

Assert.IsTrue(response.Contains(pingValue));
Assert.AreNotEqual(requestContentType, responseContentType);
}
}
}

private TestServer CreateTestHost()
{
var webHostBuilder = new WebHostBuilder()
.UseStartup<Startup>();
return new TestServer(webHostBuilder);
}
}
}
Loading

0 comments on commit 73a3d4e

Please sign in to comment.