Fix typo of webhook events property

This commit is contained in:
nicolas.dorier 2021-04-20 12:36:20 +09:00
parent 99b1e391a6
commit 315284d5f5
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
4 changed files with 40 additions and 4 deletions

View File

@ -19,7 +19,31 @@ namespace BTCPayServer.Client.Models
}
public string DeliveryId { get; set; }
public string WebhookId { get; set; }
public string OrignalDeliveryId { get; set; }
string _OriginalDeliveryId;
public string OriginalDeliveryId
{
get
{
if (_OriginalDeliveryId is null)
{
// Due to a typo in old version, we serialized `orignalDeliveryId` rather than `orignalDeliveryId`
// We silently fix that here.
// Note we can remove this code later on, as old webhook event are unlikely to be useful to anyone,
// and having a null orignalDeliveryId is not end of the world
if (AdditionalData != null &&
AdditionalData.TryGetValue("orignalDeliveryId", out var tok))
{
_OriginalDeliveryId = tok.Value<string>();
AdditionalData.Remove("orignalDeliveryId");
}
}
return _OriginalDeliveryId;
}
set
{
_OriginalDeliveryId = value;
}
}
public bool IsRedelivery { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public WebhookEventType Type { get; set; }

View File

@ -687,7 +687,7 @@ namespace BTCPayServer.Tests
Assert.NotNull(newDelivery);
Assert.Equal(404, newDelivery.HttpCode);
var req = await clientProfile.GetWebhookDeliveryRequest(user.StoreId, hook.Id, newDeliveryId);
Assert.Equal(delivery.Id, req.OrignalDeliveryId);
Assert.Equal(delivery.Id, req.OriginalDeliveryId);
Assert.True(req.IsRedelivery);
Assert.Equal(WebhookDeliveryStatus.HttpError, newDelivery.Status);
});

View File

@ -3175,6 +3175,18 @@ namespace BTCPayServer.Tests
}
}
[Trait("Fast", "Fast")]
[Fact]
public void CanFixupWebhookEventPropertyName()
{
string legacy = "{\"orignalDeliveryId\":\"blahblah\"}";
var obj = JsonConvert.DeserializeObject<WebhookEvent>(legacy, WebhookEvent.DefaultSerializerSettings);
Assert.Equal("blahblah", obj.OriginalDeliveryId);
var serialized = JsonConvert.SerializeObject(obj, WebhookEvent.DefaultSerializerSettings);
Assert.DoesNotContain("orignalDeliveryId", serialized);
Assert.Contains("originalDeliveryId", serialized);
}
[Fact(Timeout = LongRunningTestTimeout)]
[Trait("Fast", "Fast")]
public async Task CanCreateSqlitedb()

View File

@ -101,7 +101,7 @@ namespace BTCPayServer.HostedServices
webhookEvent.DeliveryId = newDelivery.Id;
webhookEvent.WebhookId = webhookDelivery.Webhook.Id;
// if we redelivered a redelivery, we still want the initial delivery here
webhookEvent.OrignalDeliveryId ??= deliveryId;
webhookEvent.OriginalDeliveryId ??= deliveryId;
webhookEvent.IsRedelivery = true;
newDeliveryBlob.Request = ToBytes(webhookEvent);
newDelivery.SetBlob(newDeliveryBlob);
@ -125,7 +125,7 @@ namespace BTCPayServer.HostedServices
webhookEvent.StoreId = invoiceEvent.Invoice.StoreId;
webhookEvent.DeliveryId = delivery.Id;
webhookEvent.WebhookId = webhook.Id;
webhookEvent.OrignalDeliveryId = delivery.Id;
webhookEvent.OriginalDeliveryId = delivery.Id;
webhookEvent.IsRedelivery = false;
webhookEvent.Timestamp = delivery.Timestamp;
var context = new WebhookDeliveryRequest(webhook.Id, webhookEvent, delivery, webhookBlob);