Skip to content

Commit d87f63f

Browse files
Merge pull request #209 from alexanderjordanbaker/NonAsciiDecodingTest
Bring test from https://github.com/apple/app-store-server-library-jav…
2 parents 2b566af + ff0671f commit d87f63f

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"transactionId":"23456",
3+
"originalTransactionId":"12345",
4+
"bundleId":"com.example",
5+
"productId":"com.example.product",
6+
"purchaseDate":1698148900000,
7+
"signedDate":1698148900000,
8+
"environment":"LocalTesting",
9+
"advancedCommerceInfo": {
10+
"descriptors": {
11+
"description": "Abonnement Café — 5,99 € par mois",
12+
"displayName": "Café Premium"
13+
},
14+
"items": [
15+
{
16+
"SKU": "com.example.sku.premium",
17+
"description": "プレミアム機能",
18+
"displayName": "プレミアム",
19+
"price": 9990
20+
}
21+
]
22+
}
23+
}

‎tests/test_decoded_payloads.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,24 @@ def test_transaction_decoding(self):
132132
self.assertEqual(119880, commitment.commitmentPrice)
133133
self.assertEqual(12, commitment.totalBillingPeriods)
134134

135+
def test_non_ascii_data_decoding_is_independent_of_the_default_charset(self):
136+
"""
137+
The payload of a JWS is always UTF-8 encoded, so decoding it must not depend on the default charset of the interpreter.
138+
The expected values below are written as escape sequences so that this test does not depend on the encoding
139+
used to compile it either.
140+
"""
141+
signed_transaction = create_signed_data_from_json('tests/resources/models/signedTransactionWithNonAsciiData.json')
142+
143+
signed_data_verifier = get_default_signed_data_verifier()
144+
145+
transaction = signed_data_verifier.verify_and_decode_signed_transaction(signed_transaction)
146+
147+
advanced_commerce_info = transaction.advancedCommerceInfo
148+
self.assertEqual("Abonnement Caf\u00e9 \u2014 5,99 \u20ac par mois", advanced_commerce_info.descriptors.description)
149+
self.assertEqual("Caf\u00e9 Premium", advanced_commerce_info.descriptors.displayName)
150+
self.assertEqual("\u30d7\u30ec\u30df\u30a2\u30e0\u6a5f\u80fd", advanced_commerce_info.items[0].description)
151+
self.assertEqual("\u30d7\u30ec\u30df\u30a2\u30e0", advanced_commerce_info.items[0].displayName)
152+
135153
def test_transaction_with_revocation_decoding(self):
136154
signed_transaction = create_signed_data_from_json('tests/resources/models/signedTransactionWithRevocation.json')
137155

‎tests/util.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def decode_json_from_signed_date(data: str) -> Dict[str, Any]:
2424

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

3030
def read_data_from_binary_file(path: str) -> str:

0 commit comments

Comments
 (0)