def test_6_logger_mode(self): logger_path = test_base.getTestDirectory(test_base.CONFIG_DIR) test_mode = 0754 # Strange mode that should never exist daemon = self._run_daemon({ "disable_watchdog": True, "disable_extensions": True, "disable_logging": False, }, options_only={ "logger_path": logger_path, "logger_mode": test_mode, "verbose": True, }) info_path = os.path.join(logger_path, "osqueryd.INFO") self.assertTrue(daemon.isAlive()) def info_exists(): return os.path.exists(info_path) # Wait for the daemon to flush to GLOG. test_base.expectTrue(info_exists) # Both log files should exist, the results should have the given mode. for fname in ['osqueryd.INFO', 'osqueryd.results.log']: pth = os.path.join(logger_path, fname) self.assertTrue(os.path.exists(pth)) # Only apply the mode checks to .log files. if fname.find('.log') > 0: rpath = os.path.realpath(pth) mode = os.stat(rpath).st_mode & 0777 self.assertEqual(mode, test_mode) daemon.kill()
def test_2_daemon_with_option(self): logger_path = test_base.getTestDirectory(test_base.CONFIG_DIR) daemon = self._run_daemon( { "disable_watchdog": True, "disable_extensions": True, "disable_logging": False, }, options_only={ "logger_path": logger_path, "verbose": True, }) self.assertTrue(daemon.isAlive()) def info_exists(): info_path = test_base.getLatestInfoLog(logger_path) return os.path.exists(info_path) # Wait for the daemon to flush to GLOG. test_base.expectTrue(info_exists) # Assign the variable after we have assurances it exists info_path = test_base.getLatestInfoLog(logger_path) self.assertTrue(os.path.exists(info_path)) # Lastly, verify that we have permission to read the file data = '' with open(info_path, 'r') as fh: try: data = fh.read() except: pass self.assertTrue(len(data) > 0) daemon.kill()
def test_2_daemon_with_option(self): logger_path = test_base.getTestDirectory(test_base.TEMP_DIR) daemon = self._run_daemon( { "disable_watchdog": True, "disable_extensions": True, "disable_logging": False, }, options_only={ "logger_path": logger_path, "verbose": True, }) self.assertTrue(daemon.isAlive()) info_path = os.path.join(logger_path, "osqueryd.INFO*") def info_exists(): return len(glob.glob(info_path)) > 0 # Wait for the daemon to flush to GLOG. test_base.expectTrue(info_exists) # Assign the variable after we have assurances it exists self.assertTrue(info_exists()) # Lastly, verify that we have permission to read the file data = '' with open(glob.glob(info_path)[0], 'r') as fh: try: data = fh.read() except: pass self.assertTrue(len(data) > 0) daemon.kill()
def test_6_logger_mode(self): logger_path = test_base.getTestDirectory(test_base.CONFIG_DIR) test_mode = 0754 # Strange mode that should never exist daemon = self._run_daemon( { "disable_watchdog": True, "disable_extensions": True, "disable_logging": False, }, options_only={ "logger_path": logger_path, "logger_mode": test_mode, "verbose": True, }) info_path = os.path.join(logger_path, "osqueryd.INFO") self.assertTrue(daemon.isAlive()) def info_exists(): return os.path.exists(info_path) # Wait for the daemon to flush to GLOG. test_base.expectTrue(info_exists) # Both log files should exist, the results should have the given mode. for fname in ['osqueryd.INFO', 'osqueryd.results.log']: pth = os.path.join(logger_path, fname) self.assertTrue(os.path.exists(pth)) # Only apply the mode checks to .log files. if fname.find('.log') > 0: rpath = os.path.realpath(pth) mode = os.stat(rpath).st_mode & 0777 self.assertEqual(mode, test_mode) daemon.kill()
def test_logger_mode(self): logger_path = test_base.getTestDirectory(test_base.TEMP_DIR) test_mode = "0754" # Strange mode that should never exist daemon = self._run_daemon( { "disable_watchdog": True, "disable_extensions": True, "disable_logging": False, "logger_mode": test_mode, }, options_only={ "logger_path": logger_path, "verbose": True, }, ) self.assertTrue(daemon.isAlive()) # Wait for the daemon to write the info log to disk before continuing info_path = os.path.join(logger_path, "osqueryd.INFO*") def info_exists(): return len(glob.glob(info_path)) > 0 results_path = os.path.join(logger_path, "osqueryd.results.log") def results_exists(): return os.path.exists(results_path) # Wait for the daemon to flush to GLOG. test_base.expectTrue(info_exists) test_base.expectTrue(results_exists) info_path = glob.glob(info_path)[0] # Both log files should exist, the results should have the given mode. for pth in [info_path, results_path]: self.assertTrue(os.path.exists(pth)) # Only apply the mode checks to .log files. # TODO: Add ACL checks for Windows logs if pth.find('.log') > 0 and os.name != "nt": rpath = os.path.realpath(pth) mode = os.stat(rpath).st_mode & 0o777 # NOTE: We are converting test_mode in this way because # the python integer to octal string conversion # uses a format ("0o754") that's not supported by C++ self.assertEqual(mode, int(test_mode, 8)) daemon.kill()
def test_6_logger_mode(self): logger_path = test_base.getTestDirectory(test_base.CONFIG_DIR) test_mode = 0o754 # Strange mode that should never exist daemon = self._run_daemon( { "disable_watchdog": True, "disable_extensions": True, "disable_logging": False, }, options_only={ "logger_path": logger_path, "logger_mode": test_mode, "verbose": True, }) self.assertTrue(daemon.isAlive()) # Wait for the daemon to write the info log to disk before continuing info_path = os.path.join(logger_path, "osqueryd.INFO*") def info_exists(): return len(glob.glob(info_path)) > 0 results_path = os.path.join(logger_path, "osqueryd.results.log") def results_exists(): return os.path.exists(results_path) # Wait for the daemon to flush to GLOG. test_base.expectTrue(info_exists) test_base.expectTrue(results_exists) info_path = glob.glob(info_path)[0] # Both log files should exist, the results should have the given mode. for pth in [info_path, results_path]: self.assertTrue(os.path.exists(pth)) # Only apply the mode checks to .log files. # TODO: Add ACL checks for Windows logs if pth.find('.log') > 0 and os.name != "nt": rpath = os.path.realpath(pth) mode = os.stat(rpath).st_mode & 0o777 self.assertEqual(mode, test_mode) daemon.kill()
def test_6_logger_mode(self): logger_path = test_base.getTestDirectory(test_base.CONFIG_DIR) test_mode = 0754 # Strange mode that should never exist daemon = self._run_daemon( { "disable_watchdog": True, "disable_extensions": True, "disable_logging": False, }, options_only={ "logger_path": logger_path, "logger_mode": test_mode, "verbose": True, }) results_path = os.path.join(logger_path, "osqueryd.results.log") self.assertTrue(daemon.isAlive()) # Wait for the daemon to write the info log to disk before continuing def info_exists(): info_path = test_base.getLatestInfoLog(logger_path) return os.path.exists(info_path) info_path = test_base.getLatestInfoLog(logger_path) def results_exists(): return os.path.exists(results_path) # Wait for the daemon to flush to GLOG. test_base.expectTrue(info_exists) test_base.expectTrue(results_exists) # Both log files should exist, the results should have the given mode. for pth in [info_path, results_path]: self.assertTrue(os.path.exists(pth)) # Only apply the mode checks to .log files. # TODO: Add ACL checks for Windows logs if pth.find('.log') > 0 and os.name != "nt": rpath = os.path.realpath(pth) mode = os.stat(rpath).st_mode & 0777 self.assertEqual(mode, test_mode) daemon.kill()
def test_7_logger_stdout(self): logger_path = test_base.getTestDirectory(test_base.CONFIG_DIR) daemon = self._run_daemon({ "disable_watchdog": True, "disable_extensions": True, "disable_logging": False, "logger_plugin": "stdout", "logger_path": logger_path, "verbose": True, }) info_path = os.path.join(logger_path, "osqueryd.INFO") def pathDoesntExist(): if os.path.exists(info_path): return False return True self.assertTrue(daemon.isAlive()) self.assertTrue(pathDoesntExist()) daemon.kill()
def test_2_daemon_with_option(self): logger_path = test_base.getTestDirectory(test_base.CONFIG_DIR) daemon = self._run_daemon({ "disable_watchdog": True, "disable_extensions": True, "disable_logging": False, }, options_only={ "logger_path": logger_path, "verbose": True, }) info_path = os.path.join(logger_path, "osqueryd.INFO") self.assertTrue(daemon.isAlive()) def info_exists(): return os.path.exists(info_path) # Wait for the daemon to flush to GLOG. test_base.expectTrue(info_exists) self.assertTrue(os.path.exists(info_path)) daemon.kill()