Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #69 from mozilla-services/67_fix_error_formatting_…
Browse files Browse the repository at this point in the history
…in_oauth

Fix error formatting in OAuth endpoints (fixes #67)
  • Loading branch information
Natim committed Mar 4, 2015
2 parents 2bb9363 + 50f1c5b commit e521232
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cliquet/tests/test_views_oauth.py
Expand Up @@ -8,6 +8,11 @@
class LoginViewTest(BaseWebTest, unittest.TestCase):
url = '/fxa-oauth/login?redirect=http://perdu.com/'

def test_redirect_parameter_is_mandatory(self):
url = '/fxa-oauth/login'
r = self.app.get(url, status=400)
self.assertIn('redirect', r.json['message'])

def test_login_view_persists_state(self):
r = self.app.get(self.url)
url = r.headers['Location']
Expand Down Expand Up @@ -63,7 +68,8 @@ def test_fails_if_no_ongoing_session(self):
def test_fails_if_state_or_code_is_missing(self):
headers = {'Cookie': 'state=abc'}
for params in ['', '?state=abc', '?code=1234']:
self.app.get(self.url + params, headers=headers, status=400)
r = self.app.get(self.url + params, headers=headers, status=400)
self.assertIn('missing', r.json['message'])

def test_fails_if_state_does_not_match(self):
self.app.app.registry.session.set('def', 'http://foobar')
Expand Down
12 changes: 9 additions & 3 deletions cliquet/views/oauth.py
Expand Up @@ -13,9 +13,15 @@
from cliquet.views.errors import authorization_required
from cliquet import logger

login = Service(name='fxa-oauth-login', path='/fxa-oauth/login')
params = Service(name='fxa-oauth-params', path='/fxa-oauth/params')
token = Service(name='fxa-oauth-token', path='/fxa-oauth/token')
login = Service(name='fxa-oauth-login',
path='/fxa-oauth/login',
error_handler=errors.json_error_handler)
params = Service(name='fxa-oauth-params',
path='/fxa-oauth/params',
error_handler=errors.json_error_handler)
token = Service(name='fxa-oauth-token',
path='/fxa-oauth/token',
error_handler=errors.json_error_handler)


def fxa_conf(request, name):
Expand Down

0 comments on commit e521232

Please sign in to comment.