@@ -30,13 +30,15 @@ class TestWebhooks:
3030 "webhook-signature" : f"v1,{ signature } " ,
3131 }
3232 secret = "whsec_zlFsbBZ8Xcodlpcu6NDTdSzZRLSdhkst"
33+
3334 @time_machine .travel (fake_now )
3435 def test_unwrap (self , client : Lithic ) -> None :
3536 payload = self .payload
3637 headers = self .headers
3738 secret = self .secret
3839
3940 client .webhooks .unwrap (payload , headers , secret = secret )
41+
4042 @time_machine .travel (fake_now )
4143 def test_verify_signature (self , client : Lithic ) -> None :
4244 payload = self .payload
@@ -117,6 +119,7 @@ def test_verify_signature(self, client: Lithic) -> None:
117119 headers = headers ,
118120 secret = secret ,
119121 )
122+
120123 @time_machine .travel (fake_now )
121124 def test_parse (self , client : Lithic ) -> None :
122125 valid_payload = """{"event_type":"account_holder.created","token":"00000000-0000-0000-0000-000000000001","account_token":"00000000-0000-0000-0000-000000000001","created":"2019-12-27T18:11:19.117Z","status":"ACCEPTED"}"""
@@ -151,6 +154,7 @@ def test_parse(self, client: Lithic) -> None:
151154 wrong_secret = f"whsec_{ base64 .b64encode (b'wrong' ).decode ('utf-8' )} "
152155 with pytest .raises (standardwebhooks .WebhookVerificationError ):
153156 client .webhooks .parse (valid_payload , headers = headers , secret = wrong_secret )
157+
154158 def test_parse_unsafe (self , client : Lithic ) -> None :
155159 valid_payload = """{"event_type":"account_holder.created","token":"00000000-0000-0000-0000-000000000001","account_token":"00000000-0000-0000-0000-000000000001","created":"2019-12-27T18:11:19.117Z","status":"ACCEPTED"}"""
156160
@@ -161,20 +165,6 @@ def test_parse_unsafe(self, client: Lithic) -> None:
161165 assert isinstance (result , AccountHolderCreatedWebhookEvent )
162166 assert result .event_type == "account_holder.created"
163167 assert result .token == "00000000-0000-0000-0000-000000000001"
164- @pytest .mark .parametrize (
165- "client_opt,method_opt" ,
166- [
167- ("whsec_c2VjcmV0Cg==" , None ),
168- ("wrong" , b"secret\n " ),
169- ("wrong" , "whsec_c2VjcmV0Cg==" ),
170- (None , b"secret\n " ),
171- (None , "whsec_c2VjcmV0Cg==" ),
172- ],
173- )
174- def test_method_parsed (self , client : Lithic , client_opt : str | None , method_opt : str | bytes | None ) -> None :
175- hook = standardwebhooks .Webhook (b"secret\n " )
176-
177- client = client .with_options (webhook_secret = client_opt )
178168
179169
180170class TestAsyncWebhooks :
@@ -190,13 +180,15 @@ class TestAsyncWebhooks:
190180 "webhook-signature" : f"v1,{ signature } " ,
191181 }
192182 secret = "whsec_zlFsbBZ8Xcodlpcu6NDTdSzZRLSdhkst"
183+
193184 @time_machine .travel (fake_now )
194185 def test_unwrap (self , async_client : AsyncLithic ) -> None :
195186 payload = self .payload
196187 headers = self .headers
197188 secret = self .secret
198189
199190 async_client .webhooks .unwrap (payload , headers , secret = secret )
191+
200192 @time_machine .travel (fake_now )
201193 def test_verify_signature (self , async_client : AsyncLithic ) -> None :
202194 payload = self .payload
@@ -277,6 +269,7 @@ def test_verify_signature(self, async_client: AsyncLithic) -> None:
277269 headers = headers ,
278270 secret = secret ,
279271 )
272+
280273 @time_machine .travel (fake_now )
281274 def test_parse (self , async_client : AsyncLithic ) -> None :
282275 valid_payload = """{"event_type":"account_holder.created","token":"00000000-0000-0000-0000-000000000001","account_token":"00000000-0000-0000-0000-000000000001","created":"2019-12-27T18:11:19.117Z","status":"ACCEPTED"}"""
@@ -311,6 +304,7 @@ def test_parse(self, async_client: AsyncLithic) -> None:
311304 wrong_secret = f"whsec_{ base64 .b64encode (b'wrong' ).decode ('utf-8' )} "
312305 with pytest .raises (standardwebhooks .WebhookVerificationError ):
313306 async_client .webhooks .parse (valid_payload , headers = headers , secret = wrong_secret )
307+
314308 def test_parse_unsafe (self , async_client : AsyncLithic ) -> None :
315309 valid_payload = """{"event_type":"account_holder.created","token":"00000000-0000-0000-0000-000000000001","account_token":"00000000-0000-0000-0000-000000000001","created":"2019-12-27T18:11:19.117Z","status":"ACCEPTED"}"""
316310
@@ -321,17 +315,3 @@ def test_parse_unsafe(self, async_client: AsyncLithic) -> None:
321315 assert isinstance (result , AccountHolderCreatedWebhookEvent )
322316 assert result .event_type == "account_holder.created"
323317 assert result .token == "00000000-0000-0000-0000-000000000001"
324- @pytest .mark .parametrize (
325- "client_opt,method_opt" ,
326- [
327- ("whsec_c2VjcmV0Cg==" , None ),
328- ("wrong" , b"secret\n " ),
329- ("wrong" , "whsec_c2VjcmV0Cg==" ),
330- (None , b"secret\n " ),
331- (None , "whsec_c2VjcmV0Cg==" ),
332- ],
333- )
334- def test_method_parsed (self , async_client : Lithic , client_opt : str | None , method_opt : str | bytes | None ) -> None :
335- hook = standardwebhooks .Webhook (b"secret\n " )
336-
337- async_client = async_client .with_options (webhook_secret = client_opt )
0 commit comments