changeset 5250:3d3bec370fa5

LoginController test: verify cookie expiration ("Remember me")
author Søren Løvborg <kwi@kwi.dk>
date Tue, 14 Jul 2015 13:59:59 +0200
parents 81c70071b6f2
children a38e328db172
files kallithea/tests/functional/test_login.py
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/tests/functional/test_login.py	Tue Jun 30 22:30:57 2015 +0200
+++ b/kallithea/tests/functional/test_login.py	Tue Jul 14 13:59:59 2015 +0200
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 from __future__ import with_statement
+import re
+
 import mock
 from kallithea.tests import *
 from kallithea.tests.fixture import Fixture
@@ -57,6 +59,28 @@
         self.assertEqual(response.status, '200 OK')
         response.mustcontain('Users Administration')
 
+    def test_login_do_not_remember(self):
+        response = self.app.post(url(controller='login', action='index'),
+                                 {'username': TEST_USER_REGULAR_LOGIN,
+                                  'password': TEST_USER_REGULAR_PASS,
+                                  'remember': False})
+
+        self.assertIn('Set-Cookie', response.headers)
+        for cookie in response.headers.getall('Set-Cookie'):
+            self.assertFalse(re.search(r';\s+(Max-Age|Expires)=', cookie, re.IGNORECASE),
+                'Cookie %r has expiration date, but should be a session cookie' % cookie)
+
+    def test_login_remember(self):
+        response = self.app.post(url(controller='login', action='index'),
+                                 {'username': TEST_USER_REGULAR_LOGIN,
+                                  'password': TEST_USER_REGULAR_PASS,
+                                  'remember': True})
+
+        self.assertIn('Set-Cookie', response.headers)
+        for cookie in response.headers.getall('Set-Cookie'):
+            self.assertTrue(re.search(r';\s+(Max-Age|Expires)=', cookie, re.IGNORECASE),
+                'Cookie %r should have expiration date, but is a session cookie' % cookie)
+
     def test_logout(self):
         response = self.app.post(url(controller='login', action='index'),
                                  {'username': TEST_USER_REGULAR_LOGIN,