1#!/usr/bin/env python 2############################################################################# 3# Copyright (c) 2007-2015 Balabit 4# 5# This program is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License version 2 as published 7# by the Free Software Foundation, or (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program; if not, write to the Free Software 16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17# 18# As an additional exemption you are allowed to compile & link against the 19# OpenSSL libraries as published by the OpenSSL project. See the file 20# COPYING for details. 21# 22############################################################################# 23 24import os, errno 25 26#internal modules 27from log import * 28from messagegen import * 29from control import * 30from globals import * 31import messagegen 32 33 34 35def init_env(): 36 for pipe in ('log-pipe', 'log-padded-pipe'): 37 try: 38 os.unlink(pipe) 39 except OSError: 40 pass 41 os.mkfifo(pipe) 42 try: 43 os.mkdir("wildcard") 44 except OSError as e: 45 if e.errno != errno.EEXIST: 46 raise 47 48def get_seed_input(): 49 raw_input = """k/zFvqjGWdhStmhfOeTNtTs89P8soknF1J9kSQrz8hKdrjIutqTXMfIqCNUb7DXrMykMW+wKd1Pg 50DwaUwxKmlaU1ItOek+jNUWVw9ZOSI1EmsXVgu+Hu7URgmeyY0A3WsDmMzR0Z2wTcRFSuINgBP8LC 518SG27gJZVOoVv09pfY9WyjvUYwg1jBdTfEM+qcDQKOACx4DH+SzO0bOOJMfMbR2iFaq18b/TCeQN 52kRy9Lz2WvBsByQoXw/afxiu5xzn0MHoxTMCZCTjIyhGXzO/R2yj3eBVc5vxc5oxG3/EdjGnhmn/L 53HEFVgc6EJ5OF1ye8hDIHFdZFehCAPbso3LL/3r8oJn+Axmc2sOrvhzMLpCV2KWdy8haiv3WZ9hZP 54iJkC0pGBR+vhrdYE7qh2RzcdYoHRCvX5tpaOG+SE8+Az2WPHPOD7j4j+4KbhW+YbzYfUAsmwOQb4 55R3vIyGO6Og4fg+AmKcycpv9Bo17zidbQe9zdZO6X4Df+ychK+yRSCMHLUyrEry7IFt60ivLAjc8b 56Ladp70v7icWO+J9P/3pXIzKuQuaeT7J1q2xlCc/srV2pNV4+EhKJ8qSe+hG4LzpXWRGKo72h6BvL 57Wgcp3S/wy1e6ov8XsVKjkWeQH8Nh3xOMWGYh6/yXSN44BLIBUdqk4I3TCKy1DawJQd1ivytEF0Xh 58BstGzSoyeR92mN/K5/gy9wKFZffTbE7DmysKflRAN85ht7IVqxrTNXQ+UPWvlGZDAQ0NY45rQI3K 59S1q0ahQivgGUZmEhuZkAUlYGWAqtCeDz3rZvrp5r2WJFGTZ+9yJZC5T2L+erDGBYxmcwxDzz8AvS 60Ybp4aIBEtTK71cx9DtFTtSaQ6aW9rI5nc/owo0gv4Ddm5BYjMAd7kcc9TWnb1DZ9AJQAnSxgcuJM 61acbYkFcqtMnafh/VnGekZ8yM0ZZqQPKBhysx+u2UBXib7Vvb6x6Y/xglNcqBWGFmzruKt6hx0pR2 62x9IunzeIwdlcwIhLEKfIiy9ULwi7RTjVSeqgwucWoC0lw0BTotGeLDcFxTlQsE3T/UneLa8H6iSH 63VW5iRZrvI0sdxt5Ud0TjNqXRGxuVczSuwpQwwxBn0ogr9DoRnp375PwGGh1/yqimW/+OStwP3cRR 64yXEg6Zq1CvuYF/E6el4h9GylxkU7wEM2Ti9QJY4n3YsHyesalERqdd9xx5t7ADRodpMpZXoZGbrS 65vccp3zMzS/aEZRuxky1/qjrAEh8OVA58e82jQqTdY8OQ/kKOu/gUgKBnHAvLkB/020p0CNbq6HjY 66l625DLckaYmOPTh0ECFKzhaPF+/LNmzD36ToOAeuNjfbUjiUVGfntr2mc4E8mUFyo+TskrkSfw== 67""".encode() 68 69 import sys 70 import base64 71 if sys.version_info.major == 2: 72 return base64.decodestring(raw_input) 73 else: 74 return base64.decodebytes(raw_input) 75 76 77def seed_rnd(): 78 # Some platforms lack kernel supported random numbers, on those we have to explicitly seed the RNG. 79 # using a fixed RND input does not matter as we are not protecting real data in this test program. 80 try: 81 import socket 82 import ssl 83 rnd = get_seed_input() 84 ssl.RAND_add(rnd, 1024) 85 if not ssl.RAND_status(): 86 raise "PRNG not seeded" 87 except ImportError: 88 return 89 90def run_testcase(test_name, config, verbose, test_case): 91 print_start(test_name) 92 93 if not start_syslogng(config, verbose): 94 sys.exit(1) 95 96 print_user("Starting test case...") 97 success = test_case() 98 if not stop_syslogng(): 99 sys.exit(1) 100 print_end(test_name, success) 101 return success 102 103# import test modules 104import test_file_source 105import test_filters 106import test_input_drivers 107import test_performance 108import test_sql 109import test_python 110import test_map_value_pairs 111 112tests = (test_input_drivers, test_sql, test_file_source, test_filters, test_performance, test_python, test_map_value_pairs) 113failed_tests = [] 114 115init_env() 116seed_rnd() 117 118 119verbose = False 120if len(sys.argv) > 1: 121 verbose = True 122try: 123 for test_module in tests: 124 if hasattr(test_module, "check_env") and not test_module.check_env(): 125 continue 126 127 128 contents = dir(test_module) 129 contents.sort() 130 for obj in contents: 131 if obj[:5] != 'test_': 132 continue 133 test_case = getattr(test_module, obj) 134 135 if type(test_module.config) is str: 136 test_case_name = test_module.__name__ + '.' + obj 137 if not run_testcase(test_case_name, test_module.config, verbose, test_case): 138 failed_tests.append(test_case_name) 139 140 elif type(test_module.config) is dict: 141 for config_name in test_module.config: 142 testcase_name = "%s.%s[%s]" %(test_module.__name__, obj, config_name) 143 config = test_module.config[config_name] 144 if not run_testcase(testcase_name, config, verbose, test_case): 145 failed_tests.append(testcase_name) 146 147finally: 148 stop_syslogng() 149 150if len(failed_tests)>0: 151 print("List of failed test cases: %s" % ','.join(failed_tests)) 152 sys.exit(1) 153 154sys.exit(0) 155