Skip to content

Commit c3e70a8

Browse files
author
Glenn Snyder
committed
fixed unit test and changing logging to a named logger in the library
1 parent cf3f49d commit c3e70a8

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

examples/get_bom_component_vulnerability_info.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
response = hub.execute_get(vulnerable_components_url, custom_headers=custom_headers)
7272
vulnerable_bom_components = response.json().get('items', [])
7373

74+
bdsa_records = set()
75+
cve_records = set()
76+
7477
for i, vuln in enumerate(vulnerable_bom_components):
7578
source = vuln['vulnerabilityWithRemediation']['source']
7679
vuln_name = vuln['vulnerabilityWithRemediation']['vulnerabilityName']
@@ -87,18 +90,23 @@
8790
vuln_details_response = hub.execute_get(vuln_url, custom_headers={'Accept': 'application/json'})
8891
vuln_details = vuln_details_response.json()
8992

90-
import pdb; pdb.set_trace()
91-
9293
vuln['additional_vuln_info'] = vuln_details
94+
9395
if source == 'BDSA':
96+
bdsa_records.add(vuln_name)
97+
9498
# get related vulnerability info, i.e. CVE
9599
# note: not all BDSA records will have a corresponding CVE record
96100
cve_url = hub.get_link(vuln_details, "related-vulnerability")
97101
if cve_url:
98102
cve_details_response = hub.execute_get(cve_url, custom_headers={'Accept': 'application/json'})
99103
cve_details = cve_details_response.json()
100104
vuln['related_vulnerability'] = cve_details
101-
105+
cve_records.add(cve_details['name'])
106+
elif source == "NVD":
107+
cve_records.add(vuln_name)
108+
else:
109+
logging.warning(f"source {source} was not recognized")
102110

103111
if vulnerable_bom_components:
104112
vulnerable_bom_components = sorted(
@@ -137,7 +145,9 @@
137145

138146
everything = {
139147
'counts': counts,
140-
'vulnerabilities': vulnerable_bom_components
148+
'vulnerabilities': vulnerable_bom_components,
149+
'bdsa_records': list(bdsa_records),
150+
'cve_records': list(cve_records),
141151
}
142152

143153
print(json.dumps(everything))

test/test_hub_rest_api_python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_get_policy_url(mock_hub_instance):
158158

159159
def test_get_parameter_string(mock_hub_instance):
160160
assert mock_hub_instance._get_parameter_string({"limit":"100"}) == "?limit=100"
161-
assert mock_hub_instance._get_parameter_string({"limit":"100", "q":"name:my-name"}) == "?limit=100&q=name:my-name"
161+
assert mock_hub_instance._get_parameter_string({"limit":"100", "q":"name:my-name"}) == "?limit=100&q=name%3Amy-name"
162162
assert mock_hub_instance._get_parameter_string({"limit":"100", "sort":"updatedAt"}) == "?limit=100&sort=updatedAt"
163163

164164
def test_hub_instance_username_password_for_auth(mock_hub_instance):

0 commit comments

Comments
 (0)