class FileIO(): def __init__(self, file_path): self.__readable_file = File(file_path) self.__writeable_file = File(file_path) def read_number_of_lines(self, counter): if not self.__readable_file.is_opened(): if not self.__readable_file.wait_for_creation(): raise Exception("{} was not created in time.".format( self.__readable_file.path)) self.__readable_file.open("r") return self.__readable_file.wait_for_number_of_lines(counter) def read_until_lines(self, lines): if not self.__readable_file.is_opened(): if not self.__readable_file.wait_for_creation(): raise Exception("{} was not created in time.".format( self.__readable_file.path)) self.__readable_file.open("r") return self.__readable_file.wait_for_lines(lines) def write(self, content): if not self.__writeable_file.is_opened(): self.__writeable_file.open("a+") self.__writeable_file.write(content)
def write(self, content, rate=None): loggen_input_file_path = Path(tc_parameters.WORKING_DIR, "loggen_input_{}.txt".format(get_unique_id())) loggen_input_file = File(loggen_input_file_path) loggen_input_file.open(mode="w") loggen_input_file.write(content) loggen_input_file.close() Loggen().start(self.__ip, self.__port, read_file=str(loggen_input_file_path), dont_parse=True, permanent=True, rate=rate, **self.__transport.value)
def test_pp_tls_passthrough(config, syslog_ng, port_allocator, loggen, testcase_parameters): server_key_path = copy_shared_file(testcase_parameters, "server.key") server_cert_path = copy_shared_file(testcase_parameters, "server.crt") network_source = config.create_network_source( ip="localhost", port=port_allocator(), transport='"proxied-tls-passthrough"', flags="no-parse", tls={ "key-file": server_key_path, "cert-file": server_cert_path, "peer-verify": '"optional-untrusted"', }, ) file_destination = config.create_file_destination(file_name="output.log", template=TEMPLATE) config.create_logpath(statements=[network_source, file_destination]) syslog_ng.start(config) loggen_input_file_path = Path( tc_parameters.WORKING_DIR, "loggen_input_{}.txt".format(get_unique_id())) loggen_input_file = File(loggen_input_file_path) loggen_input_file.open(mode="w") loggen_input_file.write(INPUT_MESSAGES) loggen_input_file.close() loggen.start( network_source.options["ip"], network_source.options["port"], number=NUMBER_OF_MESSAGES, use_ssl=True, proxied_tls_passthrough=True, read_file=str(loggen_input_file_path), dont_parse=True, proxy_src_ip="1.1.1.1", proxy_dst_ip="2.2.2.2", proxy_src_port="3333", proxy_dst_port="4444", ) wait_until_true( lambda: loggen.get_sent_message_count() == NUMBER_OF_MESSAGES) assert file_destination.read_log() == EXPECTED_MESSAGES