Skip to content

Commit

Permalink
do more at once
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Dec 6, 2024
1 parent c2e774d commit 61c0ac8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 5 additions & 7 deletions src/edutap/wallet_google/handlers/validate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .._vendor.google_pay_token_decryption import GooglePayError
from .._vendor.google_pay_token_decryption import GooglePayTokenDecryptor
from ..models.callback import CallbackData
from ..models.callback import SignedMessage
from ..settings import GoogleWalletSettings


Expand All @@ -18,18 +18,16 @@ def _raw_private_key(inkey: str) -> str:
return result


def verify_signature(data: CallbackData) -> bool:
def verified_signed_message(data: CallbackData) -> SignedMessage:
"""
Verifies the signature of the callback data.
and returns the parsed SignedMessage
"""
settings = GoogleWalletSettings()
decryptor = GooglePayTokenDecryptor(
settings.google_root_signing_public_keys.dict()["keys"],
settings.issuer_id,
_raw_private_key(settings.credentials_info["private_key"]),
)
try:
decryptor.verify_signature(dict(data))
except GooglePayError:
return False
return True
decryptor.verify_signature(dict(data))
return SignedMessage.model_validate(data.signedMessage)
11 changes: 8 additions & 3 deletions tests/test_handler_validate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from edutap.wallet_google.handlers.validate import verify_signature
from edutap.wallet_google._vendor.google_pay_token_decryption import GooglePayError
from edutap.wallet_google.models.callback import CallbackData

import pytest


callbackdata_for_test_failure = {
"signature": "foo",
Expand All @@ -18,6 +20,9 @@
}


def test_handler_validate_valid():
def test_handler_validate_invalid():
from edutap.wallet_google.handlers.validate import verified_signed_message

data = CallbackData.model_validate(callbackdata_for_test_failure)
assert verify_signature(data) is False
with pytest.raises(GooglePayError):
verified_signed_message(data)

0 comments on commit 61c0ac8

Please sign in to comment.