13
13
from datetime import datetime
14
14
from pathlib import Path
15
15
16
+ import requests
17
+ from jsonschema import validate
16
18
from rich .console import Console
17
19
18
20
from cve_bin_tool .output_engine import OutputEngine , output_csv , output_json , output_pdf
19
21
from cve_bin_tool .output_engine .console import output_console
20
22
from cve_bin_tool .output_engine .util import format_output
21
23
from cve_bin_tool .util import CVE , CVEData , ProductInfo , VersionInfo
22
24
25
+ VEX_SCHEMA = "https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.4.schema.json"
26
+
23
27
24
28
class TestOutputEngine (unittest .TestCase ):
25
29
"""Test the OutputEngine class functions"""
@@ -616,8 +620,8 @@ class TestOutputEngine(unittest.TestCase):
616
620
"name" : "NVD" ,
617
621
"url" : "https://nvd.nist.gov/vuln-metrics/cvss/v2-calculator?name=CVE-1234-1234&vector=C:H&version=2.0" ,
618
622
},
619
- "score" : " 4.2" ,
620
- "severity" : "MEDIUM " ,
623
+ "score" : 4.2 ,
624
+ "severity" : "medium " ,
621
625
"method" : "CVSSv2" ,
622
626
"vector" : "C:H" ,
623
627
}
@@ -630,10 +634,9 @@ class TestOutputEngine(unittest.TestCase):
630
634
"published" : "NOT_KNOWN" ,
631
635
"updated" : "NOT_KNOWN" ,
632
636
"analysis" : {
633
- "state" : "under_review" ,
634
- "response" : "Outstanding" ,
635
- "justification" : "" ,
636
- "detail" : "" ,
637
+ "state" : "in_triage" ,
638
+ "response" : [],
639
+ "detail" : "NewFound" ,
637
640
},
638
641
"affects" : [{"ref" : "urn:cdx:NOTKNOWN/1#product0-1.0" }],
639
642
},
@@ -649,8 +652,8 @@ class TestOutputEngine(unittest.TestCase):
649
652
"name" : "NVD" ,
650
653
"url" : "https://nvd.nist.gov/vuln-metrics/cvss/v2-calculator?name=CVE-1234-1234&vector=CVSS2.0/C:H&version=2.0" ,
651
654
},
652
- "score" : " 1.2" ,
653
- "severity" : "LOW " ,
655
+ "score" : 1.2 ,
656
+ "severity" : "low " ,
654
657
"method" : "CVSSv2" ,
655
658
"vector" : "CVSS2.0/C:H" ,
656
659
}
@@ -663,10 +666,9 @@ class TestOutputEngine(unittest.TestCase):
663
666
"published" : "NOT_KNOWN" ,
664
667
"updated" : "NOT_KNOWN" ,
665
668
"analysis" : {
666
- "state" : "under_review" ,
667
- "response" : "Outstanding" ,
668
- "justification" : "" ,
669
- "detail" : "" ,
669
+ "state" : "in_triage" ,
670
+ "response" : [],
671
+ "detail" : "NewFound" ,
670
672
},
671
673
"affects" : [{"ref" : "urn:cdx:NOTKNOWN/1#product0-1.0" }],
672
674
},
@@ -682,8 +684,8 @@ class TestOutputEngine(unittest.TestCase):
682
684
"name" : "NVD" ,
683
685
"url" : "https://nvd.nist.gov/vuln-metrics/cvss/v3-calculator?name=CVE-1234-1234&vector=CVSS3.0/C:H/I:L/A:M&version=3.1" ,
684
686
},
685
- "score" : " 2.5" ,
686
- "severity" : "LOW " ,
687
+ "score" : 2.5 ,
688
+ "severity" : "low " ,
687
689
"method" : "CVSSv3" ,
688
690
"vector" : "CVSS3.0/C:H/I:L/A:M" ,
689
691
}
@@ -696,10 +698,9 @@ class TestOutputEngine(unittest.TestCase):
696
698
"published" : "NOT_KNOWN" ,
697
699
"updated" : "NOT_KNOWN" ,
698
700
"analysis" : {
699
- "state" : "under_review" ,
700
- "response" : "Outstanding" ,
701
- "justification" : "" ,
702
- "detail" : "" ,
701
+ "state" : "in_triage" ,
702
+ "response" : [],
703
+ "detail" : "NewFound" ,
703
704
},
704
705
"affects" : [{"ref" : "urn:cdx:NOTKNOWN/1#product0-2.8.6" }],
705
706
},
@@ -715,8 +716,8 @@ class TestOutputEngine(unittest.TestCase):
715
716
"name" : "NVD" ,
716
717
"url" : "https://nvd.nist.gov/vuln-metrics/cvss/v2-calculator?name=CVE-1234-1234&vector=C:H/I:L/A:M&version=2.0" ,
717
718
},
718
- "score" : " 7.5" ,
719
- "severity" : "HIGH " ,
719
+ "score" : 7.5 ,
720
+ "severity" : "high " ,
720
721
"method" : "CVSSv2" ,
721
722
"vector" : "C:H/I:L/A:M" ,
722
723
}
@@ -729,10 +730,9 @@ class TestOutputEngine(unittest.TestCase):
729
730
"published" : "NOT_KNOWN" ,
730
731
"updated" : "NOT_KNOWN" ,
731
732
"analysis" : {
732
- "state" : "under_review" ,
733
- "response" : "Outstanding" ,
734
- "justification" : "" ,
735
- "detail" : "" ,
733
+ "state" : "in_triage" ,
734
+ "response" : [],
735
+ "detail" : "NewFound" ,
736
736
},
737
737
"affects" : [{"ref" : "urn:cdx:NOTKNOWN/1#product1-3.2.1.0" }],
738
738
},
@@ -783,7 +783,10 @@ def test_output_vex(self):
783
783
"""Test creating VEX formatted file"""
784
784
self .output_engine .generate_vex (self .MOCK_OUTPUT , "test.vex" )
785
785
with open ("test.vex" ) as f :
786
- self .assertEqual (json .load (f ), self .VEX_FORMATTED_OUTPUT [0 ])
786
+ vex_json = json .load (f )
787
+ SCHEMA = requests .get (VEX_SCHEMA ).json ()
788
+ validate (vex_json , SCHEMA )
789
+ self .assertEqual (vex_json , self .VEX_FORMATTED_OUTPUT [0 ])
787
790
Path ("test.vex" ).unlink ()
788
791
789
792
@unittest .skipUnless (
0 commit comments