コード例 #1
0
ファイル: test_views.py プロジェクト: pop993012/111122
    def test_begin_view(self):
        response = self.client.get(reverse('social:begin', kwargs={'backend': 'facebook'}))
        self.assertEqual(response.status_code, 302)

        url = reverse('social:begin', kwargs={'backend': 'blabla'})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 404)
コード例 #2
0
    def test_authentication_backends(self):
        """
        Test that socail-auth-app-django contains authentication backends in setting.py.
        In this method, response will equal to 302 if authenticated, equal to 404 if otherwise.
        """
        response = self.client.get(
            reverse('social:begin', kwargs={'backend': 'facebook'}))
        self.assertEqual(response.status_code, 302)

        response = self.client.get(
            reverse('social:begin', kwargs={'backend': 'github'}))
        self.assertEqual(response.status_code, 404)
コード例 #3
0
ファイル: tests.py プロジェクト: Riphiphip/website
    def test_logout_view(self):
        client = Client()
        client.login(username='******', password='******')

        response = client.get(reverse('auth:logout'))

        self.assertEquals(response.status_code, 302)
コード例 #4
0
    def setUp(self):
        session = self.client.session
        session['facebook_state'] = '1'
        session.save()

        self.complete_url = reverse('social:complete',
                                    kwargs={'backend': 'facebook'})
        self.complete_url += '?code=2&state=1'
コード例 #5
0
ファイル: test_views.py プロジェクト: pop993012/111122
 def test_complete(self, mock_request):
     url = reverse('social:complete', kwargs={'backend': 'facebook'})
     url += '?code=2&state=1'
     mock_request.return_value.json.return_value = {'access_token': '123'}
     with mock.patch('django.contrib.sessions.backends.base.SessionBase'
                     '.set_expiry', side_effect=[OverflowError, None]):
         response = self.client.get(url)
         self.assertEqual(response.status_code, 302)
         self.assertEqual(response.url, base_url + '/accounts/profile/')
コード例 #6
0
ファイル: test_views.py プロジェクト: pop993012/111122
    def test_disconnect(self, mock_request):
        user_model = get_user_model()
        user = user_model.objects.create_user(username='******', password='******')
        UserSocialAuth.objects.create(user=user, provider='facebook')
        self.client.login(username='******', password='******')

        url = reverse('social:disconnect', kwargs={'backend': 'facebook'})
        response = self.client.post(url)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, 'http://testserver/accounts/profile/')

        url = reverse('social:disconnect_individual',
                      kwargs={'backend': 'facebook', 'association_id': '123'})
        hup = AbstractBaseUser.has_usable_password
        del AbstractBaseUser.has_usable_password
        response = self.client.post(url)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, 'http://testserver/accounts/profile/')
        AbstractBaseUser.has_usable_password = hup
コード例 #7
0
    def wrapper(cls, root, info, **kwargs):
        context = info.context
        context._jwt_token_auth = True

        def on_resolve(values):
            user, payload = values
            payload.token = get_token(user, context)

            if jwt_settings.JWT_LONG_RUNNING_REFRESH_TOKEN:
                payload.refresh_token = refresh_token_lazy(user)

            return payload

        token = kwargs.get('access_token')
        backend = kwargs.get('backend')

        if conf.settings.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY is None or conf.settings.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET is None:
            authorization_key = AuthorizationKey.objects.get(name="google-oauth2")
            conf.settings.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = authorization_key.key
            conf.settings.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = authorization_key.password

        if conf.settings.SOCIAL_AUTH_FACEBOOK_KEY is None or conf.settings.SOCIAL_AUTH_FACEBOOK_SECRET is None:
            authorization_key = AuthorizationKey.objects.get(name="facebook")
            conf.settings.SOCIAL_AUTH_FACEBOOK_KEY = authorization_key.key
            conf.settings.SOCIAL_AUTH_FACEBOOK_SECRET = authorization_key.password

        context.social_strategy = load_strategy(context)

        # backward compatibility in attribute name, only if not already
        # defined
        if not hasattr(context, 'strategy'):
            context.strategy = context.social_strategy
        uri = reverse('social:complete', args=(backend,))
        context.backend = load_backend(context.social_strategy, backend, uri)

        user_data = context.backend.user_data(token)

        if not user_data or not (user_data["email"] and user_data["email"].strip()):
            LOG.error('Empty email or id from social login received')
            LOG.error(user_data)
            raise JSONWebTokenError(_('Please, enter valid credentials'))

        user = context.backend.do_auth(token)

        if hasattr(context, 'user'):
            context.user = user

        result = f(cls, root, info, **kwargs)
        values = (user, result)

        token_issued.send(sender=cls, request=context, user=user)

        if is_thenable(result):
            return Promise.resolve(values).then(on_resolve)
        return on_resolve(values)
コード例 #8
0
        def wrapper(request, backend, *args, **kwargs):
            uri = redirect_uri
            if uri and not uri.startswith('/'):
                uri = reverse(redirect_uri, args=(kwargs.pop('version'), backend,))
            request.social_strategy = load_strategy(request)
            # backward compatibility in attribute name, only if not already
            # defined
            if not hasattr(request, 'strategy'):
                request.strategy = request.social_strategy

            try:
                request.backend = load_backend(request.social_strategy,
                                               backend, uri)
            except MissingBackend as exc:
                raise Http404('Backend not found') from exc
            return func(request, backend, *args, **kwargs)
コード例 #9
0
 def test_begin_view(self):
     response = self.client.get(reverse('social:begin', kwargs={'backend': 'github'}))
     self.assertEqual(response.status_code, 302)
コード例 #10
0
 def test_social_auth_changelist(self):
     """The App name in the admin index page"""
     self.client.login(username='******', password='******')
     meta = UserSocialAuth._meta
     url_name = 'admin:%s_%s_changelist' % (meta.app_label, meta.model_name)
     self.client.get(reverse(url_name))
コード例 #11
0
 def test_admin_app_name(self):
     """The App name in the admin index page"""
     self.client.login(username='******', password='******')
     response = self.client.get(reverse('admin:index'))
     self.assertContains(response, "Social_Django")