Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/resources/models/signedTransactionWithNonAsciiData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"transactionId":"23456",
"originalTransactionId":"12345",
"bundleId":"com.example",
"productId":"com.example.product",
"purchaseDate":1698148900000,
"signedDate":1698148900000,
"environment":"LocalTesting",
"advancedCommerceInfo": {
"descriptors": {
"description": "Abonnement Café — 5,99 € par mois",
"displayName": "Café Premium"
},
"items": [
{
"SKU": "com.example.sku.premium",
"description": "プレミアム機能",
"displayName": "プレミアム",
"price": 9990
}
]
}
}
18 changes: 18 additions & 0 deletions tests/test_decoded_payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ def test_transaction_decoding(self):
self.assertEqual(119880, commitment.commitmentPrice)
self.assertEqual(12, commitment.totalBillingPeriods)

def test_non_ascii_data_decoding_is_independent_of_the_default_charset(self):
"""
The payload of a JWS is always UTF-8 encoded, so decoding it must not depend on the default charset of the interpreter.
The expected values below are written as escape sequences so that this test does not depend on the encoding
used to compile it either.
"""
signed_transaction = create_signed_data_from_json('tests/resources/models/signedTransactionWithNonAsciiData.json')

signed_data_verifier = get_default_signed_data_verifier()

transaction = signed_data_verifier.verify_and_decode_signed_transaction(signed_transaction)

advanced_commerce_info = transaction.advancedCommerceInfo
self.assertEqual("Abonnement Caf\u00e9 \u2014 5,99 \u20ac par mois", advanced_commerce_info.descriptors.description)
self.assertEqual("Caf\u00e9 Premium", advanced_commerce_info.descriptors.displayName)
self.assertEqual("\u30d7\u30ec\u30df\u30a2\u30e0\u6a5f\u80fd", advanced_commerce_info.items[0].description)
self.assertEqual("\u30d7\u30ec\u30df\u30a2\u30e0", advanced_commerce_info.items[0].displayName)

def test_transaction_with_revocation_decoding(self):
signed_transaction = create_signed_data_from_json('tests/resources/models/signedTransactionWithRevocation.json')

Expand Down
2 changes: 1 addition & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def decode_json_from_signed_date(data: str) -> Dict[str, Any]:

def read_data_from_file(path: str) -> str:
full_path = os.path.join(path)
with open(full_path, mode='r') as test_file:
with open(full_path, mode='r', encoding='utf-8') as test_file:
return test_file.read()

def read_data_from_binary_file(path: str) -> str:
Expand Down