[auth] Use a second authtkt policy for 'rememberme'
The former solution was buggy because the expire time of the auth cookie, if
set through 'remember', was lost on the first cookie reissuing.
The new approach, make possible thanks to multiauth, use two different cookies.
One for session bounded authentication (no 'rememberme'), and one for long
lasting authentication (w 'rememberme').
The choice between the two of them is done by adding a 'persistent' argument
to the top-level 'security.remember' call. Passing this argument will inhibate
a policy or the other.
The two policies are (a little) configurable through the
'cubicweb.auth.authtkt.[session|persistent].*' variables.
Related to #4985962
from pyramid_cubicweb.tests import PyramidCWTest
class LoginTest(PyramidCWTest):
def test_login_form(self):
res = self.webapp.get('/login')
self.assertIn('__login', res.text)
def test_login_password_login(self):
res = self.webapp.post('/login', {
'__login': self.admlogin, '__password': self.admpassword})
self.assertEqual(res.status_int, 303)
res = self.webapp.get('/login')
self.assertEqual(res.status_int, 303)
def test_login_password_login_cookie_expires(self):
res = self.webapp.post('/login', {
'__login': self.admlogin, '__password': self.admpassword})
self.assertEqual(res.status_int, 303)
cookies = self.webapp.cookiejar._cookies['localhost.local']['/']
self.assertNotIn('pauth_tkt', cookies)
self.assertIn('auth_tkt', cookies)
self.assertIsNone(cookies['auth_tkt'].expires)
res = self.webapp.get('/logout')
self.assertEqual(res.status_int, 303)
self.assertNotIn('auth_tkt', cookies)
self.assertNotIn('pauth_tkt', cookies)
res = self.webapp.post('/login', {
'__login': self.admlogin, '__password': self.admpassword,
'__setauthcookie': 1})
self.assertEqual(res.status_int, 303)
cookies = self.webapp.cookiejar._cookies['localhost.local']['/']
self.assertNotIn('auth_tkt', cookies)
self.assertIn('pauth_tkt', cookies)
self.assertIsNotNone(cookies['pauth_tkt'].expires)