Esempio n. 1
0
 def test_redirect_for_saml_based_on_email_only(self, email,
                                                expected_redirect_url,
                                                is_saml):
     """
     Test that only email(and not username) is used by saml based auth flows
     to determine if a user already exists
     """
     saml_provider = mock.MagicMock(slug='unique_slug',
                                    send_to_registration_first=True,
                                    skip_email_verification=False)
     with mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') as get_from_pipeline:  # lint-amnesty, pylint: disable=line-too-long
         get_from_pipeline.return_value = saml_provider
         with mock.patch(
                 'common.djangoapps.third_party_auth.pipeline.provider.Registry.get_enabled_by_backend_name'
         ) as enabled_saml_providers:
             enabled_saml_providers.return_value = [
                 saml_provider,
             ] if is_saml else []
             with mock.patch('social_core.pipeline.partial.partial_prepare'
                             ) as partial_prepare:
                 partial_prepare.return_value = mock.MagicMock(token='')
                 strategy = mock.MagicMock()
                 response = pipeline.ensure_user_information(
                     strategy=strategy,
                     backend=None,
                     auth_entry=pipeline.AUTH_ENTRY_LOGIN,
                     pipeline_index=0,
                     details={
                         'username': self.user.username,
                         'email': email
                     })
                 assert response.status_code == 302
                 assert response.url == expected_redirect_url
Esempio n. 2
0
    def test_provider_settings_redirect_to_registration(
            self, send_to_registration_first, expected_redirect_url):
        """
        Test if user is not authenticated, that they get redirected to the appropriate page
        based on the provider's setting for send_to_registration_first.
        """

        provider = mock.MagicMock(
            send_to_registration_first=send_to_registration_first,
            skip_email_verification=False)

        with mock.patch(
                'common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline'
        ) as get_from_pipeline:
            get_from_pipeline.return_value = provider
            with mock.patch('social_core.pipeline.partial.partial_prepare'
                            ) as partial_prepare:
                partial_prepare.return_value = mock.MagicMock(token='')
                strategy = mock.MagicMock()
                response = pipeline.ensure_user_information(
                    strategy=strategy,
                    backend=None,
                    auth_entry=pipeline.AUTH_ENTRY_LOGIN,
                    pipeline_index=0)
                assert response.status_code == 302
                assert response.url == expected_redirect_url