示例#1
0
    def testCronTabParser(self):
        """Ensure we can extract jobs from a crontab file."""
        parser = cron_file_parser.CronTabParser()
        results = []

        path = os.path.join(self.base_path, "parser_test", "crontab")
        plist_file = open(path, "rb")
        stat = rdf_client.StatEntry(pathspec=rdf_paths.PathSpec(
            path=path, pathtype=rdf_paths.PathSpec.PathType.OS),
                                    st_mode=16877)
        results.extend(list(parser.Parse(stat, plist_file, None)))

        self.assertEqual(len(results), 1)

        for result in results:
            self.assertEqual(result.jobs[0].minute, "1")
            self.assertEqual(result.jobs[0].hour, "2")
            self.assertEqual(result.jobs[0].dayofmonth, "3")
            self.assertEqual(result.jobs[0].month, "4")
            self.assertEqual(result.jobs[0].dayofweek, "5")
            self.assertEqual(result.jobs[0].command, "/usr/bin/echo \"test\"")
示例#2
0
  def testCronTabParser(self):
    """Ensure we can extract jobs from a crontab file."""
    parser = cron_file_parser.CronTabParser()
    client = "C.1000000000000000"
    results = []

    path = os.path.join(self.base_path, "crontab")
    plist_file = open(path)
    stat = rdfvalue.StatEntry(
        aff4path=rdfvalue.ClientURN(client).Add("fs/os").Add(path),
        pathspec=rdfvalue.PathSpec(path=path,
                                   pathtype=rdfvalue.PathSpec.PathType.OS),
        st_mode=16877)
    results.extend(list(parser.Parse(stat, plist_file, None)))

    self.assertEqual(len(results), 1)

    for result in results:
      self.assertEqual(result.jobs[0].minute, '1')
      self.assertEqual(result.jobs[0].hour, '2')
      self.assertEqual(result.jobs[0].dayofmonth, '3')
      self.assertEqual(result.jobs[0].month, '4')
      self.assertEqual(result.jobs[0].dayofweek, '5')
      self.assertEqual(result.jobs[0].command, '/usr/bin/echo "test"')