Beispiel #1
0
    def get_request_and_strategy(self, auth_entry=None, redirect_uri=None):
        """Gets a fully-configured request and strategy.

        These two objects contain circular references, so we create them
        together. The references themselves are a mixture of normal __init__
        stuff and monkey-patching done by python-social-auth. See, for example,
        social.apps.django_apps.utils.strategy().
        """
        request = self.request_factory.get(
            pipeline.get_complete_url(self.backend_name) +
            '?redirect_state=redirect_state_value&code=code_value&state=state_value'
        )
        request.user = auth_models.AnonymousUser()
        request.session = cache.SessionStore()
        request.session[self.backend_name + '_state'] = 'state_value'

        if auth_entry:
            request.session[pipeline.AUTH_ENTRY_KEY] = auth_entry

        strategy = social_utils.load_strategy(request=request)
        request.social_strategy = strategy
        request.backend = social_utils.load_backend(strategy,
                                                    self.backend_name,
                                                    redirect_uri)

        return request, strategy
 def setUp(self):
     ecidp = EnterpriseCustomerIdentityProviderFactory(provider_id='provider_slug')
     self.customer = ecidp.enterprise_customer
     self.user = UserFactory(is_active=True)
     self.request_factory = RequestFactory()
     self.request = self.request_factory.get('/')
     self.request.session = cache.SessionStore()
     super().setUp()
    def _fake_strategy(self):
        """Simulate the strategy passed to the pipeline step. """
        request = RequestFactory().get(
            pipeline.get_complete_url(self.BACKEND_NAME))
        request.user = self.user
        request.session = cache.SessionStore()

        return social_utils.load_strategy(backend=self.BACKEND_NAME,
                                          request=request)
Beispiel #4
0
    def _get_mock_request():
        """
        Get mock django HttpRequest object.
        """
        request = RequestFactory().get('/')
        request.session = cache.SessionStore()
        # Monkey-patch storage for messaging;   pylint: disable=protected-access
        request._messages = fallback.FallbackStorage(request)

        return request
Beispiel #5
0
    def get_mocked_sso_backend(self):
        """
        Get a mocked request backend with mocked strategy.
        """
        request_factory = RequestFactory()
        request = request_factory.get('/')
        request.session = cache.SessionStore()
        # Monkey-patch storage for messaging;   pylint: disable=protected-access
        request._messages = fallback.FallbackStorage(request)

        strategy_mock = mock.MagicMock(request=request)
        backend = mock.MagicMock(
            name=None,
            strategy=strategy_mock,
        )
        return backend
Beispiel #6
0
def whois(request):

    mimetype = 'application/json'

    # Get channel_layer function
    from channels.asgi import get_channel_layer
    from channels.sessions import session_for_reply_channel
            
    # passing group_channel takes channel name
    #channel_layer = get_channel_layer()
    #data = channel_layer.group_channels('notifications')
    #data = channel_layer.global_statistics()
    #data = channel_layer.channel_statistics('notifications')
    #data = get_channel_layer().group_channels('notifications')    
    #data = Group("notifications").extensions
    #data = get_channel_layer().receive_twisted()
    
    #from channels import channel_layers
    #layer = channel_layers["default"]
    #print(layer.router.channels)    
    
    data = []
    
    
    from django.contrib.sessions.backends import cache as engine
    data = get_channel_layer().group_channels('notifications')
    
    active_users = []
    for C in data:        
        #Channel(C).send({"text": json.dumps({'clean_signal':True})})
        c_session = session_for_reply_channel(C)        
        session = engine.SessionStore(c_session._session_key)        
        
        #print(c_session._session['_auth_user_id'])
        #print(session.keys())
        #print(session.get('username', None), session.get_expiry_date())
        
        username = session.get('username', None)
        # this is the same
        # username = c_session.get('username', None)
        if username not in active_users and username != None:
            active_users.append(username)
    data = active_users
            
    
    return HttpResponse(json.dumps(data), mimetype)