Skip to content

Commit

Permalink
Do not throw on invalid replyTo address
Browse files Browse the repository at this point in the history
  • Loading branch information
ig-sinicyn committed May 10, 2020
1 parent c9e36dc commit 51b56db
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
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
32 changes: 30 additions & 2 deletions projects/Unit/TestBasicProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public void TestPersistentPropertyChangesDeliveryMode_PersistentFalseDelivery1()
public void TestNullableProperties_CanWrite(
[Values(null, "cluster1")] string clusterId,
[Values(null, "732E39DC-AF56-46E8-B8A9-079C4B991B2E")] string correlationId,
[Values(null, "7D221C7E-1788-4D11-9CA5-AC41425047CF")] string messageId
)
[Values(null, "7D221C7E-1788-4D11-9CA5-AC41425047CF")] string messageId)
{
// Arrange
var subject = new Framing.BasicProperties
Expand Down Expand Up @@ -120,5 +119,34 @@ 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

0 comments on commit 51b56db

Please sign in to comment.