@@ -59,12 +59,12 @@ def test_profiles_list_via_main(self):
5959class TestNlboot (unittest .TestCase ):
6060 def test_inspect_evidence_fixture (self ):
6161 path = FIXTURES / "sample_nlboot_evidence.json"
62- args = _Args (path = str (path ))
62+ args = _Args (path = str (path ), validate = False )
6363 result = nlboot .inspect_evidence (args )
6464 self .assertIn (result , (0 , None ))
6565
6666 def test_inspect_evidence_missing_file (self ):
67- args = _Args (path = "/nonexistent/path/evidence.json" )
67+ args = _Args (path = "/nonexistent/path/evidence.json" , validate = False )
6868 result = nlboot .inspect_evidence (args )
6969 self .assertEqual (result , 1 )
7070
@@ -73,7 +73,7 @@ def test_inspect_evidence_bad_json(self):
7373 f .write ("not json {{{" )
7474 tmp_path = f .name
7575 try :
76- args = _Args (path = tmp_path )
76+ args = _Args (path = tmp_path , validate = False )
7777 result = nlboot .inspect_evidence (args )
7878 self .assertEqual (result , 1 )
7979 finally :
@@ -84,6 +84,67 @@ def test_nlboot_evidence_inspect_via_main(self):
8484 rc = main (["nlboot" , "evidence" , "inspect" , str (path )])
8585 self .assertEqual (rc , 0 )
8686
87+ # --- schema validation ---
88+
89+ def test_validate_evidence_valid_fixture (self ):
90+ path = FIXTURES / "sample_nlboot_evidence.json"
91+ args = _Args (path = str (path ))
92+ result = nlboot .validate_evidence (args )
93+ self .assertEqual (result , 0 )
94+
95+ def test_validate_evidence_invalid_fixture (self ):
96+ path = FIXTURES / "invalid_nlboot_evidence.json"
97+ args = _Args (path = str (path ))
98+ result = nlboot .validate_evidence (args )
99+ self .assertEqual (result , 1 )
100+
101+ def test_validate_evidence_missing_file (self ):
102+ args = _Args (path = "/nonexistent/evidence.json" )
103+ result = nlboot .validate_evidence (args )
104+ self .assertEqual (result , 1 )
105+
106+ def test_validate_evidence_bad_json (self ):
107+ with tempfile .NamedTemporaryFile (suffix = ".json" , mode = "w" , delete = False ) as f :
108+ f .write ("not json {{{" )
109+ tmp_path = f .name
110+ try :
111+ args = _Args (path = tmp_path )
112+ result = nlboot .validate_evidence (args )
113+ self .assertEqual (result , 1 )
114+ finally :
115+ os .unlink (tmp_path )
116+
117+ def test_validate_evidence_unknown_schema (self ):
118+ with tempfile .NamedTemporaryFile (suffix = ".json" , mode = "w" , delete = False ) as f :
119+ json .dump ({"schemaVersion" : "unknown-schema.v99" , "kind" : "Unknown" }, f )
120+ tmp_path = f .name
121+ try :
122+ args = _Args (path = tmp_path )
123+ result = nlboot .validate_evidence (args )
124+ self .assertEqual (result , 1 )
125+ finally :
126+ os .unlink (tmp_path )
127+
128+ def test_inspect_with_validate_flag_valid (self ):
129+ path = FIXTURES / "sample_nlboot_evidence.json"
130+ rc = main (["nlboot" , "evidence" , "inspect" , "--validate" , str (path )])
131+ self .assertEqual (rc , 0 )
132+
133+ def test_inspect_with_validate_flag_invalid (self ):
134+ path = FIXTURES / "invalid_nlboot_evidence.json"
135+ rc = main (["nlboot" , "evidence" , "inspect" , "--validate" , str (path )])
136+ self .assertEqual (rc , 1 )
137+
138+ def test_validate_subcommand_valid_via_main (self ):
139+ path = FIXTURES / "sample_nlboot_evidence.json"
140+ rc = main (["nlboot" , "evidence" , "validate" , str (path )])
141+ self .assertEqual (rc , 0 )
142+
143+ def test_validate_subcommand_invalid_via_main (self ):
144+ path = FIXTURES / "invalid_nlboot_evidence.json"
145+ rc = main (["nlboot" , "evidence" , "validate" , str (path )])
146+ self .assertEqual (rc , 1 )
147+
87148
88149class TestRelease (unittest .TestCase ):
89150 def test_inspect_fixture (self ):
0 commit comments