def test_write_manually(self):
        obj = RlimitRule('as', '1024MB')

        expected = '    set rlimit as <= 1024MB,'

        self.assertEqual(expected, obj.get_clean(2), 'unexpected clean rule')
        self.assertEqual(expected, obj.get_raw(2), 'unexpected raw rule')
    def _check_invalid_rawrule(self, rawrule):
        obj = None
        self.assertFalse(RlimitRule.match(rawrule))
        with self.assertRaises(AppArmorException):
            obj = RlimitRule(RlimitRule.parse(rawrule))

        self.assertIsNone(obj, 'RlimitRule handed back an object unexpectedly')
    def test_borked_obj_is_covered_2(self):
        obj = RlimitRule.parse('set rlimit cpu <= 1024,')

        testobj = RlimitRule('cpu', '1024')
        testobj.value = ''

        with self.assertRaises(AppArmorBug):
            obj.is_covered(testobj)
Exemplo n.º 4
0
class RlimitFromInit(RlimitTest):
    tests = [
        # RlimitRule object                                  audit  allow  deny   comment        rlimit         value     all/infinity?
        (RlimitRule('as', '2047MB')                     , exp(False, False, False, ''           , 'as'      ,   '2047MB'    , False)),
        (RlimitRule('as', '2047 MB')                    , exp(False, False, False, ''           , 'as'      ,   '2047 MB'   , False)),
        (RlimitRule('cpu', '1024')                      , exp(False, False, False, ''           , 'cpu'     ,   '1024'      , False)),
        (RlimitRule('rttime', '60minutes')              , exp(False, False, False, ''           , 'rttime'  ,    '60minutes', False)),
        (RlimitRule('nice', '-10')                      , exp(False, False, False, ''           , 'nice'    ,   '-10'       , False)),
        (RlimitRule('rss', RlimitRule.ALL)              , exp(False, False, False, ''           , 'rss'     ,   None        , True )),
    ]

    def _run_test(self, obj, expected):
        self._compare_obj(obj, expected)
 def AASetup(self):
     self.obj = RlimitRule('cpu', '1')
 def test_empty_net_data_2(self):
     obj = RlimitRule('as', '1024MB')
     obj.value = ''
     # no value set, and ALL not set
     with self.assertRaises(AppArmorBug):
         obj.get_clean(1)
 def test_audit_keyword(self):
     with self.assertRaises(AppArmorBug):
         RlimitRule('as', '1024MB', audit=True)
 def test_deny_keyword(self):
     with self.assertRaises(AppArmorBug):
         RlimitRule('as', '1024MB', deny=True)
 def test_missing_params_2(self):
     with self.assertRaises(TypeError):
         RlimitRule('as')
 def _run_test(self, params, expected):
     with self.assertRaises(expected):
         RlimitRule(params[0], params[1])