44import pytest
55
66from unblob .file_utils import InvalidInputFormat
7- from unblob .models import Chunk , ProcessResult , Task , TaskResult , UnknownChunk , to_json
7+ from unblob .models import (
8+ Chunk ,
9+ ProcessResult ,
10+ Task ,
11+ TaskResult ,
12+ UnknownChunk ,
13+ ValidChunk ,
14+ to_json ,
15+ )
816from unblob .report import (
917 ChunkReport ,
1018 ExtractCommandFailedReport ,
@@ -170,56 +178,57 @@ def test_process_result_conversion(self):
170178 decoded_report = json .loads (json_text )
171179 assert decoded_report == [
172180 {
173- "__typename__" : "TaskResult" ,
181+ "task" : {
182+ "path" : "/nonexistent" ,
183+ "depth" : 0 ,
184+ "blob_id" : "" ,
185+ "is_multi_file" : False ,
186+ "__typename__" : "Task" ,
187+ },
174188 "reports" : [
175189 {
176- "__typename__" : "StatReport" ,
190+ "path" : "/nonexistent" ,
191+ "size" : 384 ,
177192 "is_dir" : False ,
178193 "is_file" : True ,
179194 "is_link" : False ,
180195 "link_target" : None ,
181- "path" : "/nonexistent" ,
182- "size" : 384 ,
196+ "__typename__" : "StatReport" ,
183197 },
184198 {
185- "__typename__" : "FileMagicReport" ,
186199 "magic" : "Zip archive data, at least v2.0 to extract" ,
187200 "mime_type" : "application/zip" ,
201+ "__typename__" : "FileMagicReport" ,
188202 },
189203 {
190- "__typename__" : "HashReport" ,
191204 "md5" : "9019fcece2433ad7f12c077e84537a74" ,
192205 "sha1" : "36998218d8f43b69ef3adcadf2e8979e81eed166" ,
193206 "sha256" : "7d7ca7e1410b702b0f85d18257aebb964ac34f7fad0a0328d72e765bfcb21118" ,
207+ "__typename__" : "HashReport" ,
194208 },
195209 {
196- "__typename__" : "ChunkReport" ,
197- "end_offset" : 384 ,
198- "extraction_reports" : [],
199- "handler_name" : "zip" ,
200210 "id" : "test_basic_conversion:id" ,
201- "is_encrypted" : False ,
202- "size" : 384 ,
211+ "handler_name" : "zip" ,
203212 "start_offset" : 0 ,
213+ "end_offset" : 384 ,
214+ "size" : 384 ,
215+ "is_encrypted" : False ,
216+ "metadata" : {},
217+ "extraction_reports" : [],
218+ "__typename__" : "ChunkReport" ,
204219 },
205220 ],
206221 "subtasks" : [
207222 {
208- "__typename__" : "Task" ,
209- "blob_id" : "test_basic_conversion:id" ,
223+ "path" : "/extractions/nonexistent_extract" ,
210224 "depth" : 314 ,
225+ "blob_id" : "test_basic_conversion:id" ,
211226 "is_multi_file" : False ,
212- "path " : "/extractions/nonexistent_extract " ,
227+ "__typename__ " : "Task " ,
213228 }
214229 ],
215- "task" : {
216- "__typename__" : "Task" ,
217- "blob_id" : "" ,
218- "depth" : 0 ,
219- "is_multi_file" : False ,
220- "path" : "/nonexistent" ,
221- },
222- },
230+ "__typename__" : "TaskResult" ,
231+ }
223232 ]
224233
225234 def test_exotic_command_output (self ):
@@ -235,35 +244,44 @@ def test_exotic_command_output(self):
235244 decoded_report = json .loads (json_text )
236245
237246 assert decoded_report == {
238- "__typename__" : "ExtractCommandFailedReport" ,
239- "command" : "dump all bytes" ,
240- "exit_code" : 1 ,
241247 "severity" : "WARNING" ,
248+ "command" : "dump all bytes" ,
249+ "stdout" : "\x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 "
250+ "\t \n \x0b \x0c \r \x0e \x0f \x10 \x11 \x12 \x13 \x14 \x15 \x16 "
251+ "\x17 \x18 \x19 \x1a \x1b \x1c \x1d \x1e \x1f !\" #$%&'()*+,"
252+ "-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\ ]"
253+ "^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f \udc80 \udc81 "
254+ "\udc82 \udc83 \udc84 \udc85 \udc86 \udc87 \udc88 \udc89 "
255+ "\udc8a \udc8b \udc8c \udc8d \udc8e \udc8f \udc90 \udc91 "
256+ "\udc92 \udc93 \udc94 \udc95 \udc96 \udc97 \udc98 \udc99 "
257+ "\udc9a \udc9b \udc9c \udc9d \udc9e \udc9f \udca0 \udca1 "
258+ "\udca2 \udca3 \udca4 \udca5 \udca6 \udca7 \udca8 \udca9 "
259+ "\udcaa \udcab \udcac \udcad \udcae \udcaf \udcb0 \udcb1 "
260+ "\udcb2 \udcb3 \udcb4 \udcb5 \udcb6 \udcb7 \udcb8 \udcb9 "
261+ "\udcba \udcbb \udcbc \udcbd \udcbe \udcbf \udcc0 \udcc1 "
262+ "\udcc2 \udcc3 \udcc4 \udcc5 \udcc6 \udcc7 \udcc8 \udcc9 "
263+ "\udcca \udccb \udccc \udccd \udcce \udccf \udcd0 \udcd1 "
264+ "\udcd2 \udcd3 \udcd4 \udcd5 \udcd6 \udcd7 \udcd8 \udcd9 "
265+ "\udcda \udcdb \udcdc \udcdd \udcde \udcdf \udce0 \udce1 "
266+ "\udce2 \udce3 \udce4 \udce5 \udce6 \udce7 \udce8 \udce9 "
267+ "\udcea \udceb \udcec \udced \udcee \udcef \udcf0 \udcf1 "
268+ "\udcf2 \udcf3 \udcf4 \udcf5 \udcf6 \udcf7 \udcf8 \udcf9 "
269+ "\udcfa \udcfb \udcfc \udcfd \udcfe \udcff " ,
242270 "stderr" : "stdout is pretty strange ;)" ,
243- "stdout" : (
244- "b'\\ x00\\ x01\\ x02\\ x03\\ x04\\ x05\\ x06\\ x07"
245- "\\ x08\\ t\\ n\\ x0b\\ x0c\\ r\\ x0e\\ x0f"
246- "\\ x10\\ x11\\ x12\\ x13\\ x14\\ x15\\ x16\\ x17"
247- '\\ x18\\ x19\\ x1a\\ x1b\\ x1c\\ x1d\\ x1e\\ x1f !"#'
248- "$%&\\ '()*+,-./0123456789:;<=>?@AB"
249- "CDEFGHIJKLMNOPQRSTUVWXYZ[\\ \\ ]^_`a"
250- "bcdefghijklmnopqrstuvwxyz{|}~\\ x7f"
251- "\\ x80\\ x81\\ x82\\ x83\\ x84\\ x85\\ x86\\ x87"
252- "\\ x88\\ x89\\ x8a\\ x8b\\ x8c\\ x8d\\ x8e\\ x8f"
253- "\\ x90\\ x91\\ x92\\ x93\\ x94\\ x95\\ x96\\ x97"
254- "\\ x98\\ x99\\ x9a\\ x9b\\ x9c\\ x9d\\ x9e\\ x9f"
255- "\\ xa0\\ xa1\\ xa2\\ xa3\\ xa4\\ xa5\\ xa6\\ xa7"
256- "\\ xa8\\ xa9\\ xaa\\ xab\\ xac\\ xad\\ xae\\ xaf"
257- "\\ xb0\\ xb1\\ xb2\\ xb3\\ xb4\\ xb5\\ xb6\\ xb7"
258- "\\ xb8\\ xb9\\ xba\\ xbb\\ xbc\\ xbd\\ xbe\\ xbf"
259- "\\ xc0\\ xc1\\ xc2\\ xc3\\ xc4\\ xc5\\ xc6\\ xc7"
260- "\\ xc8\\ xc9\\ xca\\ xcb\\ xcc\\ xcd\\ xce\\ xcf"
261- "\\ xd0\\ xd1\\ xd2\\ xd3\\ xd4\\ xd5\\ xd6\\ xd7"
262- "\\ xd8\\ xd9\\ xda\\ xdb\\ xdc\\ xdd\\ xde\\ xdf"
263- "\\ xe0\\ xe1\\ xe2\\ xe3\\ xe4\\ xe5\\ xe6\\ xe7"
264- "\\ xe8\\ xe9\\ xea\\ xeb\\ xec\\ xed\\ xee\\ xef"
265- "\\ xf0\\ xf1\\ xf2\\ xf3\\ xf4\\ xf5\\ xf6\\ xf7"
266- "\\ xf8\\ xf9\\ xfa\\ xfb\\ xfc\\ xfd\\ xfe\\ xff"
267- "'"
268- ),
271+ "exit_code" : 1 ,
272+ "__typename__" : "ExtractCommandFailedReport" ,
269273 }
274+
275+ @pytest .mark .parametrize (
276+ "metadata" ,
277+ [
278+ pytest .param (1 , id = "metadata_int" ),
279+ pytest .param (0.2 , id = "metadata_float" ),
280+ pytest .param (True , id = "metadata_bool" ),
281+ pytest .param ([1 , 2 ], id = "metadata_list" ),
282+ pytest .param ((1 , 2 ), id = "metadata_tuple" ),
283+ ],
284+ )
285+ def test_invalid_metadata (self , metadata ):
286+ with pytest .raises (ValueError , match = "Can only convert dict or Instance" ):
287+ ValidChunk (start_offset = 0 , end_offset = 100 , metadata = metadata )
0 commit comments