Commit bdd04f56 by James Tait

Guard update_user_openid against missing account_verified element; DRY up ax…

Guard update_user_openid against missing account_verified element; DRY up ax account_verified tests.
parent 203c4cca
...@@ -282,7 +282,7 @@ class OpenIDBackend: ...@@ -282,7 +282,7 @@ class OpenIDBackend:
def update_user_openid(self, user_openid, details): def update_user_openid(self, user_openid, details):
updated = False updated = False
if details['account_verified'] is not None: if details.get('account_verified', None) is not None:
user_openid.account_verified = details['account_verified'] user_openid.account_verified = details['account_verified']
updated = True updated = True
if updated: if updated:
......
...@@ -1144,7 +1144,7 @@ class RelyingPartyTests(TestCase): ...@@ -1144,7 +1144,7 @@ class RelyingPartyTests(TestCase):
self.assertEqual(['email', 'language'], sreg_request.required) self.assertEqual(['email', 'language'], sreg_request.required)
self.assertEqual(['fullname', 'nickname'], sreg_request.optional) self.assertEqual(['fullname', 'nickname'], sreg_request.optional)
def test_login_attribute_exchange(self): def _test_login_attribute_exchange(self, validation_type, is_verified):
settings.OPENID_UPDATE_DETAILS_FROM_SREG = True settings.OPENID_UPDATE_DETAILS_FROM_SREG = True
user = User.objects.create_user('testuser', 'someone@example.com') user = User.objects.create_user('testuser', 'someone@example.com')
useropenid = UserOpenID( useropenid = UserOpenID(
...@@ -1202,9 +1202,10 @@ class RelyingPartyTests(TestCase): ...@@ -1202,9 +1202,10 @@ class RelyingPartyTests(TestCase):
'http://axschema.org/namePerson/last', 'Lastname') 'http://axschema.org/namePerson/last', 'Lastname')
fetch_response.addValue( fetch_response.addValue(
'http://axschema.org/namePerson/friendly', 'someuser') 'http://axschema.org/namePerson/friendly', 'someuser')
if validation_type is not None:
fetch_response.addValue( fetch_response.addValue(
'http://ns.login.ubuntu.com/2013/validation/account', 'http://ns.login.ubuntu.com/2013/validation/account',
'token_via_email') validation_type)
openid_response.addExtension(fetch_response) openid_response.addExtension(fetch_response)
response = self.complete(openid_response) response = self.complete(openid_response)
self.assertRedirects(response, 'http://testserver/getuser/') self.assertRedirects(response, 'http://testserver/getuser/')
...@@ -1222,60 +1223,16 @@ class RelyingPartyTests(TestCase): ...@@ -1222,60 +1223,16 @@ class RelyingPartyTests(TestCase):
self.assertEquals(user.email, 'foo@example.com') self.assertEquals(user.email, 'foo@example.com')
# And the verified status of their UserOpenID # And the verified status of their UserOpenID
user_openid = UserOpenID.objects.get(user=user) user_openid = UserOpenID.objects.get(user=user)
self.assertTrue(user_openid.account_verified) self.assertEqual(user_openid.account_verified, is_verified)
def test_login_attribute_exchange_unrecognised_validation(self): def test_login_attribute_exchange_with_validation(self):
settings.OPENID_UPDATE_DETAILS_FROM_SREG = True self._test_login_attribute_exchange('token_via_email', True)
user = User.objects.create_user('testuser', 'someone@example.com')
useropenid = UserOpenID(
user=user,
claimed_id='http://example.com/identity',
display_id='http://example.com/identity',
account_verified=False)
useropenid.save()
# Configure the provider to advertise attribute exchange
# protocol and start the authentication process:
self.provider.type_uris.append('http://openid.net/srv/ax/1.0')
response = self.client.post('/openid/login/',
{'openid_identifier': 'http://example.com/identity',
'next': '/getuser/'})
self.assertContains(response, 'OpenID transaction in progress')
openid_request = self.provider.parseFormPost(response.content)
fetch_request = ax.FetchRequest.fromOpenIDRequest(openid_request)
# Build up a response including AX data.
openid_response = openid_request.answer(True)
fetch_response = ax.FetchResponse(fetch_request)
fetch_response.addValue(
'http://axschema.org/contact/email', 'foo@example.com')
fetch_response.addValue(
'http://axschema.org/namePerson/first', 'Firstname')
fetch_response.addValue(
'http://axschema.org/namePerson/last', 'Lastname')
fetch_response.addValue(
'http://axschema.org/namePerson/friendly', 'someuser')
fetch_response.addValue(
'http://ns.login.ubuntu.com/2013/validation/account',
'unrecognised_scheme')
openid_response.addExtension(fetch_response)
response = self.complete(openid_response)
self.assertRedirects(response, 'http://testserver/getuser/')
# And they are now logged in as testuser (the passed in def test_login_attribute_exchange_without_validation(self):
# nickname has not caused the username to change), because self._test_login_attribute_exchange(None, False)
# settings.OPENID_FOLLOW_RENAMES is False.
response = self.client.get('/getuser/')
self.assertEquals(response.content, 'testuser')
# The user's full name and email have been updated. def test_login_attribute_exchange_unrecognised_validation(self):
user = User.objects.get(username='testuser') self._test_login_attribute_exchange('unrecognised_scheme', False)
self.assertEquals(user.first_name, 'Firstname')
self.assertEquals(user.last_name, 'Lastname')
self.assertEquals(user.email, 'foo@example.com')
# The verified status of their UserOpenID is unchanged
user_openid = UserOpenID.objects.get(user=user)
self.assertFalse(user_openid.account_verified)
def test_login_teams(self): def test_login_teams(self):
settings.OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO = False settings.OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO = False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment