sessions: remove session_id substitution variable (#39786)

This commit is contained in:
Frédéric Péters 2020-05-27 10:06:19 +02:00
parent 69e6f69975
commit ecfed38818
3 changed files with 3 additions and 27 deletions

View File

@ -177,27 +177,6 @@ def test_session_do_not_reuse_id(pub, user, app):
assert pub.session_manager.session_class.count() == 2
def test_session_substitution_variables(pub, user, app):
pub.session_manager.session_class.wipe()
resp = app.get('/')
formdef = FormDef()
formdef.name = 'foobar'
formdef.fields = [fields.CommentField(id='7', label='Hello [session_id]', type='comment')]
formdef.store()
resp = app.get('/foobar/')
assert pub.session_manager.session_class.count() == 1
session_id = pub.session_manager.session_class.select()[0].id
assert 'Hello %s' % session_id in resp.text
login(app, username='foo', password='foo')
assert pub.session_manager.session_class.count() == 2
session_id = [x for x in pub.session_manager.session_class.select() if x.id != session_id][0].id
resp = app.get('/foobar/')
assert 'Hello %s' % session_id in resp.text
def test_session_substitution_variables_1st_page_condition(pub, user, app):
pub.session_manager.session_class.wipe()
resp = app.get('/')
@ -205,17 +184,15 @@ def test_session_substitution_variables_1st_page_condition(pub, user, app):
formdef = FormDef()
formdef.name = 'foobar'
formdef.fields = [fields.PageField(id='0', label='1st PAGE', type='page',
condition={'type': 'python', 'value': 'vars().get("session_id") is not None'}),
fields.CommentField(id='7', label='COM1 [session_id]', type='comment'),
condition={'type': 'python', 'value': 'vars().get("session_hash_id") is not None'}),
fields.CommentField(id='10', label='COMHASH1 [session_hash_id]', type='comment'),
fields.PageField(id='8', label='2nd PAGE', type='page'),
fields.CommentField(id='9', label='COM2 [session_id]', type='comment')]
fields.CommentField(id='9', label='COM2 [session_hash_id]', type='comment')]
formdef.store()
resp = app.get('/foobar/')
assert pub.session_manager.session_class.count() == 1
session = pub.session_manager.session_class.select()[0]
assert 'COM1 %s' % session.id in resp.text
assert 'COMHASH1 %s' % session.get_substitution_variables().get('session_hash_id') in resp.text

View File

@ -635,7 +635,7 @@ class FormPage(Directory, FormTemplateMixin):
session = get_session()
if not session.id:
# force session to be written down, this is required so
# [session_var_id] is available on the first page.
# [session_hash_id] is available on the first page.
session.force()
if self.has_draft_support():

View File

@ -335,7 +335,6 @@ class Session(QommonSession, CaptchaSession, StorableObject):
def get_substitution_variables(self, prefix='session_'):
d = {}
d[prefix + 'id'] = self.id
d[prefix + 'hash_id'] = hashlib.sha1(force_bytes(self.id)).hexdigest()
if self.extra_variables:
for k, v in self.extra_variables.items():