Commit 8b46f393 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

astakos: Handle pending third party provider validation issues

skip validation errors and reset invalid field values for received user
metadata.
parent 952e2902
......@@ -73,13 +73,30 @@ class ShibbolethTests(TestCase):
self.assertContains(r, messages.SHIBBOLETH_MISSING_NAME)
astakos_settings.SHIBBOLETH_REQUIRE_NAME_INFO = False
# shibboleth logged us in
client.set_tokens(mail="kpap@synnefo.org", remote_user="kpapeppn",
cn="Kostas Papadimitriou" + 30*"*",
ep_affiliation="Test Affiliation")
r = client.get(ui_url('login/shibboleth?'), follow=True,
**{'HTTP_SHIB_CUSTOM_IDP_KEY': 'test'})
# name exceeds first_name character limit, validation error skipped
self.assertEqual(r.status_code, 200)
pending = PendingThirdPartyUser.objects.get()
self.assertEqual(pending.first_name, "Kostas")
self.assertEqual(pending.last_name, None)
# shibboleth logged us in
client.set_tokens(mail="kpap@synnefo.org", remote_user="kpapeppn",
cn="Kostas Papadimitriou",
ep_affiliation="Test Affiliation")
r = client.get(ui_url('login/shibboleth?'), follow=True,
**{'HTTP_SHIB_CUSTOM_IDP_KEY': 'test'})
token = PendingThirdPartyUser.objects.get().token
pending = PendingThirdPartyUser.objects.get()
token = pending.token
self.assertEqual(pending.first_name, "Kostas")
self.assertEqual(pending.last_name, "Papadimitriou")
self.assertRedirects(r, ui_url('signup?third_party_token=%s' % token))
self.assertEqual(r.status_code, 200)
......
......@@ -36,6 +36,7 @@ import json
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.core.validators import ValidationError
from django.db import transaction
from astakos.im.models import PendingThirdPartyUser, AstakosUser
......@@ -132,6 +133,18 @@ def handle_third_party_signup(request, userid, provider_module,
user.info = json.dumps(provider_info)
user.generate_token()
# skip non required fields validation errors. Reset the field instead of
# raising a validation exception.
try:
user.full_clean()
except ValidationError, e:
non_required_fields = ['email', 'first_name',
'last_name', 'affiliation']
for field in e.message_dict.keys():
if field in non_required_fields:
setattr(user, field, None)
user.save()
extra_context['provider'] = provider.module
......
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