Permalink
Browse files

start of lib/pay (bug 795127)

  • Loading branch information...
1 parent ad04ff2 commit 85cd006124a58457c59cc256ffc56209c90e8bcb @andymckay andymckay committed Oct 3, 2012
Showing with 55 additions and 5 deletions.
  1. 0 lib/pay/samples.py
  2. +17 −3 lib/pay/tests.py
  3. +29 −1 lib/pay/views.py
  4. +9 −1 webpay/settings/base.py
View
No changes.
View
@@ -1,10 +1,24 @@
+import json
+
from django import test
from django.core.urlresolvers import reverse
+import jwt
from nose.tools import eq_
+from moz_inapp_pay.tests import JWTtester
+
+class TestVerify(JWTtester):
+
+ def setUp(self):
+ self.url = '/en-US' + reverse('verify')
+
+ def test_get(self):
+ eq_(self.client.get(self.url).status_code, 405)
-class TestVerify(test.TestCase):
+ def test_post_bad(self):
+ eq_(self.client.post(self.url).status_code, 400)
- def hello(self):
- eq_(self.client.get(reverse('verify')).status_code, 200)
+ def test_post_some_jwt(self):
+ payload = self.request()
+ eq_(self.client.post(self.url, payload).status_code, 200)
View
@@ -1,5 +1,33 @@
from django import http
+from django.conf import settings
+from django.views.decorators.http import require_POST
+import commonware.log
+from moz_inapp_pay.exc import InvalidJWT, RequestExpired
+from moz_inapp_pay.verify import verify_jwt
+from session_csrf import anonymous_csrf_exempt
+
+log = commonware.log.getLogger('w.pay')
+
+
+def error(msg, request):
+ log.error(msg, exc_info=True)
+ if settings.DEBUG:
+ raise
+ else:
+ return http.HttpResponseBadRequest()
+
+@anonymous_csrf_exempt
+@require_POST
def verify(request):
- return http.HttpResponse('Hello world.')
+ data = request.body
+ try:
+ res = verify_jwt(data, settings.KEY, settings.SECRET)
+ except (InvalidJWT, RequestExpired):
+ return error(u'Failed to parse JWT', error)
+ if not res:
+ print res
+ return http.HttpResponseBadRequest()
+
+ return http.HttpResponse('ok')
View
@@ -13,6 +13,7 @@
# Application base, containing global templates.
'%s.base' % PROJECT_MODULE,
'lib.pay',
+ 'tower'
]
LOCALE_PATHS = (
@@ -63,7 +64,7 @@
LOGGING = dict(loggers=dict(playdoh = {'level': logging.DEBUG}))
MIDDLEWARE_CLASSES = (
- #'funfactory.middleware.LocaleURLMiddleware',
+ 'funfactory.middleware.LocaleURLMiddleware',
'multidb.middleware.PinningRouterMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -74,3 +75,10 @@
'mobility.middleware.DetectMobileMiddleware',
'mobility.middleware.XMobileMiddleware',
)
+
+# This is the key and secret for the JWT that is going to come in.
+KEY = ''
+SECRET = ''
+
+DEBUG = True
+DEBUG_PROPAGATE_EXCEPTIONS = False

0 comments on commit 85cd006

Please sign in to comment.