Beispiel #1
0
    def test_match_filter_recurses_exec_command_filter_matches(self):
        filter_list = [
            filters.IpNetnsExecFilter('/sbin/ip', 'root'),
            filters.IpFilter('/sbin/ip', 'root')
        ]
        args = ['ip', 'netns', 'exec', 'foo', 'ip', 'link', 'list']

        self.assertIsNotNone(wrapper.match_filter(filter_list, args))
Beispiel #2
0
    def test_match_filter_recurses_exec_command_matches_user(self):
        filter_list = [
            filters.IpNetnsExecFilter('/sbin/ip', 'root'),
            filters.IpFilter('/sbin/ip', 'user')
        ]
        args = ['ip', 'netns', 'exec', 'foo', 'ip', 'link', 'list']

        # Currently ip netns exec requires root, so verify that
        # no non-root filter is matched, as that would escalate privileges
        self.assertRaises(wrapper.NoFilterMatched, wrapper.match_filter,
                          filter_list, args)
Beispiel #3
0
    def test_match_filter_recurses_exec_command_filter_does_not_match(self):
        filter_list = [
            filters.IpNetnsExecFilter('/sbin/ip', 'root'),
            filters.IpFilter('/sbin/ip', 'root')
        ]
        args = [
            'ip', 'netns', 'exec', 'foo', 'ip', 'netns', 'exec', 'bar', 'ip',
            'link', 'list'
        ]

        self.assertRaises(wrapper.NoFilterMatched, wrapper.match_filter,
                          filter_list, args)
Beispiel #4
0
 def test_IpNetnsExecFilter_nomatch_nonroot(self):
     f = filters.IpNetnsExecFilter('/sbin/ip', 'user')
     self.assertFalse(
         f.match(['ip', 'netns', 'exec', 'foo', 'ip', 'link', 'list']))
Beispiel #5
0
    def test_IpNetnsExecFilter_nomatch(self):
        f = filters.IpNetnsExecFilter('/sbin/ip', 'root')
        self.assertFalse(f.match(['ip', 'link', 'list']))

        # verify that at least a NS is given
        self.assertFalse(f.match(['ip', 'netns', 'exec']))
Beispiel #6
0
 def test_IpNetnsExecFilter_match(self):
     f = filters.IpNetnsExecFilter('/sbin/ip', 'root')
     self.assertTrue(
         f.match(['ip', 'netns', 'exec', 'foo', 'ip', 'link', 'list']))