Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix problem with timestamp in WsMessageFilter #1083

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/SoapCore.Tests/MessageFilter/WsMessageFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public async Task IncorrectCredentialsNotAuthrorized()
await filter.OnRequestExecuting(CreateMessage(usernameToken));
}

[TestMethod]
[ExpectedException(typeof(InvalidCredentialException))]
public async Task IncorrectCredentialsWithTimestampNotAuthrorized()
{
var usernameToken = new XElement(
_wsse + "UsernameToken",
new XElement(_wsse + "Username", "INVALID_USERNAME"),
new XElement(_wsse + "Password", "INAVLID_PASSWORD"));

var filter = new WsMessageFilter("yourusername", "yourpassword");
await filter.OnRequestExecuting(CreateMessageWithTimestamp(usernameToken));
}

[TestMethod]
public async Task PasswordIsOptional()
{
Expand Down Expand Up @@ -166,5 +179,27 @@ private static Message CreateMessage(XNode usernameToken)
var doc = new XDocument(envelope);
return Message.CreateMessage(doc.CreateReader(), int.MaxValue, MessageVersion.Soap11);
}

private static Message CreateMessageWithTimestamp(XNode usernameToken)
{
var envelope = new XElement(
_soapenv11 + "Envelope",
new XAttribute(XNamespace.Xmlns + "wsse", _wsse.NamespaceName),
new XAttribute(XNamespace.Xmlns + "soap", _soapenv11.NamespaceName),
new XElement(
_soapenv11 + "Header",
new XElement(
_wsse + "Security",
new XElement(_wsse + "Timestamp", new XElement(_wsse + "Created"), new XElement(_wsse + "Expires")),
usernameToken)),
new XElement(
_soapenv11 + "Body",
new XElement(
XName.Get("Ping", "http://tempuri.org/"),
"abc")));

var doc = new XDocument(envelope);
return Message.CreateMessage(doc.CreateReader(), int.MaxValue, MessageVersion.Soap11);
}
}
}
6 changes: 5 additions & 1 deletion src/SoapCore/WsMessageFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ private WsUsernameToken GetWsUsernameToken(Message message)
if (message.Headers[i].Name.ToLower() == "security")
{
using var reader = message.Headers.GetReaderAtHeader(i);
reader.Read();
while (!reader.EOF && reader.LocalName != "UsernameToken")
{
reader.Read();
}

var serializer = new XmlSerializer(typeof(WsUsernameToken));
wsUsernameToken = (WsUsernameToken)serializer.Deserialize(reader);
}
Expand Down
Loading