def setUp(self) -> None: super().setUp() RefreshLog.init() self.s = RefreshLog._session() self.s.query(RefreshLog).delete() cia = _ClamavTestItem('spam', 'option', 'a', path='a') cib = _ClamavTestItem('spamalot', 'option', 'b', path='b') self.s.add(RefreshLog(cia, 'dummy')) self.s.add(RefreshLog(cib, 'dummy')) self.s.commit() self.s.commit()
def test_refresh(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_MD5, 'md5', f'{self.TMPDIR}/x') self.s.add(RefreshLog(ci, DIGEST_DUMMY)) self.s.commit() n = self.ref.refresh_all() self.assertEqual(3, n)
def test_refresh_digest_match(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_MD5, 'md5', f'{self.TMPDIR}/x') r = RefreshLog(ci, DIGEST_MD5) self.s.add(r) self.s.commit() self.assertFalse(self.ref.refresh(ci))
def test_url_blank(self): ci = _ClamavTestItem('unittest4', 'url_blank', '', 'md5', f'{self.TMPDIR}/blank') self.s.add(RefreshLog(ci, DIGEST_DUMMY)) self.s.commit() n = self.ref.refresh_all() self.assertEqual(3, n)
def test_refresh_age(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_SHA256, 'sha256', f'{self.TMPDIR}/x') r = RefreshLog(ci, DIGEST_DUMMY) r.updated += timedelta(minutes=10) self.s.add(r) self.s.commit() self.assertFalse(self.ref.refresh(ci))
def setUp(self) -> None: super().setUp() self.ci = _ClamavTestItem(url=URL1, section=self.UNITTEST, option='option', path='path') RefreshLog.init() self.s = RefreshLog._session() self.s.query(RefreshLog).delete() self.s.add(RefreshLog(self.ci, DIGEST_DUMMY)) self.s.commit()
def test_unknown_check(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_BAD_SHA256, 'BAD') self.assertFalse(self.ref.refresh(ci))
def test_missing_path(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_MD5, 'md5') with self.assertRaises(TypeError): self.assertTrue(self.ref.refresh(ci))
def test_missing_checksum(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_MISSING, 'sha256') self.assertFalse(self.ref.refresh(ci))
def test_good_md5(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_MD5, 'md5', f'{self.TMPDIR}/x') self.assertTrue(self.ref.refresh(ci))
def test_good_sha256(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_SHA256, 'sha256', f'{self.TMPDIR}/x') self.assertTrue(self.ref.refresh(ci))
def test_bad_sha256(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_BAD_SHA256, 'sha256') self.assertFalse(self.ref.refresh(ci))
def test_404(self): ci = _ClamavTestItem(self.UNITTEST, 'x', URL_BAD_SHA256 + 'BAD') self.assertFalse(self.ref.refresh(ci))