def test_password_change_clears_sessions(self): SessionFactory(user=self.user) SessionFactory(user=self.user) SessionFactory(user=self.user) assert Session.find().count() == 3 self.user.set_password('killerqueen') assert Session.find().count() == 0
def test_remove_session_for_user(self): SessionFactory(user=self.user) # sanity check assert Session.find().count() == 1 utils.remove_sessions_for_user(self.user) assert Session.find().count() == 0 SessionFactory() SessionFactory(user=self.user) # sanity check assert Session.find().count() == 2 utils.remove_sessions_for_user(self.user) assert Session.find().count() == 1
def setUp(self): super(TestUserLastLoginDate, self).setUp() self.user = AuthUserFactory() self.session = SessionFactory( data={ 'auth_user_id': self.user._id, 'auth_user_username': self.user.username } ) self.cookie = itsdangerous.Signer(settings.SECRET_KEY).sign(self.session._id).decode()
def test_expired_cookie(self): self.session = SessionFactory(user=self.user1) with connection.cursor() as cursor: cursor.execute(""" UPDATE osf_session SET date_created = %s WHERE id = %s """, [(timezone.now() - timedelta(seconds=settings.OSF_SESSION_TIMEOUT)), self.session.id]) cookie = self.user1.get_or_create_cookie() self.app.set_cookie(settings.COOKIE_NAME, str(cookie)) res = self.app.get(self.reachable_url) assert_equal(res.status_code, 302) assert_in('login', res.location)
def test_remove_session(self): session = SessionFactory(user=self.user) assert Session.find().count() == 1 utils.remove_session(session) assert Session.find().count() == 0