

def testParseCronData(self):
    test_data = 'root\n    user\n\n    user2 user3\n    root\n    hi hello\n    user\n    pparth'
    file_obj = StringIO.StringIO(test_data)
    pathspec = rdf_paths.PathSpec(path='/etc/at.allow')
    stat = rdf_client.StatEntry(pathspec=pathspec)
    parser = config_file.CronAtAllowDenyParser()
    results = list(parser.Parse(stat, file_obj, None))
    result = [d for d in results if isinstance(d, rdf_protodict.AttributedDict)][0]
    filename = result.filename
    users = result.users
    self.assertEqual('/etc/at.allow', filename)
    self.assertEqual(sorted(['root', 'user', 'pparth']), sorted(users))
    anomalies = [a for a in results if isinstance(a, rdf_anomaly.Anomaly)]
    self.assertEqual(1, len(anomalies))
    anom = anomalies[0]
    self.assertEqual('Dodgy entries in /etc/at.allow.', anom.symptom)
    self.assertEqual(sorted(['user2 user3', 'hi hello']), sorted(anom.finding))
    self.assertEqual(pathspec, anom.reference_pathspec)
    self.assertEqual('PARSER_ANOMALY', anom.type)

dataset/ETHPy150Open google/grr/grr/parsers/config_file_test.py CronAtAllowDenyParserTests.testParseCronData/original