<s> """<STR_LIT>""" <EOL> from grr . lib import aff4 <EOL> from grr . lib import flags <EOL> from grr . lib import test_lib <EOL> from grr . lib . flows . general import network <EOL> from grr . lib . rdfvalues import client as rdf_client <EOL> class NetstatTest ( test_lib . FlowTestsBaseclass ) : <EOL> """<STR_LIT>""" <EOL> def testNetstat ( self ) : <EOL> """<STR_LIT>""" <EOL> class ClientMock ( object ) : <EOL> def Netstat ( self , _ ) : <EOL> """<STR_LIT>""" <EOL> conn1 = rdf_client . NetworkConnection ( <EOL> state = rdf_client . NetworkConnection . State . LISTEN , <EOL> type = rdf_client . NetworkConnection . Type . SOCK_STREAM , <EOL> local_address = rdf_client . NetworkEndpoint ( <EOL> ip = "<STR_LIT>" , <EOL> port = <NUM_LIT> ) , <EOL> remote_address = rdf_client . NetworkEndpoint ( <EOL> ip = "<STR_LIT>" , <EOL> port = <NUM_LIT:0> ) , <EOL> pid = <NUM_LIT> , <EOL> ctime = <NUM_LIT:0> ) <EOL> conn2 = rdf_client . NetworkConnection ( <EOL> state = rdf_client . NetworkConnection . State . LISTEN , <EOL> type = rdf_client . NetworkConnection . Type . SOCK_STREAM , <EOL> local_address = rdf_client . NetworkEndpoint ( <EOL> ip = "<STR_LIT>" , <EOL> port = <NUM_LIT> ) , <EOL> remote_address = rdf_client . NetworkEndpoint ( <EOL> ip = "<STR_LIT>" , <EOL> port = <NUM_LIT> ) , <EOL> pid = <NUM_LIT:1> , <EOL> ctime = <NUM_LIT:0> ) <EOL> return [ conn1 , conn2 ] <EOL> fd = aff4 . FACTORY . Create ( self . client_id , "<STR_LIT>" , <EOL> token = self . token ) <EOL> fd . Set ( fd . Schema . SYSTEM ( "<STR_LIT>" ) ) <EOL> fd . Close ( ) <EOL> for _ in test_lib . TestFlowHelper ( <EOL> "<STR_LIT>" , ClientMock ( ) , client_id = self . client_id , token = self . token ) : <EOL> pass <EOL> fd = aff4 . FACTORY . Open ( self . client_id . Add ( "<STR_LIT>" ) , token = self . token ) <EOL> conns = fd . Get ( fd . Schema . CONNECTIONS ) <EOL> self . assertEqual ( len ( conns ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( conns [ <NUM_LIT:0> ] . local_address . ip , "<STR_LIT>" ) <EOL> self . assertEqual ( conns [ <NUM_LIT:0> ] . local_address . port , <NUM_LIT> ) <EOL> self . assertEqual ( conns [ <NUM_LIT:1> ] . local_address . ip , "<STR_LIT>" ) <EOL> self . assertEqual ( conns [ <NUM_LIT:1> ] . pid , <NUM_LIT:1> ) <EOL> self . assertEqual ( conns [ <NUM_LIT:1> ] . remote_address . port , <NUM_LIT> ) <EOL> def main ( argv ) : <EOL> test_lib . GrrTestProgram ( argv = argv ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> flags . StartMain ( main ) </s>
