'Ensure we can extract users from a netgroup file.'

def testNetgroupParser(self):

    parser = linux_file_parser.NetgroupParser()
    dat = u'group1    (-,user1,)    (-,user2,)    (-,user3,)\n#group1    comment\ngroup2    (-,user4,)    (-,user2,)\n\nsuper_group    (-,user5,)    (-,user6,)    (-,\u6587\u5fb7\u6587,)    group1    group2\nsuper_group2    (-,user7,)    super_group\nsuper_group3    (-,user5,)    (-,user6,)    group1    group2\n'
    dat_fd = StringIO.StringIO(dat)
    with test_lib.ConfigOverrider({'Artifacts.netgroup_user_blacklist': ['user2', 'user3']}):
        out = list(parser.Parse(None, dat_fd, None))
        users = []
        for result in out:
            if isinstance(result, rdf_anomaly.Anomaly):
                self.assertTrue((utils.SmartUnicode(u'\u6587\u5fb7\u6587') in result.symptom))
            else:
                users.append(result)
        self.assertItemsEqual([x.username for x in users], [u'user1', u'user4', u'user5', u'user6', u'user7'])
        dat_fd.seek(0)
    with test_lib.ConfigOverrider({'Artifacts.netgroup_filter_regexes': ['^super_group3$']}):
        out = list(parser.Parse(None, dat_fd, None))
        self.assertItemsEqual([x.username for x in out], [u'user5', u'user6'])
