@@ -23,57 +23,15 @@ def test_experimental_enabled(self, client):
2323
2424 def test_get_project_vulnerabilities (self , client ):
2525 project_id = 1
26- total_pages = 4
27- total_records = total_pages * 2
26+ total_pages = 1
27+ total_records = total_pages * 3
2828 response_header = {"content-type" : "application/json" }
2929 response_header ["current-page" ] = "1"
3030 response_header ["number-of-pages" ] = str (total_pages )
3131 response_header ["total-records" ] = str (total_records )
32- fake_response_json = """ { "data": [
33- {
34- "itemNumber": 1,
35- "id": 12345,
36- "name": "Inventory Item 1",
37- "type":"component",
38- "priority":"low",
39- "createdBy":"Zach",
40- "createdOn":"Today",
41- "updatedOn":"Tomorrow",
42- "componentName":"snakeyaml",
43- "componentVersionName":"2.0",
44- "vulnerabilitySummary": []
45- },
46- {
47- "itemNumber": 2,
48- "id": 12346,
49- "name": "Inventory Item 2",
50- "type":"component",
51- "priority":"low",
52- "createdBy":"Zach",
53- "createdOn":"Today",
54- "updatedOn":"Tomorrow",
55- "componentName":"snakeyaml",
56- "componentVersionName":"2.0",
57- "vulnerabilitySummary": [{
58- "CvssV2": {
59- "High": 2,
60- "Medium": 2,
61- "Low": 3,
62- "Unknown": 4
63- },
64- "CvssV3": {
65- "Critical": 1,
66- "High": 1,
67- "Medium": 2,
68- "Low": 6,
69- "Unknown": 1
70- }
71- }]
72- }
73- ]}
74- """
75-
76- mock_resp_vuln = """ { "data": [ {
32+ fake_response_json = """
33+ { "projectId": 1, "inventoryItems": [
34+ {"itemNumber":1, "id":1234, "name":"Example component","type":"component","priority":"low","createdBy":"Zach","createdOn":"Today","updatedOn":"Tomorrow","componentName":"snakeyaml","componentVersionName":"2.0","vulnerabilities": [ {
7735 "vulnerabilityId":123456,
7836 "vulnerabilityName":"CVE-123-45678",
7937 "vulnerabilityDescription":"Insecure library! Watch out.",
@@ -84,23 +42,22 @@ def test_get_project_vulnerabilities(self, client):
8442 "vulnerabilityName":"CVE-987-65432",
8543 "vulnerabilityDescription":"Insecure library 2! Watch out.",
8644 "vulnerabilityCvssV3Score": 9,
87- "vulnerabilityCvssV3Severity":"CRITICAL"} ] }
45+ "vulnerabilityCvssV3Severity":"CRITICAL"} ] },
46+ {"itemNumber":2, "id":1235, "name":"Example component 2","type":"component","priority":"low","createdBy":"Zach","createdOn":"Today","updatedOn":"Tomorrow","componentName":"snakeyaml","componentVersionName":"2.0"},
47+ {"itemNumber":3, "id":1235, "name":"Example component 3","type":"component","priority":"low","createdBy":"Zach","createdOn":"Today","updatedOn":"Tomorrow","componentName":"snakeyaml","componentVersionName":"2.0","vulnerabilities":[]}
48+ ]}
8849 """
50+
8951 with requests_mock .Mocker () as m :
9052 m .get (
91- f"{ TEST_URL } /codeinsight/api/projects/ { project_id } /inventorySummary " ,
53+ f"{ TEST_URL } /codeinsight/api/project/inventory/ { project_id } " ,
9254 text = fake_response_json ,
9355 headers = response_header ,
9456 )
95- m .get (
96- f"{ TEST_URL } /codeinsight/api/inventories/12346/vulnerabilities" ,
97- text = mock_resp_vuln ,
98- headers = response_header ,
99- )
10057 vulnerable_items = client .experimental .get_project_vulnerabilities (
10158 project_id
10259 )
103- assert len (vulnerable_items ) > 0
60+ assert len (vulnerable_items ) == 1
10461 assert vulnerable_items [0 ].vulnerabilities is not None
10562 assert (
10663 vulnerable_items [0 ].vulnerabilities [1 ].vulnerabilityName == "CVE-987-65432"
0 commit comments