Skip to content

Commit

Permalink
Merge branch 'release/0.100.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Jun 1, 2023
2 parents b2b991e + 241cbb8 commit 17885c8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
37 changes: 37 additions & 0 deletions Source/StrongGrid.UnitTests/WebhookParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,43 @@ public async Task Serialize_and_deserialize_derived_types()
((OpenedEvent)result[2]).IpAddress.ShouldBe("This is a test");
}

[Fact]
// This unit reproduces the problem described in GH-491 and
// demonstrates that it was resolved in StrongGrid 0.99.1
public async Task Webhook_includes_unknow_property()
{
const string JSON_WITH_RESELLER_ID = @"
{
""reseller_id"":1234,
""email"":""example@test.com"",
""timestamp"":1513299569,
""smtp-id"":""<14c5d75ce93.dfd.64b469@ismtpd-555>"",
""event"":""open"",
""sg_machine_open"": false,
""category"":""cat facts"",
""sg_event_id"":""FOTFFO0ecsBE-zxFXfs6WA=="",
""sg_message_id"":""14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0"",
""useragent"":""Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"",
""ip"":""255.255.255.255""
}";

// Arrange
var responseContent = $"[{JSON_WITH_RESELLER_ID}]";
var parser = new WebhookParser();
using (var stream = GetStream(responseContent))
{
// Act
var result = await parser.ParseEventsWebhookAsync(stream).ConfigureAwait(false);

// Assert
result.ShouldNotBeNull();
result.Length.ShouldBe(1);
result[0].UniqueArguments.ShouldNotBeNull();
result[0].UniqueArguments.Count.ShouldBe(1);
result[0].UniqueArguments.ShouldContainKeyAndValue("reseller_id", "1234"); // Note that the value has been converted to a string
}
}

private Stream GetStream(string responseContent)
{
var byteArray = Encoding.UTF8.GetBytes(responseContent);
Expand Down
6 changes: 3 additions & 3 deletions Source/StrongGrid/Json/EventConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public override Event Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSe
throw new Exception($"{typeAsString} is an unknown event type");
}

var properties = doc.RootElement
var unkownProperties = doc.RootElement
.EnumerateObject()
.Where(property => !_knownProperties.Contains(property.Name));

foreach (var property in properties)
foreach (var unkownProperty in unkownProperties)
{
webHookEvent.UniqueArguments.Add(property.Name, property.Value.GetString());
webHookEvent.UniqueArguments.Add(unkownProperty.Name, unkownProperty.Value.GetRawText());
}

return webHookEvent;
Expand Down

0 comments on commit 17885c8

Please sign in to comment.