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

Do not throw on invalid ReplyTo address #828

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
8 changes: 8 additions & 0 deletions projects/RabbitMQ.Client/client/api/PublicationAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ public PublicationAddress(string exchangeType, string exchangeName, string routi
/// </summary>
public static PublicationAddress Parse(string uriLikeString)
{
// Callers such as IBasicProperties.ReplyToAddress
// expect null result for invalid input.
// The regex.Match() throws on null arguments so we perform explicit check here
if (uriLikeString == null)
{
return null;
}

Match match = PSEUDO_URI_PARSER.Match(uriLikeString);
if (match.Success)
{
Expand Down
31 changes: 31 additions & 0 deletions projects/Unit/TestBasicProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,36 @@ public void TestNullableProperties_CanWrite(
Assert.AreEqual(isCorrelationIdPresent, propertiesFromStream.IsCorrelationIdPresent());
Assert.AreEqual(isMessageIdPresent, propertiesFromStream.IsMessageIdPresent());
}

[Test]
public void TestProperties_ReplyTo(
[Values(null, "foo_1", "fanout://name/key")] string replyTo
)
{
// Arrange
var subject = new Framing.BasicProperties
{

// Act
ReplyTo = replyTo,
};

// Assert
bool isReplyToPresent = replyTo != null;
string replyToAddress = PublicationAddress.Parse(replyTo)?.ToString();
Assert.AreEqual(isReplyToPresent, subject.IsReplyToPresent());

var writer = new Impl.ContentHeaderPropertyWriter(new byte[1024]);
subject.WritePropertiesTo(ref writer);

// Read from Stream
var propertiesFromStream = new Framing.BasicProperties();
var reader = new Impl.ContentHeaderPropertyReader(writer.Memory.Slice(0, writer.Offset));
propertiesFromStream.ReadPropertiesFrom(ref reader);

Assert.AreEqual(replyTo, propertiesFromStream.ReplyTo);
Assert.AreEqual(isReplyToPresent, propertiesFromStream.IsReplyToPresent());
Assert.AreEqual(replyToAddress, propertiesFromStream.ReplyToAddress?.ToString());
}
}
}
17 changes: 9 additions & 8 deletions projects/Unit/TestPropertiesClone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ private void TestBasicPropertiesClone(BasicProperties bp)
bp.ContentType = "foo_1";
bp.ContentEncoding = "foo_2";
bp.Headers = new Dictionary<string, object>
{
{ "foo_3", "foo_4" },
{ "foo_5", "foo_6" }
};
{
{ "foo_3", "foo_4" },
{ "foo_5", "foo_6" }
};
bp.DeliveryMode = 2;
// Persistent also changes DeliveryMode's value to 2
bp.Persistent = true;
Expand Down Expand Up @@ -123,6 +123,7 @@ private void TestBasicPropertiesClone(BasicProperties bp)
Assert.AreEqual(12, bpClone.Priority);
Assert.AreEqual("foo_7", bpClone.CorrelationId);
Assert.AreEqual("foo_8", bpClone.ReplyTo);
Assert.AreEqual(null, bpClone.ReplyToAddress);
Assert.AreEqual("foo_9", bpClone.Expiration);
Assert.AreEqual("foo_10", bpClone.MessageId);
Assert.AreEqual(new AmqpTimestamp(123), bpClone.Timestamp);
Expand All @@ -141,10 +142,10 @@ private void TestBasicPropertiesNoneClone(BasicProperties bp)
bp.ContentType = "foo_1";
bp.ContentEncoding = "foo_2";
bp.Headers = new Dictionary<string, object>
{
{ "foo_3", "foo_4" },
{ "foo_5", "foo_6" }
};
{
{ "foo_3", "foo_4" },
{ "foo_5", "foo_6" }
};
bp.DeliveryMode = 2;
// Persistent also changes DeliveryMode's value to 2
bp.Persistent = true;
Expand Down
1 change: 1 addition & 0 deletions projects/Unit/TestPublicationAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void TestParseOk()
[Test]
public void TestParseFail()
{
Assert.IsNull(PublicationAddress.Parse(null));
Assert.IsNull(PublicationAddress.Parse("not a valid uri"));
}

Expand Down