def receipt_signer(): destination = getattr(settings, "SIGNING_SERVER", None) if not destination: return "", "Signer is not configured." # Just send some test data into the signer. now = int(time.time()) not_valid = settings.SITE_URL + "/not-valid" data = { "detail": not_valid, "exp": now + 3600, "iat": now, "iss": settings.SITE_URL, "product": {"storedata": "id=1", "url": u"http://not-valid.com"}, "nbf": now, "typ": "purchase-receipt", "reissue": not_valid, "user": {"type": "directed-identifier", "value": u"something-not-valid"}, "verify": not_valid, } try: result = receipt.sign(data) except SigningError as err: msg = "Error on signing (%s): %s" % (destination, err) return msg, msg try: cert, rest = receipt.crack(result) except Exception as err: msg = "Error on cracking receipt (%s): %s" % (destination, err) return msg, msg # Check that the certs used to sign the receipts are not about to expire. limit = now + (60 * 60 * 24) # One day. if cert["exp"] < limit: msg = "Cert will expire soon (%s)" % destination return msg, msg cert_err_msg = "Error on checking public cert (%s): %s" location = cert["iss"] try: resp = requests.get(location, timeout=5, stream=False) except Exception as err: msg = cert_err_msg % (location, err) return msg, msg if not resp.ok: msg = cert_err_msg % (location, resp.reason) return msg, msg cert_json = resp.json() if not cert_json or "jwk" not in cert_json: msg = cert_err_msg % (location, "Not valid JSON/JWK") return msg, msg return "", "Signer working and up to date"
def receipt_signer(): destination = getattr(settings, 'SIGNING_SERVER', None) if not destination: return '', 'Signer is not configured.' # Just send some test data into the signer. now = int(time.time()) not_valid = (settings.SITE_URL + '/not-valid') data = {'detail': not_valid, 'exp': now + 3600, 'iat': now, 'iss': settings.SITE_URL, 'product': {'storedata': 'id=1', 'url': u'http://not-valid.com'}, 'nbf': now, 'typ': 'purchase-receipt', 'reissue': not_valid, 'user': {'type': 'directed-identifier', 'value': u'something-not-valid'}, 'verify': not_valid } try: result = receipt.sign(data) except SigningError as err: msg = 'Error on signing (%s): %s' % (destination, err) return msg, msg try: cert, rest = receipt.crack(result) except Exception as err: msg = 'Error on cracking receipt (%s): %s' % (destination, err) return msg, msg # Check that the certs used to sign the receipts are not about to expire. limit = now + (60 * 60 * 24) # One day. if cert['exp'] < limit: msg = 'Cert will expire soon (%s)' % destination return msg, msg cert_err_msg = 'Error on checking public cert (%s): %s' location = cert['iss'] try: resp = requests.get(location, timeout=5, stream=False) except Exception as err: msg = cert_err_msg % (location, err) return msg, msg if not resp.ok: msg = cert_err_msg % (location, resp.reason) return msg, msg cert_json = resp.json() if not cert_json or not 'jwk' in cert_json: msg = cert_err_msg % (location, 'Not valid JSON/JWK') return msg, msg return '', 'Signer working and up to date'
def test_completed_inapp_simulation(self): inapp = self.get_inapp_product( webapp=None, simulate=json.dumps({'result': 'postback'})) contribution = self.get_contribution(inapp=inapp, addon=None) data = self.get_status(self.get_contribution_url(contribution)) eq_(data['status'], 'complete') receipt = crack(data['receipt'])[0] eq_(receipt['typ'], 'test-receipt') eq_(receipt['product']['url'], settings.SITE_URL) storedata = parse_qs(receipt['product']['storedata']) eq_(storedata['id'][0], '0') eq_(storedata['contrib'][0], str(contribution.pk)) eq_(storedata['inapp_id'][0], str(contribution.inapp_product.guid))
def test_completed_inapp_purchase(self): price = Price.objects.get(pk=1) inapp = InAppProduct.objects.create( logo_url='logo.png', name='Magical Unicorn', price=price, webapp=self.contribution.addon) self.contribution.update(inapp_product=inapp) data = self.get() eq_(data['status'], 'complete') receipt = crack(data['receipt'])[0] eq_(receipt['typ'], 'purchase-receipt') eq_(receipt['product']['url'], self.contribution.addon.origin) storedata = parse_qs(receipt['product']['storedata']) eq_(storedata['id'][0], str(self.contribution.addon.pk)) eq_(storedata['contrib'][0], str(self.contribution.pk)) assert 'user' in receipt, ( 'The web platform requires a user value')
def test_completed_inapp_purchase(self): price = Price.objects.get(pk=1) inapp = InAppProduct.objects.create(logo_url='logo.png', name='Magical Unicorn', price=price, webapp=self.contribution.addon) self.contribution.update(inapp_product=inapp) data = self.get() eq_(data['status'], 'complete') receipt = crack(data['receipt'])[0] eq_(receipt['typ'], 'purchase-receipt') eq_(receipt['product']['url'], self.contribution.addon.origin) storedata = parse_qs(receipt['product']['storedata']) eq_(storedata['id'][0], str(self.contribution.addon.pk)) eq_(storedata['contrib'][0], str(self.contribution.pk)) assert 'user' in receipt, ('The web platform requires a user value')
def test_completed_inapp_simulation(self): inapp = self.get_inapp_product(webapp=None, simulate=json.dumps( {'result': 'postback'})) contribution = self.get_contribution(inapp=inapp, addon=None) data = self.get_status(self.get_contribution_url(contribution)) eq_(data['status'], 'complete') receipt = crack(data['receipt'])[0] eq_(receipt['typ'], 'test-receipt') eq_(receipt['product']['url'], settings.SITE_URL) storedata = parse_qs(receipt['product']['storedata']) eq_(storedata['id'][0], '0') eq_(storedata['contrib'][0], str(contribution.pk)) eq_(storedata['inapp_id'][0], str(contribution.inapp_product.guid))
def test_crack_mulitple(self): eq_(crack('~'.join([jwt.encode('foo', 'x'), jwt.encode('bar', 'y')])), [u'foo', u'bar'])
def test_crack(self): eq_(crack(jwt.encode('foo', 'x')), [u'foo'])
return True, 'Signer is not configured.' # Just send some test data into the signer. now = int(time.time()) not_valid = (settings.SITE_URL + '/not-valid') data = {'detail': not_valid, 'exp': now + 3600, 'iat': now, 'iss': settings.SITE_URL, 'product': {'storedata': 'id=1', 'url': u'http://not-valid.com'}, 'nbf': now, 'typ': 'purchase-receipt', 'reissue': not_valid, 'user': {'type': 'directed-identifier', 'value': u'something-not-valid'}, 'verify': not_valid } try: result = receipt.sign(data) except receipt.SigningError, err: return False, 'Error on signing (%s): %s' % (destination, err) try: cert, rest = receipt.crack(result) except Exception, err: return False, 'Error on cracking receipt (%s): %s' % (destination, err) # Check that the certs used to sign the receipts are not about to expire. limit = now + (60 * 60 * 24) # One day. if cert['exp'] < limit: return False, 'Cert will expire soon (%s)' % destination return True, 'Signer working and up to date'
def test_completed_inapp_purchase(self): contribution = self.get_contribution(inapp=self.get_inapp_product()) data = self.get_status(self.get_contribution_url(contribution)) eq_(data['status'], 'complete') receipt = crack(data['receipt'])[0] self.validate_inapp_receipt(receipt, contribution)
def test_crack_mulitple(self): eq_(crack("~".join([jwt.encode("foo", "x"), jwt.encode("bar", "y")])), [u"foo", u"bar"])
def test_crack(self): eq_(crack(jwt.encode("foo", "x")), [u"foo"])