def test_new_expiry(self, sign): receipt_data = get_sample_app_receipt() receipt_data['exp'] = old = calendar.timegm(time.gmtime()) - 10000 self.make_purchase() sign.return_value = '' self.verify_receipt_data(receipt_data) assert sign.call_args[0][0]['exp'] > old
def test_expired_has_receipt(self, sign): sign.return_value = '' receipt_data = get_sample_app_receipt() receipt_data['exp'] = calendar.timegm(time.gmtime()) - 1000 self.make_purchase() res = self.verify_receipt_data(receipt_data) assert 'receipt' in res
def test_no_user(self, log): receipt_data = get_sample_app_receipt() del receipt_data['user'] res = self.verify_receipt_data(receipt_data) eq_(res['status'], 'invalid') eq_(res['reason'], 'NO_DIRECTED_IDENTIFIER') ok_(log.called)
def test_garbage_expired(self, sign): sign.return_value = '' receipt_data = get_sample_app_receipt() receipt_data['exp'] = 'a' self.make_purchase() res = self.verify_receipt_data(receipt_data) eq_(res['status'], 'expired')
def test_expired(self, log, sign): sign.return_value = '' receipt_data = get_sample_app_receipt() receipt_data['exp'] = calendar.timegm(time.gmtime()) - 1000 self.make_purchase() res = self.verify_receipt_data(receipt_data) eq_(res['status'], 'expired') ok_(log.called)
def test_premium_app_refund(self, log): self.app.update(premium_type=amo.ADDON_PREMIUM) purchase = self.make_purchase() for type in [amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]: purchase.update(type=type) res = self.verify_receipt_data(get_sample_app_receipt()) eq_(res['status'], 'refunded') eq_(log.call_count, 2)
def test_product_barf_store_data_for_app(self): self.make_purchase() for storedata in (urlencode({'id': 'NaN'}), 'NaN'): data = get_sample_app_receipt() data['product'] = {'url': 'http://f.com', 'storedata': storedata} res = self.verify_receipt_data(data) eq_(res['status'], 'invalid') eq_(res['reason'], 'WRONG_STOREDATA')
def test_premium_dont_check(self): self.app.update(premium_type=amo.ADDON_PREMIUM) res = self.verify_receipt_data( get_sample_app_receipt(), check_purchase=False ) # Because the receipt is the wrong type for skipping purchase. eq_(res['status'], 'invalid') eq_(res['reason'], 'WRONG_TYPE')
def test_expired(self): receipt_data = get_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])))
def test_product_ok_store_data(self): self.make_purchase() data = get_sample_app_receipt() data['product'] = {'url': 'http://f.com', 'storedata': urlencode({'id': 337141})} eq_(self.verify_receipt_data(data)['status'], 'ok')
def test_expired_not_signed(self): receipt_data = get_sample_app_receipt() receipt_data['exp'] = calendar.timegm(time.gmtime()) - 10000 self.make_purchase() res = self.verify_receipt_data(receipt_data) eq_(res['status'], 'expired')
def test_premium_no_charge(self): self.app.update(premium_type=amo.ADDON_PREMIUM) purchase = self.make_purchase() purchase.update(type=amo.CONTRIB_NO_CHARGE) res = self.verify_receipt_data(get_sample_app_receipt()) eq_(res['status'], 'ok', res)
def test_other_premiums(self): self.make_purchase() for k in (amo.ADDON_PREMIUM, amo.ADDON_PREMIUM_INAPP): self.app.update(premium_type=k) res = self.verify_receipt_data(get_sample_app_receipt()) eq_(res['status'], 'ok', res)
def test_premium_app_contribution(self): self.app.update(premium_type=amo.ADDON_PREMIUM) # There's no purchase, but the last entry we have is a sale. self.make_contribution() res = self.verify_receipt_data(get_sample_app_receipt()) eq_(res['status'], 'ok', res)
def test_no_app(self): receipt_data = get_sample_app_receipt() del receipt_data['product'] res = self.verify_receipt_data(receipt_data) eq_(res['status'], 'invalid') eq_(res['reason'], 'WRONG_STOREDATA')
def test_premium_dont_check_properly(self): self.app.update(premium_type=amo.ADDON_PREMIUM) receipt_data = get_sample_app_receipt() receipt_data['typ'] = 'developer-receipt' res = self.verify_receipt_data(receipt_data, check_purchase=False) eq_(res['status'], 'ok', res)
def test_premium_app_purchased(self): self.app.update(premium_type=amo.ADDON_PREMIUM) self.make_purchase() res = self.verify_receipt_data(get_sample_app_receipt()) eq_(res['status'], 'ok', res)
def test_user_type_incorrect(self): receipt_data = get_sample_app_receipt() receipt_data['user']['type'] = 'nope' res = self.verify_receipt_data(receipt_data) eq_(res['status'], 'invalid') eq_(res['reason'], 'NO_DIRECTED_IDENTIFIER')
def test_premium_app_not_purchased(self): self.app.update(premium_type=amo.ADDON_PREMIUM) res = self.verify_receipt_data(get_sample_app_receipt()) eq_(res['status'], 'invalid') eq_(res['reason'], 'NO_PURCHASE')
def test_type(self): receipt_data = get_sample_app_receipt() receipt_data['typ'] = 'anything' res = self.verify_receipt_data(receipt_data) eq_(res['status'], 'invalid') eq_(res['reason'], 'WRONG_TYPE')
def test_user_incorrect(self): receipt_data = get_sample_app_receipt() receipt_data['user']['value'] = 'ugh' res = self.verify_receipt_data(receipt_data) eq_(res['status'], 'invalid') eq_(res['reason'], 'NO_PURCHASE')
def test_user_deleted(self): self.user.delete() res = self.verify_receipt_data(get_sample_app_receipt()) eq_(res['status'], 'invalid') eq_(res['reason'], 'NO_PURCHASE')