Stripe-dotnet: when_constructing_an_event test fails

Created on 8 Jun 2017  路  5Comments  路  Source: stripe/stripe-dotnet

When running the test when_constructing_an_event it fails at StripeEventUtility#ConstructEvent with the exception The signature for the webhook is not present in the Stripe-Signature header..

When looking further the signature generated by StripeEventUtility#computeSignature does not match the signature in the header provided:
header v1: dca14f723dfa3bf47a310c3d6c3aff8bdb2534263d051dd2613ece097b8bdea4
generated: 86390d1392d759addd01dde4cfa5aa14d98a3b6cedd07a4aad73749cee26abe6

I did some further tests with events directly sent from Stripe and the exact same occurs.

StripeEventUtility#ParseEvent works flawlessly so I am still able to do what I need to do for now, but it would be nice to have this extra security.

Most helpful comment

found the issue, the .json file itself is correct, but for some reason the below code loads \n as \r\n and possibly other things may have changed as well.

StripeJson = new StreamReader(
    typeof(when_constructing_an_event).GetTypeInfo().Assembly.GetManifestResourceStream("Stripe.Tests.XUnit.events.event.json"),
    Encoding.UTF8
).ReadToEnd();

edit: adding .Replace("\r", ""); afterReadToEnd() makes the test pass.

All 5 comments

Are you changing something in the test? The build server and my machine both run this test successfully.

If you are using your own events, you are going to have to use your own secret. This test uses the mock data from event.json because of this reason.

Used a freshly cloned repo but fails upon running the test. My coworker was the one trying it first and when I tried it failed as well. I'm unsure as to why the test would fail for us on two different computers, but if you say it works I'll take your word for it. I'll see if I can find the reason why it's failing for us.

Are you in .net 4.5? I'm wondering if this is related to a current hurdle with a build warning due to the algorithms library.

I'm not sure I follow, if your asking if I have 4.5 installed then yes, yes I have. The test project it self has .NET Core 1.1 selected though. We are using VS 2017 if that's a problem? There are however no warnings and it is building just fine.

found the issue, the .json file itself is correct, but for some reason the below code loads \n as \r\n and possibly other things may have changed as well.

StripeJson = new StreamReader(
    typeof(when_constructing_an_event).GetTypeInfo().Assembly.GetManifestResourceStream("Stripe.Tests.XUnit.events.event.json"),
    Encoding.UTF8
).ReadToEnd();

edit: adding .Replace("\r", ""); afterReadToEnd() makes the test pass.

Was this page helpful?
0 / 5 - 0 ratings