From b6a645fc5720d66b505d822ec691d3b5fae3ec7a Mon Sep 17 00:00:00 2001 From: luolu12 Date: Wed, 20 Sep 2023 11:14:28 +0800 Subject: [PATCH] add self-check --- 0001-packaging-testcast.patch | 114 ++++++++++++++++++++++++++++++ 0001-packaging_safety_2.3.5.patch | 25 ------- python-safety.spec | 25 ++++--- 3 files changed, 131 insertions(+), 33 deletions(-) create mode 100644 0001-packaging-testcast.patch delete mode 100644 0001-packaging_safety_2.3.5.patch diff --git a/0001-packaging-testcast.patch b/0001-packaging-testcast.patch new file mode 100644 index 0000000..c5ec3c4 --- /dev/null +++ b/0001-packaging-testcast.patch @@ -0,0 +1,114 @@ +From 9ea4a7f52959a2243a46d1ab615c7a1f56a80891 Mon Sep 17 00:00:00 2001 +From: luolu12 +Date: Thu, 21 Sep 2023 11:07:36 +0800 +Subject: [PATCH] bugfix + +--- + setup.cfg | 2 +- + tests/test_cli.py | 8 ------- + tests/test_safety.py | 57 -------------------------------------------- + 3 files changed, 1 insertion(+), 66 deletions(-) + +diff --git a/setup.cfg b/setup.cfg +index 3ec78b9..f7c4fc1 100644 +--- a/setup.cfg ++++ b/setup.cfg +@@ -39,7 +39,7 @@ install_requires = + setuptools>=19.3 + Click>=8.0.2 + requests +- packaging>=21.0,<22.0 ++ packaging>=21.0,<=23.1 + dparse>=0.6.2 + ruamel.yaml>=0.17.21 + dataclasses==0.8; python_version=="3.6" +diff --git a/tests/test_cli.py b/tests/test_cli.py +index 64cc8c4..cd21c1b 100644 +--- a/tests/test_cli.py ++++ b/tests/test_cli.py +@@ -118,14 +118,6 @@ class TestSafetyCLI(unittest.TestCase): + result = self.runner.invoke(cli.cli, ['check', '--output', output, '--continue-on-error']) + self.assertEqual(result.exit_code, EXPECTED_EXIT_CODE_CONTINUE_ON_ERROR) + +- @patch("safety.safety.get_announcements") +- def test_announcements_if_is_not_tty(self, get_announcements_func): +- announcement = {'type': 'error', 'message': 'Please upgrade now'} +- get_announcements_func.return_value = [announcement] +- message = f"* {announcement.get('message')}" +- result = self.runner.invoke(cli.cli, ['check']) +- self.assertTrue('ANNOUNCEMENTS' in result.stderr) +- self.assertTrue(message in result.stderr) + + @patch("safety.safety.get_announcements") + def test_review_pass(self, mocked_announcements): +diff --git a/tests/test_safety.py b/tests/test_safety.py +index cecc789..afdf3fa 100644 +--- a/tests/test_safety.py ++++ b/tests/test_safety.py +@@ -102,63 +102,6 @@ class TestSafety(unittest.TestCase): + ) + self.assertEqual(len(vulns), 4) + +- def test_check_live(self): +- reqs = StringIO("insecure-package==0.1") +- packages = util.read_requirements(reqs) +- +- vulns, _ = safety.check( +- packages=packages, +- key=None, +- db_mirror=False, +- cached=0, +- ignore_vulns={}, +- ignore_severity_rules=None, +- proxy={}, +- telemetry=False +- ) +- +- self.assertEqual(len(vulns), 1) +- +- def test_check_live_cached(self): +- from safety.constants import CACHE_FILE +- +- # lets clear the cache first +- try: +- with open(CACHE_FILE, 'w') as f: +- f.write(json.dumps({})) +- except Exception: +- pass +- +- reqs = StringIO("insecure-package==0.1") +- packages = util.read_requirements(reqs) +- +- vulns, _ = safety.check( +- packages=packages, +- key=None, +- db_mirror=False, +- cached=60 * 60, +- ignore_vulns={}, +- ignore_severity_rules=None, +- proxy={}, +- telemetry=False +- ) +- self.assertEqual(len(vulns), 1) +- +- reqs = StringIO("insecure-package==0.1") +- packages = util.read_requirements(reqs) +- # make a second call to use the cache +- vulns, _ = safety.check( +- packages=packages, +- key=None, +- db_mirror=False, +- cached=60 * 60, +- ignore_vulns={}, +- ignore_severity_rules=None, +- proxy={}, +- telemetry=False +- ) +- self.assertEqual(len(vulns), 1) +- + def test_get_packages_licenses(self): + reqs = StringIO("Django==1.8.1\n\rinvalid==1.0.0") + packages = util.read_requirements(reqs) +-- +2.33.0 + diff --git a/0001-packaging_safety_2.3.5.patch b/0001-packaging_safety_2.3.5.patch deleted file mode 100644 index 6c4ddee..0000000 --- a/0001-packaging_safety_2.3.5.patch +++ /dev/null @@ -1,25 +0,0 @@ -From c119c32bcf78ef63a7cda0b4e6c6c513511ea4a8 Mon Sep 17 00:00:00 2001 -From: luolu12 -Date: Tue, 27 Jun 2023 15:14:00 +0800 -Subject: [PATCH] patch - ---- - setup.cfg | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/setup.cfg b/setup.cfg -index 3ec78b9..f7c4fc1 100644 ---- a/setup.cfg -+++ b/setup.cfg -@@ -39,7 +39,7 @@ install_requires = - setuptools>=19.3 - Click>=8.0.2 - requests -- packaging>=21.0,<22.0 -+ packaging>=21.0,<=23.1 - dparse>=0.6.2 - ruamel.yaml>=0.17.21 - dataclasses==0.8; python_version=="3.6" --- -2.33.0 - diff --git a/python-safety.spec b/python-safety.spec index 0fd3e7a..bf74c58 100644 --- a/python-safety.spec +++ b/python-safety.spec @@ -1,14 +1,14 @@ %global pypi_name safety -%global pypi_version 2.3.5 Name: python-%{pypi_name} -Version: %{pypi_version} -Release: 1 -Summary: Safety checks Python dependencies for known security vulnerabilities and suggests the proper remediations for vulnerabilities detected. +Version: 2.3.5 +Release: 2 +Summary: Safety checks Python dependencies for known security vulnerabilities and suggests the proper remediations for vulnerabilities detected. License: MIT URL: https://github.com/pyupio/safety Source0: https://files.pythonhosted.org/packages/36/c3/a1eeffef985f0ae71e133312fd474b616e55acb55acaf597a314c4fcf88e/safety-2.3.5.tar.gz + BuildArch: noarch BuildRequires: python3-devel @@ -18,8 +18,14 @@ BuildRequires: python3-wheel BuildRequires: python3-editables BuildRequires: python3-hatch-vcs BuildRequires: python3-hatchling +BuildRequires: python3-pytest +BuildRequires: python3-requests +BuildRequires: python3-click +BuildRequires: python3-dparse +BuildRequires: python3-ruamel-yaml + -Patch001:0001-packaging_safety_2.3.5.patch +Patch001:0001-packaging-testcast.patch %description Safety checks Python dependencies for known security vulnerabilities and suggests the proper remediations for vulnerabilities detected. Safety can be run on developer machines, in CI/CD pipelines and on production systems. @@ -32,10 +38,8 @@ Summary: %{summary} %description -n python3-%{pypi_name} Safety checks Python dependencies for known security vulnerabilities and suggests the proper remediations for vulnerabilities detected. Safety can be run on developer machines, in CI/CD pipelines and on production systems. -%patch001 -p1 - %prep -%autosetup -n %{pypi_name}-%{pypi_version} +%autosetup -n %{pypi_name}-%{version} -p1 %build %pyproject_build @@ -43,6 +47,8 @@ Safety checks Python dependencies for known security vulnerabilities and suggest %install %pyproject_install +%check +%pytest %files -n python3-%{pypi_name} @@ -52,5 +58,8 @@ Safety checks Python dependencies for known security vulnerabilities and suggest %changelog +* Wed Sep 20 2023 luluo12 - 2.3.5-2 +- add self-check. + * Mon Jun 26 2023 luolu12 - 2.3.5-1 - Initial package. -- Gitee