<s> """<STR_LIT>""" <EOL> import urllib2 <EOL> import zlib <EOL> from rekall import constants <EOL> from grr . lib import aff4 <EOL> from grr . lib import config_lib <EOL> from grr . lib import flags <EOL> from grr . lib import rdfvalue <EOL> from grr . lib import rekall_profile_server <EOL> from grr . lib import test_lib <EOL> from grr . lib import utils <EOL> class FakeHandle ( object ) : <EOL> read_count = <NUM_LIT:0> <EOL> def __init__ ( self , url ) : <EOL> profile = url . split ( constants . PROFILE_REPOSITORY_VERSION + "<STR_LIT:/>" ) [ <NUM_LIT:1> ] <EOL> profile = profile . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> self . profile = profile <EOL> def read ( self ) : <EOL> FakeHandle . read_count += <NUM_LIT:1> <EOL> profile_name = self . profile <EOL> server = test_lib . TestRekallRepositoryProfileServer ( ) <EOL> profile = server . GetProfileByName ( <EOL> profile_name , <EOL> version = constants . PROFILE_REPOSITORY_VERSION ) <EOL> return profile . data <EOL> def FakeOpen ( url , timeout = None ) : <EOL> _ = timeout <EOL> return FakeHandle ( url ) <EOL> class ProfileServerTest ( test_lib . GRRBaseTest ) : <EOL> def setUp ( self ) : <EOL> self . server = rekall_profile_server . GRRRekallProfileServer ( ) <EOL> super ( ProfileServerTest , self ) . setUp ( ) <EOL> def testProfileFetching ( self ) : <EOL> profile_name = "<STR_LIT>" <EOL> FakeHandle . read_count = <NUM_LIT:0> <EOL> with utils . Stubber ( urllib2 , "<STR_LIT>" , FakeOpen ) : <EOL> profile = self . server . GetProfileByName ( <EOL> profile_name , <EOL> version = constants . PROFILE_REPOSITORY_VERSION ) <EOL> uncompressed = zlib . decompress ( profile . data , <NUM_LIT:16> + zlib . MAX_WBITS ) <EOL> self . assertTrue ( "<STR_LIT>" in uncompressed ) <EOL> self . assertEqual ( FakeHandle . read_count , <NUM_LIT:1> ) <EOL> with utils . Stubber ( urllib2 , "<STR_LIT>" , FakeOpen ) : <EOL> profile = self . server . GetProfileByName ( <EOL> profile_name , version = constants . PROFILE_REPOSITORY_VERSION ) <EOL> self . assertEqual ( FakeHandle . read_count , <NUM_LIT:1> ) <EOL> def testGzExtension ( self ) : <EOL> with utils . Stubber ( urllib2 , "<STR_LIT>" , FakeOpen ) : <EOL> profile = self . server . GetProfileByName ( "<STR_LIT>" ) <EOL> zlib . decompress ( profile . data , <NUM_LIT:16> + zlib . MAX_WBITS ) <EOL> self . assertEqual ( FakeHandle . read_count , <NUM_LIT:1> ) <EOL> self . server . GetProfileByName ( "<STR_LIT>" ) <EOL> self . assertEqual ( FakeHandle . read_count , <NUM_LIT:1> ) <EOL> self . server . GetProfileByName ( "<STR_LIT>" ) <EOL> self . assertEqual ( FakeHandle . read_count , <NUM_LIT:1> ) <EOL> cache_urn = rdfvalue . RDFURN ( config_lib . CONFIG [ "<STR_LIT>" ] ) <EOL> cached_items = list ( aff4 . FACTORY . Open ( <EOL> cache_urn . Add ( constants . PROFILE_REPOSITORY_VERSION ) , <EOL> token = self . token ) . ListChildren ( ) ) <EOL> self . assertEqual ( len ( cached_items ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( cached_items [ <NUM_LIT:0> ] . Basename ( ) , "<STR_LIT>" ) <EOL> def main ( args ) : <EOL> test_lib . main ( args ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> flags . StartMain ( main ) </s>
