diff --git a/tests/resources/models/signedTransactionWithNonAsciiData.json b/tests/resources/models/signedTransactionWithNonAsciiData.json new file mode 100644 index 00000000..cfdb2c5e --- /dev/null +++ b/tests/resources/models/signedTransactionWithNonAsciiData.json @@ -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 + } + ] + } +} diff --git a/tests/test_decoded_payloads.py b/tests/test_decoded_payloads.py index 20232480..faec8b28 100644 --- a/tests/test_decoded_payloads.py +++ b/tests/test_decoded_payloads.py @@ -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') diff --git a/tests/util.py b/tests/util.py index 6dbeb21a..f1d8bd61 100644 --- a/tests/util.py +++ b/tests/util.py @@ -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: