Fix KeyError in verify_payment_link_signature on incomplete payload#333
Open
gottostartsomewhere wants to merge 1 commit into
Open
Conversation
verify_payment_link_signature guarded only razorpay_payment_id, payment_link_reference_id and payment_link_status, but also reads payment_link_id and razorpay_signature. A payload missing either of the latter raised KeyError instead of the documented graceful False return. Guard all required keys so incomplete payloads return False. Add a regression test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Utility.verify_payment_link_signatureis written to returnFalsefor an incomplete payload (it has an explicitelse: return Falsebranch). However, its guard only checks three keys:…while the body also reads
parameters['payment_link_id']andparameters['razorpay_signature']. So a payload that is missingpayment_link_id(orrazorpay_signature) but has the three guarded keys raisesKeyErrorinstead of returningFalse.Reproduce
Fix
Guard all required keys so an incomplete payload returns
Falseas intended, rather than raising. Behaviour for complete payloads is unchanged.Tests
Added
test_verify_payment_link_signature_missing_key, which asserts a payload missingpayment_link_idreturnsFalse. It fails onmaster(KeyError) and passes with this change. Fulltests/test_client_utility.pysuite passes (7 tests).