Ejemplo n.º 1
0
    def test_expired(self):
        old = Receipt(sample).receipt_decoded()
        new = Receipt(reissue_receipt(sample)).receipt_decoded()
        for greater in ['exp', 'iat', 'nbf']:
            assert new[greater] > old[greater], (
                '{0} for new: {1} should be greater than old: {2}'.format(
                    greater, new[greater], old[greater]))

        for same in [
                'product', 'detail', 'iss', 'reissue', 'typ', 'user', 'verify'
        ]:
            eq_(new[same], old[same],
                ('{0} for new: {1} should be the same as old: {2}'.format(
                    greater, new[same], old[same])))
Ejemplo n.º 2
0
def reissue_receipt(receipt):
    """
    Reissues and existing receipt by updating the timestamps and resigning
    the receipt. This requires a well formatted receipt, but does not verify
    the receipt contents.

    :params receipt: an existing receipt
    """
    time_ = calendar.timegm(time.gmtime())
    receipt_obj = Receipt(receipt)
    data = receipt_obj.receipt_decoded()
    data.update({
        'exp': time_ + settings.WEBAPPS_RECEIPT_EXPIRY_SECONDS,
        'iat': time_,
        'nbf': time_,
    })
    return sign(data)
Ejemplo n.º 3
0
def reissue_receipt(receipt):
    """
    Reissues and existing receipt by updating the timestamps and resigning
    the receipt. This requires a well formatted receipt, but does not verify
    the receipt contents.

    :params receipt: an existing receipt
    """
    time_ = calendar.timegm(time.gmtime())
    receipt_obj = Receipt(receipt)
    data = receipt_obj.receipt_decoded()
    data.update({
        'exp': time_ + settings.WEBAPPS_RECEIPT_EXPIRY_SECONDS,
        'iat': time_,
        'nbf': time_,
    })
    return sign(data)
Ejemplo n.º 4
0
def check(model, data):
    """
    Checks the validity of the receipt against the verification service.

    `model`: the mode, of the receipt object to update with the results
    `data`: the actual receipt string sent from the client
    """
    model.checked = datetime.now()
    receipt = Receipt(data)
    log.info('Checking receipt: %s' % model.pk)
    try:
        result = receipt.verify_server()['status']
    except:
        log.error('There was an error with the verification.', exc_info=True)
        result = 'error'

    status = constants.VALID_LOOKUP[result]
    model.valid = status
    model.save()
    return constants.VALID_INVERTED[status]
Ejemplo n.º 5
0
    def test_expired(self):
        receipt_data = self.sample_app_receipt()
        curr_time = calendar.timegm(time.gmtime())
        receipt_data['iat'] = curr_time - 1000
        receipt_data['nbf'] = curr_time - 1000
        receipt_data['exp'] = curr_time
        receipt = sign(receipt_data)
        old = Receipt(receipt).receipt_decoded()
        new = Receipt(reissue_receipt(receipt)).receipt_decoded()
        for greater in ['exp', 'iat', 'nbf']:
            assert new[greater] > old[greater], (
                '{0} for new: {1} should be greater than old: {2}'.format(
                    greater, new[greater], old[greater]))

        for same in [
                'product', 'detail', 'iss', 'reissue', 'typ', 'user', 'verify'
        ]:
            eq_(new[same], old[same],
                ('{0} for new: {1} should be the same as old: {2}'.format(
                    greater, new[same], old[same])))
Ejemplo n.º 6
0
 def test_record_receipt(self, cef):
     r = self.post()
     ok_(Receipt(r.data['receipt']).receipt_decoded())
Ejemplo n.º 7
0
 def test_decode(self):
     res = self.anon.post(self.url, data=self.data)
     eq_(res.status_code, 201)
     data = json.loads(res.content)
     receipt = Receipt(data['receipt'].encode('ascii')).receipt_decoded()
     eq_(receipt['typ'], u'test-receipt')
Ejemplo n.º 8
0
 def test_record_receipt(self, cef):
     res = self.handle(self.profile)
     ok_(Receipt(res).receipt_decoded())
Ejemplo n.º 9
0
 def test_crypto_fails(self):
     r = Receipt('{0}~{1}'.format(self.cert, self.receipt))
     self.failUnlessRaises(VerificationError, r.verify_crypto)
Ejemplo n.º 10
0
 def test_crypto(self, rv):
     r = Receipt('{0}~{1}'.format(self.cert, self.receipt))
     ok_(r.verify_crypto())
Ejemplo n.º 11
0
 def test_verify(self, post):
     post.return_value = FakeResponse(json.dumps({"status": "ok"}))
     r = Receipt(self.receipt)
     eq_(r.verify_server()["status"], "ok")
Ejemplo n.º 12
0
 def test_verify(self, post):
     post.return_value = FakeResponse(json.dumps({'status': 'ok'}))
     r = Receipt(self.receipt)
     eq_(r.verify_server()['status'], 'ok')
Ejemplo n.º 13
0
 def test_cert(self):
     r = Receipt('{0}~{1}'.format(self.cert, self.receipt))
     eq_(r.cert_decoded()['cert'], 'key')
Ejemplo n.º 14
0
 def test_receipt(self):
     r = Receipt(self.receipt)
     eq_(r.verifier, 'y')
     eq_(r.issue, 1)
     eq_(r.expiry, 2)
Ejemplo n.º 15
0
 def test_crypto(self, rv):
     r = Receipt("{0}~{1}".format(self.cert, self.receipt))
     ok_(r.verify_crypto())
Ejemplo n.º 16
0
 def test_verify_fails(self, post):
     post.side_effect = VerificationError
     r = Receipt(self.receipt)
     self.failUnlessRaises(VerificationError, r.verify_server)
Ejemplo n.º 17
0
 def test_cert(self):
     r = Receipt("{0}~{1}".format(self.cert, self.receipt))
     eq_(r.cert_decoded()["cert"], "key")