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 ,
@@ -153,56 +161,57 @@ def test_process_result_conversion(self):
153161 decoded_report = json .loads (json_text )
154162 assert decoded_report == [
155163 {
156- "__typename__" : "TaskResult" ,
164+ "task" : {
165+ "path" : "/nonexistent" ,
166+ "depth" : 0 ,
167+ "blob_id" : "" ,
168+ "is_multi_file" : False ,
169+ "__typename__" : "Task" ,
170+ },
157171 "reports" : [
158172 {
159- "__typename__" : "StatReport" ,
173+ "path" : "/nonexistent" ,
174+ "size" : 384 ,
160175 "is_dir" : False ,
161176 "is_file" : True ,
162177 "is_link" : False ,
163178 "link_target" : None ,
164- "path" : "/nonexistent" ,
165- "size" : 384 ,
179+ "__typename__" : "StatReport" ,
166180 },
167181 {
168- "__typename__" : "FileMagicReport" ,
169182 "magic" : "Zip archive data, at least v2.0 to extract" ,
170183 "mime_type" : "application/zip" ,
184+ "__typename__" : "FileMagicReport" ,
171185 },
172186 {
173- "__typename__" : "HashReport" ,
174187 "md5" : "9019fcece2433ad7f12c077e84537a74" ,
175188 "sha1" : "36998218d8f43b69ef3adcadf2e8979e81eed166" ,
176189 "sha256" : "7d7ca7e1410b702b0f85d18257aebb964ac34f7fad0a0328d72e765bfcb21118" ,
190+ "__typename__" : "HashReport" ,
177191 },
178192 {
179- "__typename__" : "ChunkReport" ,
180- "end_offset" : 384 ,
181- "extraction_reports" : [],
182- "handler_name" : "zip" ,
183193 "id" : "test_basic_conversion:id" ,
184- "is_encrypted" : False ,
185- "size" : 384 ,
194+ "handler_name" : "zip" ,
186195 "start_offset" : 0 ,
196+ "end_offset" : 384 ,
197+ "size" : 384 ,
198+ "is_encrypted" : False ,
199+ "metadata" : {},
200+ "extraction_reports" : [],
201+ "__typename__" : "ChunkReport" ,
187202 },
188203 ],
189204 "subtasks" : [
190205 {
191- "__typename__" : "Task" ,
192- "blob_id" : "test_basic_conversion:id" ,
206+ "path" : "/extractions/nonexistent_extract" ,
193207 "depth" : 314 ,
208+ "blob_id" : "test_basic_conversion:id" ,
194209 "is_multi_file" : False ,
195- "path " : "/extractions/nonexistent_extract " ,
210+ "__typename__ " : "Task " ,
196211 }
197212 ],
198- "task" : {
199- "__typename__" : "Task" ,
200- "blob_id" : "" ,
201- "depth" : 0 ,
202- "is_multi_file" : False ,
203- "path" : "/nonexistent" ,
204- },
205- },
213+ "__typename__" : "TaskResult" ,
214+ }
206215 ]
207216
208217 def test_exotic_command_output (self ):
@@ -218,35 +227,44 @@ def test_exotic_command_output(self):
218227 decoded_report = json .loads (json_text )
219228
220229 assert decoded_report == {
221- "__typename__" : "ExtractCommandFailedReport" ,
222- "command" : "dump all bytes" ,
223- "exit_code" : 1 ,
224230 "severity" : "WARNING" ,
231+ "command" : "dump all bytes" ,
232+ "stdout" : "\x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 "
233+ "\t \n \x0b \x0c \r \x0e \x0f \x10 \x11 \x12 \x13 \x14 \x15 \x16 "
234+ "\x17 \x18 \x19 \x1a \x1b \x1c \x1d \x1e \x1f !\" #$%&'()*+,"
235+ "-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\ ]"
236+ "^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f \udc80 \udc81 "
237+ "\udc82 \udc83 \udc84 \udc85 \udc86 \udc87 \udc88 \udc89 "
238+ "\udc8a \udc8b \udc8c \udc8d \udc8e \udc8f \udc90 \udc91 "
239+ "\udc92 \udc93 \udc94 \udc95 \udc96 \udc97 \udc98 \udc99 "
240+ "\udc9a \udc9b \udc9c \udc9d \udc9e \udc9f \udca0 \udca1 "
241+ "\udca2 \udca3 \udca4 \udca5 \udca6 \udca7 \udca8 \udca9 "
242+ "\udcaa \udcab \udcac \udcad \udcae \udcaf \udcb0 \udcb1 "
243+ "\udcb2 \udcb3 \udcb4 \udcb5 \udcb6 \udcb7 \udcb8 \udcb9 "
244+ "\udcba \udcbb \udcbc \udcbd \udcbe \udcbf \udcc0 \udcc1 "
245+ "\udcc2 \udcc3 \udcc4 \udcc5 \udcc6 \udcc7 \udcc8 \udcc9 "
246+ "\udcca \udccb \udccc \udccd \udcce \udccf \udcd0 \udcd1 "
247+ "\udcd2 \udcd3 \udcd4 \udcd5 \udcd6 \udcd7 \udcd8 \udcd9 "
248+ "\udcda \udcdb \udcdc \udcdd \udcde \udcdf \udce0 \udce1 "
249+ "\udce2 \udce3 \udce4 \udce5 \udce6 \udce7 \udce8 \udce9 "
250+ "\udcea \udceb \udcec \udced \udcee \udcef \udcf0 \udcf1 "
251+ "\udcf2 \udcf3 \udcf4 \udcf5 \udcf6 \udcf7 \udcf8 \udcf9 "
252+ "\udcfa \udcfb \udcfc \udcfd \udcfe \udcff " ,
225253 "stderr" : "stdout is pretty strange ;)" ,
226- "stdout" : (
227- "b'\\ x00\\ x01\\ x02\\ x03\\ x04\\ x05\\ x06\\ x07"
228- "\\ x08\\ t\\ n\\ x0b\\ x0c\\ r\\ x0e\\ x0f"
229- "\\ x10\\ x11\\ x12\\ x13\\ x14\\ x15\\ x16\\ x17"
230- '\\ x18\\ x19\\ x1a\\ x1b\\ x1c\\ x1d\\ x1e\\ x1f !"#'
231- "$%&\\ '()*+,-./0123456789:;<=>?@AB"
232- "CDEFGHIJKLMNOPQRSTUVWXYZ[\\ \\ ]^_`a"
233- "bcdefghijklmnopqrstuvwxyz{|}~\\ x7f"
234- "\\ x80\\ x81\\ x82\\ x83\\ x84\\ x85\\ x86\\ x87"
235- "\\ x88\\ x89\\ x8a\\ x8b\\ x8c\\ x8d\\ x8e\\ x8f"
236- "\\ x90\\ x91\\ x92\\ x93\\ x94\\ x95\\ x96\\ x97"
237- "\\ x98\\ x99\\ x9a\\ x9b\\ x9c\\ x9d\\ x9e\\ x9f"
238- "\\ xa0\\ xa1\\ xa2\\ xa3\\ xa4\\ xa5\\ xa6\\ xa7"
239- "\\ xa8\\ xa9\\ xaa\\ xab\\ xac\\ xad\\ xae\\ xaf"
240- "\\ xb0\\ xb1\\ xb2\\ xb3\\ xb4\\ xb5\\ xb6\\ xb7"
241- "\\ xb8\\ xb9\\ xba\\ xbb\\ xbc\\ xbd\\ xbe\\ xbf"
242- "\\ xc0\\ xc1\\ xc2\\ xc3\\ xc4\\ xc5\\ xc6\\ xc7"
243- "\\ xc8\\ xc9\\ xca\\ xcb\\ xcc\\ xcd\\ xce\\ xcf"
244- "\\ xd0\\ xd1\\ xd2\\ xd3\\ xd4\\ xd5\\ xd6\\ xd7"
245- "\\ xd8\\ xd9\\ xda\\ xdb\\ xdc\\ xdd\\ xde\\ xdf"
246- "\\ xe0\\ xe1\\ xe2\\ xe3\\ xe4\\ xe5\\ xe6\\ xe7"
247- "\\ xe8\\ xe9\\ xea\\ xeb\\ xec\\ xed\\ xee\\ xef"
248- "\\ xf0\\ xf1\\ xf2\\ xf3\\ xf4\\ xf5\\ xf6\\ xf7"
249- "\\ xf8\\ xf9\\ xfa\\ xfb\\ xfc\\ xfd\\ xfe\\ xff"
250- "'"
251- ),
254+ "exit_code" : 1 ,
255+ "__typename__" : "ExtractCommandFailedReport" ,
252256 }
257+
258+ @pytest .mark .parametrize (
259+ "metadata" ,
260+ [
261+ pytest .param (1 , id = "metadata_int" ),
262+ pytest .param (0.2 , id = "metadata_float" ),
263+ pytest .param (True , id = "metadata_bool" ),
264+ pytest .param ([1 , 2 ], id = "metadata_list" ),
265+ pytest .param ((1 , 2 ), id = "metadata_tuple" ),
266+ ],
267+ )
268+ def test_invalid_metadata (self , metadata ):
269+ with pytest .raises (ValueError , match = "Can only convert dict or Instance" ):
270+ ValidChunk (start_offset = 0 , end_offset = 100 , metadata = metadata )
0 commit comments