def test_message_digest_valid(signed_attributes_fixture, token_fixture): # Given signed attributes signed_attrs = signed_attributes_fixture # Given a payment data from the same token # hashed via the sha256 hashfunc hashed_payment_data = hashlib.sha256( applepay_utils.get_payment_data(token_fixture)).digest() # When the message digest is validated is_valid = applepay_utils.validate_message_digest(signed_attrs, hashed_payment_data) # Then the message digest is valid assert is_valid is True
def test_missing_message_digest(token_fixture): # Given some signed attrs that are missing the message digest signed_attrs = [] # Given a payment data from the same token # hashed via the sha256 hashfunc hashed_payment_data = hashlib.sha256( applepay_utils.get_payment_data(token_fixture)).digest() # When the message digest is validated is_valid = applepay_utils.validate_message_digest(signed_attrs, hashed_payment_data) # Then the message digest is not valid assert is_valid is False
def test_get_payment_data(): # Given an apple pay token with minimal data token = { "version": "does not matter", "data": base64.b64encode('sir robin;'), "signature": "does not matter", "header": { "transactionId": binascii.hexlify('sir lancelot;'), "ephemeralPublicKey": base64.b64encode('king arthur;'), "publicKeyHash": "does not matter" } } # When the payment data is accessed and decoded payment_data = applepay_utils.get_payment_data(token) # Then it is the expected value expected_payment_data = 'king arthur;sir robin;sir lancelot;' assert expected_payment_data == payment_data