async def _queryRangersByID(self) -> Mapping[str, Ranger]: self._log.info("Retrieving personnel from Duty Management System...") rows = await self.dbpool.runQuery(""" select id, callsign, first_name, mi, last_name, email, status, on_site, password from person where status in ('active', 'inactive', 'vintage', 'auditor') """) return dict((dmsID, Ranger( handle=handle, name=fullName(first, middle, last), status=statusFromID(status), email=(email, ), onSite=bool(onSite), dmsID=int(dmsID), password=password, )) for ( dmsID, handle, first, middle, last, email, status, onSite, password, ) in rows)
def test_verifyCredentials_none(self, ranger: Ranger, password: str) -> None: provider = AuthProvider(store=self.store(), dms=self.dms()) ranger = ranger.replace(password=None) user = User(ranger=ranger, groups=()) authorization = self.successResultOf( provider.verifyCredentials(user, password)) self.assertFalse(authorization)
def test_verifyCredentials_mismatch(self, ranger: Ranger, password: str, otherPassword: str) -> None: assume(password != otherPassword) provider = AuthProvider(store=self.store(), dms=self.dms()) ranger = ranger.replace(password=hashPassword(password)) user = User(ranger=ranger, groups=()) authorization = self.successResultOf( provider.verifyCredentials(user, otherPassword)) self.assertFalse(authorization)
def test_verifyCredentials_error(self, ranger: Ranger, password: str) -> None: provider = AuthProvider(store=self.store(), dms=self.dms()) ranger = ranger.replace(password=hashPassword(password)) user = User(ranger=ranger, groups=()) def oops(*args: Any, **kwargs: Any) -> None: raise RuntimeError() assert self.successResultOf(provider.verifyCredentials(user, password)) with patch("ims.auth._provider.verifyPassword", oops): authorization = self.successResultOf( provider.verifyCredentials(user, password)) self.assertFalse(authorization)