Python django.http.SimpleCookie() Examples

The following are 23 code examples of django.http.SimpleCookie(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.http , or try the search function .
Example #1
Source File: client.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
def logout(self):
        """
        Removes the authenticated user's cookies and session object.

        Causes the authenticated user to be logged out.
        """
        from django.contrib.auth import get_user, logout

        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        if self.session:
            request.session = self.session
            request.user = get_user(request)
        else:
            request.session = engine.SessionStore()
        logout(request)
        self.cookies = SimpleCookie() 
Example #2
Source File: client.py    From python2017 with MIT License 6 votes vote down vote up
def logout(self):
        """
        Removes the authenticated user's cookies and session object.

        Causes the authenticated user to be logged out.
        """
        from django.contrib.auth import get_user, logout

        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        if self.session:
            request.session = self.session
            request.user = get_user(request)
        else:
            request.session = engine.SessionStore()
        logout(request)
        self.cookies = SimpleCookie() 
Example #3
Source File: client.py    From python with Apache License 2.0 6 votes vote down vote up
def logout(self):
        """
        Removes the authenticated user's cookies and session object.

        Causes the authenticated user to be logged out.
        """
        from django.contrib.auth import get_user, logout

        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        if self.session:
            request.session = self.session
            request.user = get_user(request)
        else:
            request.session = engine.SessionStore()
        logout(request)
        self.cookies = SimpleCookie() 
Example #4
Source File: client.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, **defaults):
        self.defaults = defaults
        self.cookies = SimpleCookie()
        self.errors = BytesIO() 
Example #5
Source File: test_users_pay.py    From DjanGoat with MIT License 5 votes vote down vote up
def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:decrypt_bank_acct_num'
        self.route = '/users/55/pay/decrypt_bank_acct_num'
        self.view = pay.decrypt_bank_acct_num
        self.responses = {
            'exists': 200,
            'GET': 405,
            'POST': 200,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {'user_id': 55}
        self.expected_response_content = 'Decrypt the bank info 55'
        AuthRouteTestingWithKwargs.__init__(self)

        input_iv = binascii.hexlify(Random.new().read(8))
        km_input_create_date = timezone.now()
        km_input_update_date = timezone.now()

        self.key_model = KeyManagement.objects.create(
            iv=input_iv, user=self.mixin_model,
            created_at=km_input_create_date,
            updated_at=km_input_update_date
        )

        self.client.cookies = SimpleCookie({'auth_token': self.mixin_model.auth_token})

    # Override 
Example #6
Source File: test_users_pay.py    From DjanGoat with MIT License 5 votes vote down vote up
def setUp(self):
        self.factory = RequestFactory()
        self.client = Client()
        self.route_name = 'app:update_dd_info'
        self.route = '/users/55/pay/update_dd_info'
        self.view = pay.update_dd_info
        self.responses = {
            'exists': 200,
            'GET': 405,
            'POST': 200,
            'PUT': 405,
            'PATCH': 405,
            'DELETE': 405,
            'HEAD': 405,
            'OPTIONS': 405,
            'TRACE': 405
        }
        self.kwargs = {'user_id': 55}
        self.expected_response_content = 'Update dd info for user 55'
        AuthRouteTestingWithKwargs.__init__(self)

        input_iv = binascii.hexlify(Random.new().read(8))
        km_input_create_date = timezone.now()
        km_input_update_date = timezone.now()

        self.key_model = KeyManagement.objects.create(
            iv=input_iv, user=self.mixin_model,
            created_at=km_input_create_date,
            updated_at=km_input_update_date
        )

        self.client.cookies = SimpleCookie({'auth_token': self.mixin_model.auth_token})

    # Override 
Example #7
Source File: utils.py    From DjanGoat with MIT License 5 votes vote down vote up
def simulate_simple_authentication(factory, client, email, password, path, add_messages_middleware, views):
    auth_request = factory.post('/sessions/')
    add_messages_middleware(auth_request)
    auth_response = views.sessions_index(auth_request,
                                                  email=email,
                                                  password=password,
                                                  path=path)
    # Add auth token cookie to request
    auth_token = auth_response.cookies['auth_token'].value

    client.cookies = SimpleCookie({'auth_token': auth_token}) 
Example #8
Source File: cookie.py    From python2017 with MIT License 5 votes vote down vote up
def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
        """
        Stores the messages to a cookie, returning a list of any messages which
        could not be stored.

        If the encoded data is larger than ``max_cookie_size``, removes
        messages until the data fits (these are the messages which are
        returned), and add the not_finished sentinel value to indicate as much.
        """
        unstored_messages = []
        encoded_data = self._encode(messages)
        if self.max_cookie_size:
            # data is going to be stored eventually by SimpleCookie, which
            # adds its own overhead, which we must account for.
            cookie = SimpleCookie()  # create outside the loop

            def stored_length(val):
                return len(cookie.value_encode(val)[1])

            while encoded_data and stored_length(encoded_data) > self.max_cookie_size:
                if remove_oldest:
                    unstored_messages.append(messages.pop(0))
                else:
                    unstored_messages.insert(0, messages.pop())
                encoded_data = self._encode(messages + [self.not_finished],
                                            encode_empty=unstored_messages)
        self._update_cookie(encoded_data, response)
        return unstored_messages 
Example #9
Source File: client.py    From python2017 with MIT License 5 votes vote down vote up
def __init__(self, **defaults):
        self.defaults = defaults
        self.cookies = SimpleCookie()
        self.errors = BytesIO() 
Example #10
Source File: cookie.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
        """
        Stores the messages to a cookie, returning a list of any messages which
        could not be stored.

        If the encoded data is larger than ``max_cookie_size``, removes
        messages until the data fits (these are the messages which are
        returned), and add the not_finished sentinel value to indicate as much.
        """
        unstored_messages = []
        encoded_data = self._encode(messages)
        if self.max_cookie_size:
            # data is going to be stored eventually by SimpleCookie, which
            # adds its own overhead, which we must account for.
            cookie = SimpleCookie()  # create outside the loop

            def stored_length(val):
                return len(cookie.value_encode(val)[1])

            while encoded_data and stored_length(encoded_data) > self.max_cookie_size:
                if remove_oldest:
                    unstored_messages.append(messages.pop(0))
                else:
                    unstored_messages.insert(0, messages.pop())
                encoded_data = self._encode(messages + [self.not_finished],
                                            encode_empty=unstored_messages)
        self._update_cookie(encoded_data, response)
        return unstored_messages 
Example #11
Source File: client.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def logout(self):
        """
        Removes the authenticated user's cookies and session object.

        Causes the authenticated user to be logged out.
        """
        from django.contrib.auth import get_user, logout

        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        if self.session:
            request.session = self.session
            request.user = get_user(request)
        else:
            request.session = engine.SessionStore()
        logout(request)
        self.cookies = SimpleCookie() 
Example #12
Source File: client.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def __init__(self, **defaults):
        self.defaults = defaults
        self.cookies = SimpleCookie()
        self.errors = BytesIO() 
Example #13
Source File: client.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def logout(self):
        """
        Removes the authenticated user's cookies and session object.

        Causes the authenticated user to be logged out.
        """
        session = import_module(settings.SESSION_ENGINE).SessionStore()
        session_cookie = self.cookies.get(settings.SESSION_COOKIE_NAME)
        if session_cookie:
            session.delete(session_key=session_cookie.value)
        self.cookies = SimpleCookie() 
Example #14
Source File: client.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, **defaults):
        self.defaults = defaults
        self.cookies = SimpleCookie()
        self.errors = BytesIO() 
