#NEWLINE# def testHashFile( self ) : #NEWLINE# #INDENT# 'Can we hash a file?' #NEWLINE# path = os . path . join ( self . base_path , 'numbers.txt' ) #NEWLINE# p = rdf_paths . PathSpec ( path = path , pathtype = rdf_paths . PathSpec . PathType . OS ) #NEWLINE# result = self . RunAction ( 'FingerprintFile' , rdf_client . FingerprintRequest ( pathspec = p ) ) #NEWLINE# types = result [ 0 ] . matching_types #NEWLINE# fingers = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for f in result [ 0 ] . results : #NEWLINE# #INDENT# fingers [ f [ 'name' ] ] = f #NEWLINE# #UNINDENT# generic_sha256 = fingers [ 'generic' ] [ 'sha256' ] #NEWLINE# self . assertEqual ( generic_sha256 , hashlib . sha256 ( open ( path ) . read ( ) ) . digest ( ) ) #NEWLINE# t_map = { #NEWLINE# #INDENT# rdf_client . FingerprintTuple . Type . FPT_GENERIC : 'generic' , #NEWLINE# rdf_client . FingerprintTuple . Type . FPT_PE_COFF : 'pecoff' , #NEWLINE# #UNINDENT# } #NEWLINE# ti_map = dict ( ( ( v , k ) for ( k , v ) in t_map . iteritems ( ) ) ) #NEWLINE# for t in types : #NEWLINE# #INDENT# self . assertTrue ( ( t_map [ t ] in fingers ) ) #NEWLINE# #UNINDENT# for f in fingers : #NEWLINE# #INDENT# self . assertTrue ( ( ti_map [ f ] in types ) ) #NEWLINE# #UNINDENT# self . assertEqual ( result [ 0 ] . pathspec . path , path )