add in exp and reissue mkt/webapps/tests/test_models.py mkt/webapps/models.py (bug 745846)
This commit is contained in:
Родитель
489817d659
Коммит
60a20e1a92
|
@ -1365,6 +1365,8 @@ LOGIN_RATELIMIT_ALL_USERS = '15/m'
|
|||
WEBAPPS_RECEIPT_URL = '%s/verify/' % SITE_URL
|
||||
# The key we'll use to sign webapp receipts.
|
||||
WEBAPPS_RECEIPT_KEY = ''
|
||||
# The expiry that we will add into the receipt.
|
||||
WEBAPPS_RECEIPT_EXPIRY_SECONDS = 60 * 60 * 24 * 7
|
||||
|
||||
# How long a watermarked addon should be re-used for, after this
|
||||
# time it will be regenerated.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import calendar
|
||||
import json
|
||||
import time
|
||||
from urllib import urlencode
|
||||
|
@ -237,6 +238,7 @@ def create_receipt(installed_pk):
|
|||
addon_pk = installed.addon.pk
|
||||
verify = '%s%s' % (settings.WEBAPPS_RECEIPT_URL, addon_pk)
|
||||
detail = reverse('account.purchases.receipt', args=[addon_pk])
|
||||
reissue = installed.addon.get_purchase_url('reissue')
|
||||
receipt = dict(typ='purchase-receipt',
|
||||
product={'url': installed.addon.origin,
|
||||
'storedata': urlencode({'id': int(addon_pk)})},
|
||||
|
@ -244,9 +246,12 @@ def create_receipt(installed_pk):
|
|||
'value': installed.uuid},
|
||||
iss=settings.SITE_URL,
|
||||
nbf=time.mktime(installed.created.timetuple()),
|
||||
iat=time.time(),
|
||||
iat=calendar.timegm(time.gmtime()),
|
||||
exp=(calendar.timegm(time.gmtime()) +
|
||||
settings.WEBAPPS_RECEIPT_EXPIRY_SECONDS),
|
||||
detail=absolutify(detail),
|
||||
verify=absolutify(verify))
|
||||
verify=absolutify(verify),
|
||||
reissue=absolutify(reissue))
|
||||
if settings.SIGNING_SERVER_ACTIVE:
|
||||
# The shiny new code.
|
||||
cef(installed.user, installed.addon, 'sign', 'A signing request')
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import calendar
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import test_utils
|
||||
|
@ -274,9 +276,13 @@ class TestReceipt(amo.tests.TestCase):
|
|||
encode.return_value = 'tmp-to-keep-memoize-happy'
|
||||
ins = self.create_install(self.user, self.webapp)
|
||||
create_receipt(ins.pk)
|
||||
product = encode.call_args[0][0]['product']
|
||||
eq_(product['url'], self.webapp.manifest_url[:-1])
|
||||
eq_(product['storedata'], 'id=%s' % int(ins.addon.pk))
|
||||
receipt = encode.call_args[0][0]
|
||||
eq_(receipt['product']['url'], self.webapp.manifest_url[:-1])
|
||||
eq_(receipt['product']['storedata'], 'id=%s' % int(ins.addon.pk))
|
||||
assert receipt['exp'] > (calendar.timegm(time.gmtime()) +
|
||||
settings.WEBAPPS_RECEIPT_EXPIRY_SECONDS -
|
||||
100)
|
||||
eq_(receipt['reissue'], self.webapp.get_purchase_url('reissue'))
|
||||
|
||||
@mock.patch.object(settings, 'SIGNING_SERVER_ACTIVE', True)
|
||||
@mock.patch('mkt.webapps.models.sign')
|
||||
|
|
Загрузка…
Ссылка в новой задаче