Example #15
Source File: client.py    From python with Apache License 2.0 5 votes vote down vote up
def __init__(self, **defaults):
        self.defaults = defaults
        self.cookies = SimpleCookie()
        self.errors = BytesIO() 
Example #16
Source File: cookie.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
        """
        Store the messages to a cookie and return a list of any messages which
        could not be stored.

        If the encoded data is larger than ``max_cookie_size``, remove
        messages until the data fits (these are the messages which are
        returned), and add the not_finished sentinel value to indicate as much.
        """
        unstored_messages = []
        encoded_data = self._encode(messages)
        if self.max_cookie_size:
            # data is going to be stored eventually by SimpleCookie, which
            # adds its own overhead, which we must account for.
            cookie = SimpleCookie()  # create outside the loop

            def stored_length(val):
                return len(cookie.value_encode(val)[1])

            while encoded_data and stored_length(encoded_data) > self.max_cookie_size:
                if remove_oldest:
                    unstored_messages.append(messages.pop(0))
                else:
                    unstored_messages.insert(0, messages.pop())
                encoded_data = self._encode(messages + [self.not_finished],
                                            encode_empty=unstored_messages)
        self._update_cookie(encoded_data, response)
        return unstored_messages 
Example #17
Source File: client.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def logout(self):
        """Log out the user by removing the cookies and session object."""
        from django.contrib.auth import get_user, logout

        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        if self.session:
            request.session = self.session
            request.user = get_user(request)
        else:
            request.session = engine.SessionStore()
        logout(request)
        self.cookies = SimpleCookie() 
Example #18
Source File: client.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def __init__(self, *, json_encoder=DjangoJSONEncoder, **defaults):
        self.json_encoder = json_encoder
        self.defaults = defaults
        self.cookies = SimpleCookie()
        self.errors = BytesIO() 
