def _main_test_init(self, args, hammer): # allocate port port = get_next_listener_port() # collect classes of observed audit results self.actual_results = [] def main__handle_result(res): #self.orig_main__handle_result(res) if isinstance(res, ConnectionAuditResult): self.actual_results.append(ACCAR(res)) else: pass # ignore other events # create options for the controller main_args = ['-l', '%s:%d' % (TEST_LISTENER_ADDR, port)] main_args.extend(args) options = SSLCAuditUI.parse_options(main_args) # create file_bag and controller file_bag = FileBag(basename='test-sslcaudit', use_tempdir=True) self.controller = BaseClientAuditController(options, file_bag, event_handler=main__handle_result) self.hammer = hammer if self.hammer is not None: self.hammer.set_peer((TEST_LISTENER_ADDR, port))
class TestFileBag(unittest.TestCase): def setUp(self): self.file_bag = FileBag('testfilebag', use_tempdir=True) def test__mk_file(self): f = self.file_bag.mk_file(suffix='.bar', prefix='foo') f.write('blah') f.close() def test__mk_file2(self): (f1, f2) = self.file_bag.mk_two_files(suffix1='.bar1', suffix2='.bar2', prefix='foo') f1.write('blah1') f1.close() f2.write('blah2') f2.close()
def test_dummy(self): ''' This test establishes a bunch of plain TCP connections against dummy auditor. The dummy auditor just acknowledges the fact of connection happening. ''' # these variables will be updated from a hook function invoked from main self.got_result_starts = 0 self.got_conn_results = 0 self.got_result_ends = 0 self.nstray = 0 # the hook function def main__handle_result(res): ''' This function overrides main.handle_result() and updates our counters ''' if isinstance(res, SessionStartEvent): self.got_result_starts = self.got_result_starts + 1 elif isinstance(res, SessionEndResult): self.got_result_ends = self.got_result_ends + 1 elif isinstance(res, ConnectionAuditResult): self.got_conn_results = self.got_conn_results + 1 else: self.nstray = self.nstray + 1 # allocate port port = get_next_listener_port() # create a client hammering our test listener self.hammer = TCPConnectionHammer(self.HAMMER_ATTEMPTS) # create main, the target of the test main_args = [ '-m', 'dummy', '-l', ("%s:%d" % (TEST_LISTENER_ADDR, port)) ] options = SSLCAuditUI.parse_options(main_args) file_bag = FileBag(basename='test-sslcaudit', use_tempdir=True) controller = BaseClientAuditController( options, file_bag, event_handler=main__handle_result) # tell the hammer how many attempts to make exactly self.hammer.set_peer((TEST_LISTENER_ADDR, port)) # start server and client controller.start() self.hammer.start() controller.join(timeout=5) self.hammer.stop() # make sure we have received expected number of results self.assertEquals(self.got_result_starts, 1) self.assertEquals(self.got_conn_results, 2) self.assertEquals(self.got_result_ends, 1) self.assertEquals(self.nstray, 0)
def setUp(self): self.file_bag = FileBag('testfilebag', use_tempdir=True)
def setUp(self): self.file_bag = FileBag('testcertfactory', use_tempdir=True) self.cert_factory = CertFactory(self.file_bag)