Exemplo n.º 1
0
    def test_missing_cached_entry(self) -> None:
        path = Path(self.tmp.name).joinpath("vulns01.json")
        self._write_cache(path, time.time())

        with patch("ossaudit.const.CACHE", path):
            entry = cache.get("pkg:pypi/[email protected]")

        self.assertIsNone(entry)
Exemplo n.º 2
0
    def test_have_old_cached_entry(self) -> None:
        path = Path(self.tmp.name).joinpath("vulns01.json")
        self._write_cache(path, time.time() + const.CACHE_TIME + 1)

        with patch("ossaudit.const.CACHE", path):
            entry = cache.get("pkg:pypi/[email protected]")

        self.assertIsNone(entry)
Exemplo n.º 3
0
    def test_have_cached_entry(self) -> None:
        path = Path(self.tmp.name).joinpath("vulns01.json")
        self._write_cache(path, time.time())

        with patch("ossaudit.const.CACHE", path):
            entry = cache.get("pkg:pypi/[email protected]") or {}

        self.assertEqual(entry["coordinates"], "pkg:pypi/[email protected]")
Exemplo n.º 4
0
    def test_ignore_invalid(self) -> None:
        path = Path(self.tmp.name).joinpath("vulns01.json")
        path.write_text("foo")

        entry = {"coordinates": "abcd"}
        with patch("ossaudit.const.CACHE", path):
            cache.save(entry)
            entry["time"] = ANY
            self.assertEqual(cache.get("abcd"), entry)
Exemplo n.º 5
0
 def test_no_cache(self) -> None:
     self.assertIsNone(cache.get("x"))
Exemplo n.º 6
0
 def test_invalid_cache(self) -> None:
     path = Path(self.tmp.name).joinpath("invalid.json")
     path.write_text("abcd")
     with patch("ossaudit.const.CACHE", path):
         self.assertIsNone(cache.get("foo"))