File tree Expand file tree Collapse file tree 3 files changed +35
-30
lines changed
Expand file tree Collapse file tree 3 files changed +35
-30
lines changed Original file line number Diff line number Diff line change 66 asdict ,
77 dataclass ,
88)
9+ from enum import Enum
910
1011import typer
1112
@@ -78,3 +79,29 @@ def json_str(self) -> str:
7879 """Converts to a string-encoded JSON"""
7980 issue_json = asdict (self )
8081 return json .dumps (issue_json )
82+
83+
84+ class VulnerabilitySource (str , Enum ):
85+ CVE = "CVE"
86+ CWE = "CWE"
87+ GHSA = "GHSA"
88+ PYSEC = "PYSEC"
89+
90+ @classmethod
91+ def from_prefix (cls , name : str ) -> VulnerabilitySource | None :
92+ for el in cls :
93+ if name .upper ().startswith (el .value ):
94+ return el
95+ return None
96+
97+ def get_link (self , package : str , vuln_id : str ) -> str :
98+ if self == VulnerabilitySource .CWE :
99+ cwe_id = vuln_id .upper ().replace (f"{ VulnerabilitySource .CWE .value } -" , "" )
100+ return f"https://cwe.mitre.org/data/definitions/{ cwe_id } .html"
101+
102+ map_link = {
103+ VulnerabilitySource .CVE : "https://nvd.nist.gov/vuln/detail/{vuln_id}" ,
104+ VulnerabilitySource .GHSA : "https://github.com/advisories/{vuln_id}" ,
105+ VulnerabilitySource .PYSEC : "https://github.com/pypa/advisory-database/blob/main/vulns/{package}/{vuln_id}.yaml" ,
106+ }
107+ return map_link [self ].format (package = package , vuln_id = vuln_id )
Original file line number Diff line number Diff line change 2121from exasol .toolbox .security import (
2222 GitHubVulnerabilityIssue ,
2323 VulnerabilityIssue ,
24+ VulnerabilitySource ,
2425)
2526
2627stdout = print
@@ -81,32 +82,6 @@ def from_maven(report: str) -> Iterable[VulnerabilityIssue]:
8182 )
8283
8384
84- class VulnerabilitySource (str , Enum ):
85- CVE = "CVE"
86- CWE = "CWE"
87- GHSA = "GHSA"
88- PYSEC = "PYSEC"
89-
90- @classmethod
91- def from_prefix (cls , name : str ) -> VulnerabilitySource | None :
92- for el in cls :
93- if name .upper ().startswith (el .value ):
94- return el
95- return None
96-
97- def get_link (self , package : str , vuln_id : str ) -> str :
98- if self == VulnerabilitySource .CWE :
99- cwe_id = vuln_id .upper ().replace (f"{ VulnerabilitySource .CWE .value } -" , "" )
100- return f"https://cwe.mitre.org/data/definitions/{ cwe_id } .html"
101-
102- map_link = {
103- VulnerabilitySource .CVE : "https://nvd.nist.gov/vuln/detail/{vuln_id}" ,
104- VulnerabilitySource .GHSA : "https://github.com/advisories/{vuln_id}" ,
105- VulnerabilitySource .PYSEC : "https://github.com/pypa/advisory-database/blob/main/vulns/{package}/{vuln_id}.yaml" ,
106- }
107- return map_link [self ].format (package = package , vuln_id = vuln_id )
108-
109-
11085def identify_pypi_references (
11186 references : list [str ], package_name : str
11287) -> tuple [list [str ], list [str ], list [str ]]:
Original file line number Diff line number Diff line change 88
99import pytest
1010
11- from exasol .toolbox .security import GitHubVulnerabilityIssue
11+ from exasol .toolbox .security import (
12+ GitHubVulnerabilityIssue ,
13+ VulnerabilitySource ,
14+ )
1215from exasol .toolbox .tools import security
1316
1417
@@ -493,14 +496,14 @@ def test_from_json(json_file, expected):
493496 [
494497 pytest .param ("DUMMY" , None , id = "without_a_matching_prefix_returns_none" ),
495498 pytest .param (
496- f"{ security . VulnerabilitySource .CWE .value .lower ()} -1234" ,
497- security . VulnerabilitySource .CWE ,
499+ f"{ VulnerabilitySource .CWE .value .lower ()} -1234" ,
500+ VulnerabilitySource .CWE ,
498501 id = "with_matching_prefix_returns_vulnerability_source" ,
499502 ),
500503 ],
501504)
502505def test_from_prefix (prefix : str , expected ):
503- assert security . VulnerabilitySource .from_prefix (prefix ) == expected
506+ assert VulnerabilitySource .from_prefix (prefix ) == expected
504507
505508
506509@pytest .mark .parametrize (
You can’t perform that action at this time.
0 commit comments