def GetSSHDConfig(): if SSHD_CFG: return SSHD_CFG # Load an sshd config parser = config_file_parsers.SshdConfigParser() test_data = os.path.join(config.CONFIG["Test.data_dir"], "VFSFixture/etc/ssh/sshd_config") with open(test_data, "rb") as f: SSHD_CFG.extend(parser.Parse(None, f, None)) return SSHD_CFG
test_data = os.path.join(config_lib.CONFIG["Test.data_dir"], "dpkg.out") with open(test_data) as f: DPKG_SW = list( parser.Parse("/usr/bin/dpkg", ["-l"], f.read(), "", 0, 5, None)) # Load some wmi data parser = wmi_parser.WMIInstalledSoftwareParser() test_data = os.path.join(config_lib.CONFIG["Test.data_dir"], "wmi_sw.yaml") WMI_SW = [] with open(test_data) as f: wmi = yaml.safe_load(f) for sw in wmi: WMI_SW.extend(parser.Parse(None, sw, None)) # Load an sshd config parser = config_file_parsers.SshdConfigParser() test_data = os.path.join(config_lib.CONFIG["Test.data_dir"], "sshd_config") with open(test_data) as f: SSHD_CFG = list(parser.Parse(None, f, None)) def _LoadCheck(cfg_file, check_id): configs = checks.LoadConfigsFromFile(os.path.join(CHECKS_DIR, cfg_file)) cfg = configs.get(check_id) return checks.Check(**cfg) class MatchMethodTests(test_lib.GRRBaseTest): """Test match method selection and comparisons.""" def setUp(self): super(MatchMethodTests, self).setUp()
def setUpClass(cls): super(SshdCheckTests, cls).setUpClass() cls.LoadCheck("sshd.yaml") cls.parser = config_file.SshdConfigParser()
def GetConfig(self): """Read in the test configuration file.""" parser = config_file.SshdConfigParser() results = list(parser.Parse(None, StringIO.StringIO(CFG), None)) self.assertEqual(1, len(results)) return results[0]
test_data = os.path.join(config_lib.CONFIG["Test.data_dir"], "dpkg.out") with open(test_data) as f: DPKG_SW = list( parser.Parse("/usr/bin/dpkg", ["-l"], f.read(), "", 0, 5, None)) # Load some wmi data parser = wmi_parser.WMIInstalledSoftwareParser() test_data = os.path.join(config_lib.CONFIG["Test.data_dir"], "wmi_sw.yaml") WMI_SW = [] with open(test_data) as f: wmi = yaml.safe_load(f) for sw in wmi: WMI_SW.extend(parser.Parse(None, sw, None)) # Load an sshd config parser = config_file.SshdConfigParser() test_data = os.path.join(config_lib.CONFIG["Test.data_dir"], "sshd_config") with open(test_data) as f: SSHD_CFG = list(parser.Parse(None, f, None)) def _LoadCheck(cfg_file, check_id): configs = checks.LoadConfigsFromFile(os.path.join(CHECKS_DIR, cfg_file)) cfg = configs.get(check_id) return checks_rdf.Check(**cfg) class MatchMethodTests(test_lib.GRRBaseTest): """Test match method selection and comparisons.""" def setUp(self): super(MatchMethodTests, self).setUp()
def setUpClass(cls): cls.LoadCheck("sshd.yaml") cls.parser = config_file.SshdConfigParser()