<gh_stars>100-1000
import os
import sys
import base64
import unittest
import pprint

sys.path.insert(0, os.path.abspath(__file__ + "/../.."))
from iap_local_receipt.iap_receipt import IAPReceipt
from iap_local_receipt.iap_receipt_verifier import IAPReceiptVerifier

SAMPLE_RECEIPT_B64 = [
"""
Put your Base64-encoded App Receipt Here
""",

"""
Put another Base64-encoded App Receipt Here
"""
]

APPLE_ROOT_CA_CERT = """
-----BEGIN CER<KEY>
-----END CERTIFICATE-----
"""


class BasicSanityTest(unittest.TestCase):
    verifier = IAPReceiptVerifier(ca_cert_string=APPLE_ROOT_CA_CERT)

    def validate_raw_receipt(self, b64_encoded):
        print('This unit test will fail until a valid receipt etc is added')

        pkcs7_der = base64.b64decode(b64_encoded)
        iap_receipt = self.verifier.verify_and_parse(pkcs7_der)

        pprint.pprint(self.verifier.last_receipt_der())
        pprint.pprint(iap_receipt.receipt)

        ret = iap_receipt.validate(product_id='PUT_YOUR_APP_ID_HERE',
                                   bundle_id='com.example.AwesomeApp',
                                   application_version='0',
                                   guid='urn:uuid:'
                                        '12345678-1234-5678-1234-567812345678')
        return ret

    def test_sanity(self):
        for i in range(len(SAMPLE_RECEIPT_B64)):
            self.assertTrue(self.validate_raw_receipt(SAMPLE_RECEIPT_B64[i]))

if __name__ == '__main__':
    unittest.main()

import os
import sys
import base64
import unittest
import pprint

sys.path.insert(0, os.path.abspath(__file__ + "/../.."))
from iap_local_receipt.iap_receipt import IAPReceipt
from iap_local_receipt.iap_receipt_verifier import IAPReceiptVerifier

SAMPLE_RECEIPT_B64 = [
"""
Put your Base64-encoded App Receipt Here
""",

"""
Put another Base64-encoded App Receipt Here
"""
]

APPLE_ROOT_CA_CERT = """
-----BEGIN CER<KEY>
-----END CERTIFICATE-----
"""


class BasicSanityTest(unittest.TestCase):
    verifier = IAPReceiptVerifier(ca_cert_string=APPLE_ROOT_CA_CERT)

    def validate_raw_receipt(self, b64_encoded):
        print('This unit test will fail until a valid receipt etc is added')

        pkcs7_der = base64.b64decode(b64_encoded)
        iap_receipt = self.verifier.verify_and_parse(pkcs7_der)

        pprint.pprint(self.verifier.last_receipt_der())
        pprint.pprint(iap_receipt.receipt)

        ret = iap_receipt.validate(product_id='PUT_YOUR_APP_ID_HERE',
                                   bundle_id='com.example.AwesomeApp',
                                   application_version='0',
                                   guid='urn:uuid:'
                                        '12345678-1234-5678-1234-567812345678')
        return ret

    def test_sanity(self):
        for i in range(len(SAMPLE_RECEIPT_B64)):
            self.assertTrue(self.validate_raw_receipt(SAMPLE_RECEIPT_B64[i]))

if __name__ == '__main__':
    unittest.main()
Put your Base64-encoded App Receipt Here Put another Base64-encoded App Receipt Here -----BEGIN CER<KEY> -----END CERTIFICATE-----