Exemplo n.º 1
0
    def test_ChainingRegExpFilter_multiple(self):
        filter_list = [filters.ChainingRegExpFilter('ionice', 'root', 'ionice',
                                                    '-c[0-3]'),
                       filters.ChainingRegExpFilter('ionice', 'root', 'ionice',
                                                    '-c[0-3]', '-n[0-7]'),
                       filters.CommandFilter('cat', 'root')]
        # both filters match to ['ionice', '-c2'], but only the second accepts
        args = ['ionice', '-c2', '-n7', 'cat', '/a']
        dirs = ['/bin', '/usr/bin']

        self.assertIsNotNone(wrapper.match_filter(filter_list, args, dirs))
Exemplo n.º 2
0
    def test_ChainingRegExpFilter_match(self):
        filter_list = [filters.ChainingRegExpFilter('nice', 'root',
                                                    'nice', '-?\d+'),
                       filters.CommandFilter('cat', 'root')]
        args = ['nice', '5', 'cat', '/a']
        dirs = ['/bin', '/usr/bin']

        self.assertIsNotNone(wrapper.match_filter(filter_list, args, dirs))
Exemplo n.º 3
0
    def test_ChainingRegExpFilter_not_match(self):
        filter_list = [filters.ChainingRegExpFilter('nice', 'root',
                                                    'nice', '-?\d+'),
                       filters.CommandFilter('cat', 'root')]
        args_invalid = (['nice', '5', 'ls', '/a'],
                        ['nice', '--5', 'cat', '/a'],
                        ['nice2', '5', 'cat', '/a'],
                        ['nice', 'cat', '/a'],
                        ['nice', '5'])
        dirs = ['/bin', '/usr/bin']

        for args in args_invalid:
            self.assertRaises(wrapper.NoFilterMatched,
                              wrapper.match_filter, filter_list, args, dirs)