@@ -50,20 +50,32 @@ class TestValidateLogin(DatabaseMixin, unittest.TestCase):
5050 def setUp (self ):
5151 super (TestValidateLogin , self ).setUp ()
5252 self .timestamp = make_datetime ()
53+ self .add_contest ()
5354 self .contest = self .add_contest (allow_password_authentication = True )
55+ self .add_user (username = "otheruser" )
5456 self .user = self .add_user (
5557 username = "myuser" , password = build_password ("mypass" ))
5658 self .participation = self .add_participation (
5759 contest = self .contest , user = self .user )
5860
5961 def assertSuccess (self , username , password , ip_address ):
62+ # We had an issue where due to a misuse of contains_eager we ended up
63+ # with the wrong user attached to the participation. This only happens
64+ # if the correct user isn't already in the identity map, which is what
65+ # these lines trigger.
66+ self .session .flush ()
67+ self .session .expire (self .user )
68+ self .session .expire (self .contest )
69+
6070 authenticated_participation , cookie = validate_login (
6171 self .session , self .contest , self .timestamp ,
6272 username , password , ipaddress .ip_address (ip_address ))
6373
6474 self .assertIsNotNone (authenticated_participation )
6575 self .assertIsNotNone (cookie )
6676 self .assertIs (authenticated_participation , self .participation )
77+ self .assertIs (authenticated_participation .user , self .user )
78+ self .assertIs (authenticated_participation .contest , self .contest )
6779
6880 def assertFailure (self , username , password , ip_address ):
6981 authenticated_participation , cookie = validate_login (
@@ -152,7 +164,9 @@ class TestAuthenticateRequest(DatabaseMixin, unittest.TestCase):
152164 def setUp (self ):
153165 super (TestAuthenticateRequest , self ).setUp ()
154166 self .timestamp = make_datetime ()
167+ self .add_contest ()
155168 self .contest = self .add_contest ()
169+ self .add_user (username = "otheruser" )
156170 self .user = self .add_user (
157171 username = "myuser" , password = build_password ("mypass" ))
158172 self .participation = self .add_participation (
@@ -176,10 +190,23 @@ def assertSuccess(self, **kwargs):
176190 # autologin or thanks to the cookie) and return the cookie that should
177191 # be set (or None, if it should be cleared/left unset).
178192 # The arguments are the same as those of attempt_authentication.
193+
194+ # We had an issue where due to a misuse of contains_eager we ended up
195+ # with the wrong user attached to the participation. This only happens
196+ # if the correct user isn't already in the identity map, which is what
197+ # these lines trigger.
198+ self .session .flush ()
199+ self .session .expire (self .user )
200+ self .session .expire (self .contest )
201+
179202 authenticated_participation , cookie = \
180203 self .attempt_authentication (** kwargs )
204+
181205 self .assertIsNotNone (authenticated_participation )
182206 self .assertIs (authenticated_participation , self .participation )
207+ self .assertIs (authenticated_participation .user , self .user )
208+ self .assertIs (authenticated_participation .contest , self .contest )
209+
183210 return cookie
184211
185212 def assertSuccessAndCookieRefreshed (self , ** kwargs ):
0 commit comments