From b61fa627fd5fd1b4f38b0e94f3f76476698da490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sun, 21 Oct 2018 15:20:23 +0200 Subject: [PATCH] Fix usage with CASClient V2 --- allauth_cas/views.py | 2 +- tests/test_views.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/allauth_cas/views.py b/allauth_cas/views.py index d2ea9b7..b27b3c7 100644 --- a/allauth_cas/views.py +++ b/allauth_cas/views.py @@ -217,7 +217,7 @@ class CASCallbackView(CASView): # Keep tracks of the last used CAS provider. request.session[CAS_PROVIDER_SESSION_KEY] = self.provider.id - data = (uid, extra) + data = (uid, extra or {}) # Finish the login flow. login = self.adapter.complete_login(request, data) diff --git a/tests/test_views.py b/tests/test_views.py index ebae670..e7b04e1 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -184,7 +184,7 @@ class CASCallbackViewTests(CASViewTestCase): self.assertEqual('/accounts/theid/login/callback/', url) def test_ticket_valid(self): - """p( + """ If ticket is valid, the user is logged in. """ self.patch_cas_response(username='username', valid_ticket='123456') @@ -211,6 +211,18 @@ class CASCallbackViewTests(CASViewTestCase): r = self.client.get('/accounts/theid/login/callback/') self.assertLoginFailure(r) + def test_attributes_is_none(self): + """ + Without extra attributes, CASClientV2 of python-cas returns None. + """ + self.patch_cas_response( + username='username', valid_ticket='123456', attributes=None + ) + r = self.client.get('/accounts/theid/login/callback/', { + 'ticket': '123456', + }) + self.assertLoginSuccess(r) + class CASLogoutViewTests(CASViewTestCase):