def test_change_password(self): """Can change password, and authenticate with new password""" new_password = '******' self.assertTrue(utils.check_password(self.user, self.password)) self.assertTrue(utils.set_password(self.user, new_password)) self.assertTrue(utils.check_password(self.user, new_password)) self.assertTrue(utils.has_usable_password(self.user))
def test_unusable_password_empty(self): """Setting empty string as unusable password disables auth""" new_password = '' self.assertTrue(utils.has_usable_password(self.user)) self.assertTrue(utils.check_password(self.user, self.password)) self.assertTrue(utils.set_password(self.user, new_password)) self.assertFalse(utils.check_password(self.user, self.password)) self.assertFalse(utils.check_password(self.user, new_password)) self.assertFalse(utils.has_usable_password(self.user))
def test_unusable_password_none(self): """Setting None as unusable password disables auth""" new_password = None self.assertTrue(utils.has_usable_password(self.user)) self.assertTrue(utils.check_password(self.user, self.password)) self.assertTrue(utils.set_password(self.user, new_password)) self.assertFalse(utils.check_password(self.user, self.password)) self.assertFalse(utils.check_password(self.user, new_password)) self.assertFalse(utils.has_usable_password(self.user))
def authenticate(self, username=None, password=None): if not getattr(settings, 'USE_LDAP', False): # Must have USE_LDAP set to True to authenticate with this backend return None if username is None or password is None: return None if not utils.check_password(username, password): return None try: return User.objects.get(username=username) except User.DoesNotExist: return self.__create_user(username)
def check_password(self, raw_password): return ldap_utils.check_password(self.get_username(), raw_password)
def test_empty_incorrect_password(self): """Check authentication fails with empty or None password""" self.assertTrue(utils.has_usable_password(self.user)) self.assertFalse(utils.check_password(self.user, '')) self.assertFalse(utils.check_password(self.user, None))