def test_raises_does_not_exist_if_user_and_association_found_but_no_match(self): assert self.get_by_username(self.user.username) is not None social_models.DjangoStorage.user.create_social_auth( self.user, 'uid', 'other_' + self.enabled_provider.backend_name) with pytest.raises(models.User.DoesNotExist): pipeline.get_authenticated_user(self.enabled_provider, self.user.username, 'uid')
def test_raises_does_not_exist_if_user_found_but_no_association(self): backend_name = 'backend' assert self.get_by_username(self.user.username) is not None assert not any(provider.Registry.get_enabled_by_backend_name(backend_name)) with pytest.raises(models.User.DoesNotExist): pipeline.get_authenticated_user(self.enabled_provider, self.user.username, '*****@*****.**')
def test_returns_user_with_is_authenticated_and_backend_set_if_match(self): social_models.DjangoStorage.user.create_social_auth( self.user, 'uid', self.enabled_provider.backend_name) user = pipeline.get_authenticated_user(self.enabled_provider, self.user.username, 'uid') assert self.user == user assert self.enabled_provider.get_authentication_backend( ) == user.backend
def _do_third_party_auth(request): """ User is already authenticated via 3rd party, now try to find and return their associated Django user. """ running_pipeline = pipeline.get(request) username = running_pipeline['kwargs'].get('username') backend_name = running_pipeline['backend'] third_party_uid = running_pipeline['kwargs']['uid'] requested_provider = provider.Registry.get_from_pipeline(running_pipeline) platform_name = configuration_helpers.get_value("platform_name", settings.PLATFORM_NAME) try: return pipeline.get_authenticated_user(requested_provider, username, third_party_uid) except User.DoesNotExist: AUDIT_LOG.info( u"Login failed - user with username {username} has no social auth " u"with backend_name {backend_name}".format( username=username, backend_name=backend_name)) message = Text( _(u"You've successfully signed in to your {provider_name} account, " u"but this account isn't linked with your {platform_name} account yet. {blank_lines}" u"Use your {platform_name} username and password to sign in to {platform_name} below, " u"and then link your {platform_name} account with {provider_name} from your dashboard. {blank_lines}" u"If you don't have an account on {platform_name} yet, " u"click {register_label_strong} at the top of the page.") ).format(blank_lines=HTML('<br/><br/>'), platform_name=platform_name, provider_name=requested_provider.name, register_label_strong=HTML( '<strong>{register_text}</strong>').format( register_text=_('Register'))) raise AuthFailedError( message, error_code='third-party-auth-with-no-linked-account')
def test_raises_does_not_exist_if_user_missing(self): with pytest.raises(models.User.DoesNotExist): pipeline.get_authenticated_user(self.enabled_provider, 'new_' + self.user.username, '*****@*****.**')