Exemplo n.º 1
0
    def setUp(self):
        self.backend = JanrainBackend()
        muser = mock.Mock()
        muser.DoesNotExist = User.DoesNotExist
        muser.objects = mock.Mock()
        muser.objects.get = mock.Mock()
        self.muser = muser

        self.janrain_user = mock.Mock()
Exemplo n.º 2
0
def login(request):
    try:
        token = request.POST['token']
    except KeyError:
        # TODO: set ERROR to something
        return HttpResponseRedirect('/')

    api_params = {
        'token': token,
        'apiKey': settings.JANRAIN_RPX_API_KEY,
        'format': 'json',
    }

    janrain_domain = settings.JANRAIN_DOMAIN
    janrain_response = urllib2.urlopen(
            "https://rpxnow.com/api/v2/auth_info",
            urllib.urlencode(api_params))
    resp_json = janrain_response.read()
    auth_info = json.loads(resp_json)
    u = None
    if auth_info['stat'] == 'ok':
        profile = auth_info['profile']
        u = auth.authenticate(profile=profile)

    if u is not None:
        request.user = u
        auth.login(request, u)
    else:
        # Auth failure
        jb=JanrainBackend()
        errmsg=''
        if jb.get_email(profile)=='':
            errmesg="Your identity did not include email information. Please make sure your email is registered with your ID provider."
        elif jb.get_provider(profile)=='':
            errmesg="You did not use a valid identity provider. Please try again with a different provider."
        else:
            errmesg="Miscellaneous Failure."            
        msg='Authentication Failure: %s'%errmesg
        messages.add_message(request, messages.ERROR, msg)
        
    try:
        return HttpResponseRedirect(request.GET['redirect_to'])
    except KeyError:
        return HttpResponseRedirect('/')
Exemplo n.º 3
0
class TestBackend(TestCase):
    def setUp(self):
        self.backend = JanrainBackend()
        muser = mock.Mock()
        muser.DoesNotExist = User.DoesNotExist
        muser.objects = mock.Mock()
        muser.objects.get = mock.Mock()
        self.muser = muser

        self.janrain_user = mock.Mock()

    def test_find_user_found(self):
        with mock.patch('janrain.backends.User', self.muser):
            self.muser.objects.get.return_value = True
            self.assertTrue(self.backend.find_user(self.janrain_user))

    def test_find_user_not_found(self):
        with mock.patch('janrain.backends.User', self.muser):
            self.muser.objects.get.side_effect = self.muser.DoesNotExist
            self.assertEqual(self.backend.find_user(self.janrain_user), None)