22
22
23
23
from cve_bin_tool .cli import main
24
24
from cve_bin_tool .cvedb import DISK_LOCATION_DEFAULT
25
+ from cve_bin_tool .error_handler import ERROR_CODES , InsufficientArgs
25
26
from cve_bin_tool .extractor import Extractor
26
27
from cve_bin_tool .version_scanner import VersionScanner
27
28
@@ -88,37 +89,37 @@ def test_usage(self):
88
89
"""Test that the usage returns 0"""
89
90
with pytest .raises (SystemExit ) as e :
90
91
main (["cve-bin-tool" ])
91
- assert e .value .args [0 ] == 24
92
+ assert e .value .args [0 ] == ERROR_CODES [ InsufficientArgs ]
92
93
93
94
def test_invalid_file_or_directory (self ):
94
95
"""Test behaviour with an invalid file/directory"""
95
96
with pytest .raises (SystemExit ) as e :
96
97
main (["cve-bin-tool" , "non-existant" ])
97
- assert e .value .args [0 ] == 21
98
+ assert e .value .args [0 ] == ERROR_CODES [ FileNotFoundError ]
98
99
99
100
def test_invalid_parameter (self ):
100
101
"""Test that invalid parmeters exit with expected error code.
101
- ArgParse calls sys.exit(2) for all errors """
102
+ ArgParse calls sys.exit(2) for all errors"""
102
103
103
104
# no directory specified
104
105
with pytest .raises (SystemExit ) as e :
105
106
main (["cve-bin-tool" , "--bad-param" ])
106
- assert e .value .args [0 ] == 2
107
+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
107
108
108
109
# bad parameter (but good directory)
109
110
with pytest .raises (SystemExit ) as e :
110
111
main (["cve-bin-tool" , "--bad-param" , self .tempdir ])
111
- assert e .value .args [0 ] == 2
112
+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
112
113
113
114
# worse parameter
114
115
with pytest .raises (SystemExit ) as e :
115
116
main (["cve-bin-tool" , "--bad-param && cat hi" , self .tempdir ])
116
- assert e .value .args [0 ] == 2
117
+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
117
118
118
119
# bad parameter after directory
119
120
with pytest .raises (SystemExit ) as e :
120
121
main (["cve-bin-tool" , self .tempdir , "--bad-param;cat hi" ])
121
- assert e .value .args [0 ] == 2
122
+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
122
123
123
124
@unittest .skipUnless (LONG_TESTS () > 0 , "Skipping long tests" )
124
125
def test_update_flags (self ):
@@ -136,7 +137,7 @@ def test_update_flags(self):
136
137
)
137
138
with pytest .raises (SystemExit ) as e :
138
139
main (["cve-bin-tool" , "-u" , "whatever" , "-n" , "json" , self .tempdir ])
139
- assert e .value .args [0 ] == 2
140
+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
140
141
141
142
@staticmethod
142
143
def check_exclude_log (caplog , exclude_path , checkers ):
@@ -349,11 +350,11 @@ def test_severity(self, capsys, caplog):
349
350
# Check command line parameters - wrong case
350
351
with pytest .raises (SystemExit ) as e :
351
352
main (["cve-bin-tool" , "-S" , "HIGH" , self .tempdir ])
352
- assert e .value .args [0 ] == 2
353
+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
353
354
# Check command line parameters - wrong option
354
355
with pytest .raises (SystemExit ) as e :
355
356
main (["cve-bin-tool" , "-S" , "ALL" , self .tempdir ])
356
- assert e .value .args [0 ] == 2
357
+ assert e .value .args [0 ] == ERROR_CODES [ SystemExit ]
357
358
358
359
my_test_filename = "sevtest.csv"
359
360
0 commit comments