Exemple #1
0
    def test_cookies_have_correct_lifetime(self, stub_datetime):
        auth.config.set('login_token_lifetime', 42)
        stub_datetime.datetime.now.return_value = datetime.datetime.min
        stub_datetime.timedelta = datetime.timedelta
        stub_request = mock.Mock()

        auth.log_in_as_user(stub_request, 'user')

        expires = list(auth.login_tokens.values())[0]
        lifetime = expires - datetime.datetime.min

        assert lifetime == datetime.timedelta(42)
Exemple #2
0
 def set_login_cookie(self):
     if self.username is None:
         return
     cookie = auth.log_in_as_user(self, self.username)
     self.send_message("login_cookie",
                       cookie=cookie,
                       expires=config.get('login_token_lifetime'))
Exemple #3
0
    def test_returning_user_can_log_in_automatically(self):
        stub_request = mock.Mock()
        username = '******'

        cookie = auth.log_in_as_user(stub_request, username)

        assert auth.check_login_cookie(cookie) == (username, True)
Exemple #4
0
    def test_log_out_removes_token(self):
        stub_request = mock.Mock()

        cookie = auth.log_in_as_user(stub_request, 'user')
        num_tokens = len(auth.login_tokens)
        auth.forget_login_cookie(cookie)

        assert len(auth.login_tokens) == num_tokens - 1
Exemple #5
0
    def test_repeated_log_out_is_idempotent(self):
        stub_request = mock.Mock()

        cookie = auth.log_in_as_user(stub_request, 'user')
        auth.forget_login_cookie(cookie)
        login_tokens = auth.login_tokens
        auth.forget_login_cookie(cookie)  # Repeat call should do nothing

        assert login_tokens == auth.login_tokens