Projet

Général

Profil

0001-sessions-remove-session_id-substitution-variable-397.patch

Frédéric Péters, 27 mai 2020 16:53

Télécharger (3,83 ko)

Voir les différences:

Subject: [PATCH] sessions: remove session_id substitution variable (#39786)

 tests/test_sessions.py | 27 ++-------------------------
 wcs/forms/root.py      |  2 +-
 wcs/qommon/sessions.py |  1 -
 3 files changed, 3 insertions(+), 27 deletions(-)
tests/test_sessions.py
177 177
    assert pub.session_manager.session_class.count() == 2
178 178

  
179 179

  
180
def test_session_substitution_variables(pub, user, app):
181
    pub.session_manager.session_class.wipe()
182
    resp = app.get('/')
183

  
184
    formdef = FormDef()
185
    formdef.name = 'foobar'
186
    formdef.fields = [fields.CommentField(id='7', label='Hello [session_id]', type='comment')]
187
    formdef.store()
188

  
189
    resp = app.get('/foobar/')
190
    assert pub.session_manager.session_class.count() == 1
191
    session_id = pub.session_manager.session_class.select()[0].id
192
    assert 'Hello %s' % session_id in resp.text
193

  
194
    login(app, username='foo', password='foo')
195
    assert pub.session_manager.session_class.count() == 2
196
    session_id = [x for x in pub.session_manager.session_class.select() if x.id != session_id][0].id
197
    resp = app.get('/foobar/')
198
    assert 'Hello %s' % session_id in resp.text
199

  
200

  
201 180
def test_session_substitution_variables_1st_page_condition(pub, user, app):
202 181
    pub.session_manager.session_class.wipe()
203 182
    resp = app.get('/')
......
205 184
    formdef = FormDef()
206 185
    formdef.name = 'foobar'
207 186
    formdef.fields = [fields.PageField(id='0', label='1st PAGE', type='page',
208
            condition={'type': 'python', 'value': 'vars().get("session_id") is not None'}),
209
            fields.CommentField(id='7', label='COM1 [session_id]', type='comment'),
187
            condition={'type': 'python', 'value': 'vars().get("session_hash_id") is not None'}),
210 188
            fields.CommentField(id='10', label='COMHASH1 [session_hash_id]', type='comment'),
211 189
            fields.PageField(id='8', label='2nd PAGE', type='page'),
212
            fields.CommentField(id='9', label='COM2 [session_id]', type='comment')]
190
            fields.CommentField(id='9', label='COM2 [session_hash_id]', type='comment')]
213 191
    formdef.store()
214 192

  
215 193
    resp = app.get('/foobar/')
216 194
    assert pub.session_manager.session_class.count() == 1
217 195
    session = pub.session_manager.session_class.select()[0]
218
    assert 'COM1 %s' % session.id in resp.text
219 196
    assert 'COMHASH1 %s' % session.get_substitution_variables().get('session_hash_id') in resp.text
220 197

  
221 198

  
wcs/forms/root.py
635 635
        session = get_session()
636 636
        if not session.id:
637 637
            # force session to be written down, this is required so
638
            # [session_var_id] is available on the first page.
638
            # [session_hash_id] is available on the first page.
639 639
            session.force()
640 640

  
641 641
        if self.has_draft_support():
wcs/qommon/sessions.py
335 335

  
336 336
    def get_substitution_variables(self, prefix='session_'):
337 337
        d = {}
338
        d[prefix + 'id'] = self.id
339 338
        d[prefix + 'hash_id'] = hashlib.sha1(force_bytes(self.id)).hexdigest()
340 339
        if self.extra_variables:
341 340
            for k, v in self.extra_variables.items():
342
-