@@ -140,7 +140,7 @@ public void checksWebhookSignature()
140140 StripeClient client = new StripeClient ("sk_123" );
141141
142142 String payload =
143- "{\n \" id\" : \" evt_test_webhook\" ,\n \" type\" : \" v1.whatever\" ,\n \" object\" : \" event\" \n }" ;
143+ "{\n \" id\" : \" evt_test_webhook\" ,\n \" type\" : \" v1.whatever\" ,\n \" object\" : \" v2.core. event\" \n }" ;
144144 String secret = "whsec_test_secret" ;
145145
146146 Map <String , Object > options = new HashMap <>();
@@ -159,7 +159,7 @@ public void failsWebhookVerification()
159159 StripeClient client = new StripeClient ("sk_123" );
160160
161161 String payload =
162- "{\n \" id\" : \" evt_test_webhook\" ,\n \" type\" : \" v1.whatever\" ,\n \" object\" : \" event\" \n }" ;
162+ "{\n \" id\" : \" evt_test_webhook\" ,\n \" type\" : \" v1.whatever\" ,\n \" object\" : \" v2.core. event\" \n }" ;
163163 String secret = "whsec_test_secret" ;
164164 String signature = "bad signature" ;
165165
@@ -173,7 +173,7 @@ public void failsWebhookVerification()
173173 static final String v2EventNotificationWithRelatedObject =
174174 "{\n "
175175 + " \" id\" : \" evt_234\" ,\n "
176- + " \" object\" : \" event\" ,\n "
176+ + " \" object\" : \" v2.core. event\" ,\n "
177177 + " \" type\" : \" v1.billing.meter.error_report_triggered\" ,\n "
178178 + " \" livemode\" : false,\n "
179179 + " \" context\" : \" org_123\" ,\n "
@@ -191,7 +191,7 @@ public void failsWebhookVerification()
191191 static final String v2EventNotificationWithoutRelatedObject =
192192 "{\n "
193193 + " \" id\" : \" evt_234\" ,\n "
194- + " \" object\" : \" event\" ,\n "
194+ + " \" object\" : \" v2.core. event\" ,\n "
195195 + " \" type\" : \" v1.billing.meter.no_meter_found\" ,\n "
196196 + " \" livemode\" : false,\n "
197197 + " \" created\" : \" 2022-02-15T00:27:45.330Z\" \n "
@@ -200,7 +200,7 @@ public void failsWebhookVerification()
200200 static final String v2UnknownEventNotification =
201201 "{\n "
202202 + " \" id\" : \" evt_234\" ,\n "
203- + " \" object\" : \" event\" ,\n "
203+ + " \" object\" : \" v2.core. event\" ,\n "
204204 + " \" type\" : \" v1.imaginary_event\" ,\n "
205205 + " \" livemode\" : false,\n "
206206 + " \" created\" : \" 2022-02-15T00:27:45.330Z\" \n "
@@ -417,4 +417,28 @@ public void parseEventNotificationAndPull()
417417 assertEquals ("org_123" , v .getOptions ().getStripeContext ());
418418 }
419419 }
420+
421+ @ Test
422+ public void parseEventNotificationRejectsV1Payload ()
423+ throws InvalidKeyException , NoSuchAlgorithmException {
424+ StripeClient client = new StripeClient ("sk_123" );
425+
426+ String payload =
427+ "{\n \" id\" : \" evt_test_webhook\" ,\n \" object\" : \" event\" ,\n \" type\" : \" charge.succeeded\" \n }" ;
428+ String secret = "whsec_test_secret" ;
429+
430+ Map <String , Object > options = new HashMap <>();
431+ options .put ("payload" , payload );
432+ options .put ("secret" , secret );
433+
434+ String signature = WebhookTest .generateSigHeader (options );
435+
436+ IllegalArgumentException exception =
437+ assertThrows (
438+ IllegalArgumentException .class ,
439+ () -> {
440+ client .parseEventNotification (payload , signature , secret );
441+ });
442+ assertTrue (exception .getMessage ().contains ("constructEvent" ));
443+ }
420444}
0 commit comments