Skip to content

Conversation

@zulquer
Copy link
Collaborator

@zulquer zulquer commented Jan 8, 2026

This pull request improves the handling of unicode characters in webhook validation and enhances the test coverage to ensure correct behavior with non-ASCII payloads. The main changes are grouped into improvements in unicode support and expanded test coverage.

Unicode handling improvements:

  • Updated the json.dumps call in src/multisafepay/util/webhook.py to use ensure_ascii=False, allowing unicode characters to be preserved in the compact JSON used for HMAC signature calculation.

Test coverage enhancements:

  • Added a new test, test_validate_with_unicode_characters, to verify that webhook validation works correctly when the payload contains unicode characters. This test ensures the signature is generated and validated as expected with non-ASCII data.
  • Imported additional modules (base64, hashlib, hmac, time) in tests/multisafepay/unit/util/test_unit_webhook.py to support the new unicode validation test.- Update Webhook.validate to use ensure_ascii=False during JSON reconstruction.
  • Add unit test for Unicode support in webhook validation (e.g., 'ñ', '€').

- Update Webhook.validate to use ensure_ascii=False during JSON reconstruction.
- Add unit test for Unicode support in webhook validation (e.g., 'ñ', '€').

(Fix)
@zulquer zulquer requested a review from Copilot January 8, 2026 08:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes webhook validation to correctly handle Unicode characters in payloads by ensuring the HMAC signature calculation preserves non-ASCII characters instead of escaping them.

Key changes:

  • Modified JSON serialization in webhook validation to preserve Unicode characters
  • Added comprehensive test coverage for Unicode character handling in webhook payloads

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/multisafepay/util/webhook.py Added ensure_ascii=False parameter to json.dumps to preserve Unicode characters during signature validation
tests/multisafepay/unit/util/test_unit_webhook.py Added new test case with Unicode characters and imported necessary cryptographic modules

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.69%. Comparing base (41f42f2) to head (323255c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #42   +/-   ##
=======================================
  Coverage   90.69%   90.69%           
=======================================
  Files         143      143           
  Lines        2471     2471           
=======================================
  Hits         2241     2241           
  Misses        230      230           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zulquer zulquer requested a review from danielcivit January 8, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants