Skip to content

Commit

Permalink
Merge branch 'master' into fix_session_data_manager_access_permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed May 28, 2019
2 parents 222ad15 + d8213fb commit 82fbded
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Products/Transience/TransientObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import random
import sys
import time
from functools import cmp_to_key

from six.moves import _thread as thread

Expand Down Expand Up @@ -253,7 +254,7 @@ def _p_resolveConflict(self, saved, state1, state2):

# We return the state which was most recently modified, if
# possible.
states.sort(lastmodified_sort)
states.sort(key=cmp_to_key(lastmodified_sort))
if states[0].get('_last_modified'):
DEBUG and TLOG('TO _p_rc: returning last mod state')
return states[0]
Expand All @@ -263,7 +264,7 @@ def _p_resolveConflict(self, saved, state1, state2):
# the object that was most recently accessed (last pulled out of
# our parent). This will return an essentially arbitrary state if
# all last_accessed values are equal.
states.sort(lastaccessed_sort)
states.sort(key=cmp_to_key(lastaccessed_sort))
DEBUG and TLOG('TO _p_rc: returning last_accessed state')
return states[0]

Expand Down
52 changes: 52 additions & 0 deletions src/Products/Transience/tests/testTransientObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,58 @@ def test_repr_leaking_information(self):
t = self.t.new('password-storing-session')
t.set('__ac_password__', 'secret')
self.assertNotIn('secret', repr(t), '__repr__ leaks: %s' % repr(t))

def test_p_resolveConflict_doesnt_fail_on_wrong_sort_usage(self):
transient_object = self.t.new('fnord')

# objects with _last_modified
saved = {
'token': '63234647A8.Wt5y4vrs',
'id': '15589683027087205627414298864',
'_created': 1558968302.813777,
'_last_accessed': 1558968302.813777,
'_last_modified': 1558968303.205633
}
state1 = {
'token': '63234647A8.Wt5y4vrs',
'id': '15589683027087205627414298864',
'_created': 1558968302.813777,
'_last_accessed': 1558968302.813777,
'_last_modified': 1558968304.196779
}
state2 = {
'token': '63234647A8.Wt5y4vrs',
'id': '15589683027087205627414298864',
'_created': 1558968302.813777,
'_last_accessed': 1558968302.813777,
'_last_modified': 1558968304.079772
}

# should not raise
transient_object._p_resolveConflict(saved, state1, state2)

# objects with only _last_accessed
saved = {
'token': '63234647A8.Wt5y4vrs',
'id': '15589683027087205627414298864',
'_created': 1558968302.813777,
'_last_accessed': 1558968302.813777
}
state1 = {
'token': '63234647A8.Wt5y4vrs',
'id': '15589683027087205627414298864',
'_created': 1558968302.813777,
'_last_accessed': 1558968302.813777
}
state2 = {
'token': '63234647A8.Wt5y4vrs',
'id': '15589683027087205627414298864',
'_created': 1558968302.813777,
'_last_accessed': 1558968302.813777
}

# should not raise
transient_object._p_resolveConflict(saved, state1, state2)


def test_suite():
Expand Down

0 comments on commit 82fbded

Please sign in to comment.