author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 29 Sep 2010 16:16:32 +0200 | |
changeset 6366 | 1806148d6ce8 |
parent 6032 | 52f9a43d8e08 |
parent 6340 | 470d8e828fda |
child 6367 | d4c485ec1ca1 |
permissions | -rw-r--r-- |
5251
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
# -*- coding: iso-8859-1 -*- |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
"""unit tests for cubicweb.web.application |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
|
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
:organization: Logilab |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
""" |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
from cubicweb.devtools.testlib import CubicWebTC |
6032
52f9a43d8e08
[session] session auto reconnect feature has gone with the session-time refactoring in 6012:d56fd78006cd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5785
diff
changeset
|
10 |
from cubicweb.web import InvalidSession |
5251
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
|
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
class SessionTC(CubicWebTC): |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
|
6032
52f9a43d8e08
[session] session auto reconnect feature has gone with the session-time refactoring in 6012:d56fd78006cd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5785
diff
changeset
|
14 |
def test_session_expiration(self): |
5251
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
sm = self.app.session_handler.session_manager |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
16 |
# make is if the web session has been opened by the session manager |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
sm._sessions[self.cnx.sessionid] = self.websession |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
18 |
sessionid = self.websession.sessionid |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5785
diff
changeset
|
19 |
self.assertEqual(len(sm._sessions), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5785
diff
changeset
|
20 |
self.assertEqual(self.websession.sessionid, self.websession.cnx.sessionid) |
5251
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
21 |
# fake the repo session is expiring |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
22 |
self.repo.close(sessionid) |
5785
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
23 |
try: |
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
24 |
# fake an incoming http query with sessionid in session cookie |
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
25 |
# don't use self.request() which try to call req.set_session |
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
26 |
req = self.requestcls(self.vreg) |
6366 | 27 |
<<<<<<< /home/syt/src/fcubicweb/cubicweb/web/test/unittest_session.py |
6032
52f9a43d8e08
[session] session auto reconnect feature has gone with the session-time refactoring in 6012:d56fd78006cd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5785
diff
changeset
|
28 |
self.assertRaises(InvalidSession, sm.get_session, req, sessionid) |
52f9a43d8e08
[session] session auto reconnect feature has gone with the session-time refactoring in 6012:d56fd78006cd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5785
diff
changeset
|
29 |
self.assertEquals(len(sm._sessions), 0) |
6366 | 30 |
======= |
5785
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
31 |
websession = sm.get_session(req, sessionid) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5785
diff
changeset
|
32 |
self.assertEqual(len(sm._sessions), 1) |
5785
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
33 |
self.assertIs(websession, self.websession) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5785
diff
changeset
|
34 |
self.assertEqual(websession.sessionid, sessionid) |
5785
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
35 |
self.assertNotEquals(websession.sessionid, websession.cnx.sessionid) |
6366 | 36 |
>>>>>>> /tmp/unittest_session.py~other.sGNH8u |
5785
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
37 |
finally: |
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
38 |
# avoid error in tearDown by telling this connection is closed... |
c0661b963ced
[test] fix test w/ closed connection pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5251
diff
changeset
|
39 |
self.cnx._closed = True |
5251
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
40 |
|
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
41 |
if __name__ == '__main__': |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
42 |
from logilab.common.testlib import unittest_main |
b675edd05c19
[web session] fix web session id bug on automatic reconnection. The web session id should keep the first connection id, then differ of the repo connection id once some reconnection has been done (since the session cookie isn't updated in such cases). Also, use a lock to avoid potential race condition on reconnection.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
43 |
unittest_main() |