Example #19
Source File: cookie.py    From bioforum with MIT License 5 votes vote down vote up
def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
        """
        Store the messages to a cookie and return a list of any messages which
        could not be stored.

        If the encoded data is larger than ``max_cookie_size``, remove
        messages until the data fits (these are the messages which are
        returned), and add the not_finished sentinel value to indicate as much.
        """
        unstored_messages = []
        encoded_data = self._encode(messages)
        if self.max_cookie_size:
            # data is going to be stored eventually by SimpleCookie, which
            # adds its own overhead, which we must account for.
            cookie = SimpleCookie()  # create outside the loop

            def stored_length(val):
                return len(cookie.value_encode(val)[1])

            while encoded_data and stored_length(encoded_data) > self.max_cookie_size:
                if remove_oldest:
                    unstored_messages.append(messages.pop(0))
                else:
                    unstored_messages.insert(0, messages.pop())
                encoded_data = self._encode(messages + [self.not_finished],
                                            encode_empty=unstored_messages)
        self._update_cookie(encoded_data, response)
        return unstored_messages 
Example #20
Source File: client.py    From bioforum with MIT License 5 votes vote down vote up
def logout(self):
        """Log out the user by removing the cookies and session object."""
        from django.contrib.auth import get_user, logout

        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        if self.session:
            request.session = self.session
            request.user = get_user(request)
        else:
            request.session = engine.SessionStore()
        logout(request)
        self.cookies = SimpleCookie() 
Example #21
Source File: client.py    From bioforum with MIT License 5 votes vote down vote up
def __init__(self, **defaults):
        self.defaults = defaults
        self.cookies = SimpleCookie()
        self.errors = BytesIO() 
Example #22
Source File: cookie.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
        """
        Stores the messages to a cookie, returning a list of any messages which
        could not be stored.

        If the encoded data is larger than ``max_cookie_size``, removes
        messages until the data fits (these are the messages which are
        returned), and add the not_finished sentinel value to indicate as much.
        """
        unstored_messages = []
        encoded_data = self._encode(messages)
        if self.max_cookie_size:
            # data is going to be stored eventually by SimpleCookie, which
            # adds its own overhead, which we must account for.
            cookie = SimpleCookie()  # create outside the loop

            def stored_length(val):
                return len(cookie.value_encode(val)[1])

            while encoded_data and stored_length(encoded_data) > self.max_cookie_size:
                if remove_oldest:
                    unstored_messages.append(messages.pop(0))
                else:
                    unstored_messages.insert(0, messages.pop())
                encoded_data = self._encode(messages + [self.not_finished],
                                            encode_empty=unstored_messages)
        self._update_cookie(encoded_data, response)
        return unstored_messages 
Example #23
Source File: test_a6_sensitive_data_exposure.py    From DjanGoat with MIT License 4 votes vote down vote up
def setUp(self):
        # Create User Model
        input_email = "ryan.dens@example.com"
        input_password = "12345"
        input_admin = False
        input_first_name = "Ryan"
        input_last_name = "Dens"
        u_input_create_date = pytz.utc.localize(datetime.datetime(2017, 6, 1, 0, 0))
        u_input_update_date = pytz.utc.localize(datetime.datetime(2017, 6, 3, 0, 0))

        self.user = User.objects.create(
            email=input_email, password=input_password,
            is_admin=input_admin, first_name=input_first_name,
            last_name=input_last_name, created_at=u_input_create_date,
            updated_at=u_input_update_date
        )
        self.route = "/users/" + str(self.user.id) + "/work_info"

        # Create WorkInfo Model
        input_income = "fun"
        input_bonuses = "birthday"
        input_years_worked = 10
        input_ssn = "111-22-3333"
        input_encrypted_ssn = "random_chars".encode("utf-8")
        input_dob = datetime.date(1996, 7, 31)
        perf_input_create_date = pytz.utc.localize(datetime.datetime(2017, 6, 4, 0, 0))
        perf_input_update_date = pytz.utc.localize(datetime.datetime(2017, 6, 5, 0, 0))

        self.model = WorkInfo.objects.create(
            income=input_income,
            bonuses=input_bonuses,
            years_worked=input_years_worked,
            SSN=input_ssn,
            encrypted_ssn=input_encrypted_ssn,
            DoB=input_dob,
            created_at=perf_input_create_date,
            updated_at=perf_input_update_date,
            user=self.user,
        )

        input_iv = binascii.hexlify(Random.new().read(8))
        km_input_create_date = pytz.utc.localize(datetime.datetime(2017, 6, 4, 0, 0))
        km_input_update_date = pytz.utc.localize(datetime.datetime(2017, 6, 5, 0, 0))

        self.key_model = KeyManagement.objects.create(
            iv=input_iv, user=self.user,
            created_at=km_input_create_date,
            updated_at=km_input_update_date
        )

        self.client = Client()
        self.client.cookies = SimpleCookie({'auth_token': self.user.auth_token})