コード例 #1
0
ファイル: test-aa.py プロジェクト: youngker/apparmor
    def _run_test(self, params, expected):
        self.createTmpdir()

        #copy the local profiles to the test directory
        self.profile_dir = '%s/profiles' % self.tmpdir
        shutil.copytree('../../profiles/apparmor.d/', self.profile_dir, symlinks=True)

        # load the abstractions we need in the test
        apparmor.aa.profile_dir = self.profile_dir
        apparmor.aa.load_include(os.path.join(self.profile_dir, 'abstractions/base'))

        abs_include1 = write_file(self.tmpdir, 'test-abs1', "/some/random/include rw,")
        apparmor.aa.load_include(abs_include1)

        abs_include2 = write_file(self.tmpdir, 'test-abs2', "/some/other/* rw,")
        apparmor.aa.load_include(abs_include2)

        abs_include3 = write_file(self.tmpdir, 'test-abs3', "/some/other/inc* rw,")
        apparmor.aa.load_include(abs_include3)

        profile = apparmor.aa.ProfileStorage('/test', '/test', 'test-aa.py')
        profile['inc_ie'].add(IncludeRule.parse('include <abstractions/base>'))
        profile['inc_ie'].add(IncludeRule.parse('include "%s"' % abs_include1))
        profile['inc_ie'].add(IncludeRule.parse('include "%s"' % abs_include2))
        profile['inc_ie'].add(IncludeRule.parse('include "%s"' % abs_include3))

        rule_obj = FileRule(params[0], params[1], None, FileRule.ALL, owner=False, log_event=True)
        proposals = propose_file_rules(profile, rule_obj)
        self.assertEqual(proposals, expected)
コード例 #2
0
ファイル: test-aa.py プロジェクト: youngker/apparmor
    def _run_test(self, params, expected):
        self.createTmpdir()

        #copy the local profiles to the test directory
        self.profile_dir = '%s/profiles' % self.tmpdir
        shutil.copytree('../../profiles/apparmor.d/', self.profile_dir, symlinks=True)

        # load the abstractions we need in the test
        apparmor.aa.profile_dir = self.profile_dir
        apparmor.aa.load_include(os.path.join(self.profile_dir, 'abstractions/base'))
        apparmor.aa.load_include(os.path.join(self.profile_dir, 'abstractions/bash'))
        apparmor.aa.load_include(os.path.join(self.profile_dir, 'abstractions/enchant'))
        apparmor.aa.load_include(os.path.join(self.profile_dir, 'abstractions/aspell'))

        # add some user_globs ('(N)ew') to simulate a professional aa-logprof user (and to make sure that part of the code also gets tested)
        apparmor.aa.user_globs['/usr/share/common*/foo/*'] = AARE('/usr/share/common*/foo/*', True)
        apparmor.aa.user_globs['/no/thi*ng'] = AARE('/no/thi*ng', True)

        profile = apparmor.aa.ProfileStorage('/test', '/test', 'test-aa.py')
        profile['inc_ie'].add(IncludeRule.parse('include <abstractions/base>'))
        profile['inc_ie'].add(IncludeRule.parse('include <abstractions/bash>'))
        profile['inc_ie'].add(IncludeRule.parse('include <abstractions/enchant>'))


        profile['file'].add(FileRule.parse('owner /usr/share/common-licenses/**  w,'))
        profile['file'].add(FileRule.parse('/dev/null rwk,'))
        profile['file'].add(FileRule.parse('/foo/bar rwix,'))
        profile['file'].add(FileRule.parse('/foo/log a,'))  # will be replaced with '/foo/log w,' (not 'wa')

        rule_obj = FileRule(params[0], params[1], None, FileRule.ALL, owner=False, log_event=True)
        proposals = propose_file_rules(profile, rule_obj)
        self.assertEqual(proposals, expected)
コード例 #3
0
ファイル: test-aa.py プロジェクト: youngker/apparmor
    def _run_test(self, params, expected):
        self.createTmpdir()

        #copy the local profiles to the test directory
        self.profile_dir = '%s/profiles' % self.tmpdir
        shutil.copytree('../../profiles/apparmor.d/', self.profile_dir, symlinks=True)

        # load the abstractions we need in the test
        apparmor.aa.profile_dir = self.profile_dir
        apparmor.aa.load_include(os.path.join(self.profile_dir, 'abstractions/base'))
        apparmor.aa.load_include(os.path.join(self.profile_dir, 'abstractions/bash'))
        apparmor.aa.load_include(os.path.join(self.profile_dir, 'abstractions/enchant'))
        apparmor.aa.load_include(os.path.join(self.profile_dir, 'abstractions/aspell'))

        profile = apparmor.aa.ProfileStorage('/test', '/test', 'test-aa.py')
        profile['inc_ie'].add(IncludeRule.parse('include <abstractions/base>'))
        profile['inc_ie'].add(IncludeRule.parse('include <abstractions/bash>'))
        profile['inc_ie'].add(IncludeRule.parse('include <abstractions/enchant>'))

        profile['file'].add(FileRule.parse('owner /usr/share/common-licenses/**  w,'))
        profile['file'].add(FileRule.parse('owner /usr/share/common-licenses/what/ever a,'))  # covered by the above 'w' rule, so 'a' should be ignored
        profile['file'].add(FileRule.parse('/dev/null rwk,'))
        profile['file'].add(FileRule.parse('/foo/bar rwix,'))

        perms = get_file_perms(profile, params, False, False)  # only testing with audit and deny = False
        self.assertEqual(perms, expected)
コード例 #4
0
ファイル: test-include.py プロジェクト: youngker/apparmor
    def test_ruleset_1(self):
        ruleset = IncludeRuleset()
        rules = [
            ' include  <foo>  ',
            ' #include   "/bar" ',
        ]

        expected_raw = [
            'include  <foo>',
            '#include   "/bar"',
            '',
        ]

        expected_clean = [
            'include "/bar"',
            'include <foo>',
            '',
        ]

        expected_clean_unsorted = [
            'include <foo>',
            'include "/bar"',
            '',
        ]

        expected_fullpaths = [os.path.join(self.profile_dir, 'foo'), '/bar']

        for rule in rules:
            ruleset.add(IncludeRule.parse(rule))

        self.assertEqual(expected_raw, ruleset.get_raw())
        self.assertEqual(expected_clean, ruleset.get_clean())
        self.assertEqual(expected_clean_unsorted, ruleset.get_clean_unsorted())
        self.assertEqual(expected_fullpaths,
                         ruleset.get_all_full_paths(self.profile_dir))
コード例 #5
0
ファイル: test-include.py プロジェクト: youngker/apparmor
    def _run_test(self, param, expected):
        obj = IncludeRule.parse(self.rule)
        check_obj = IncludeRule.parse(param)

        self.assertTrue(IncludeRule.match(param))

        self.assertEqual(obj.is_equal(check_obj), expected[0],
                         'Mismatch in is_equal, expected %s' % expected[0])
        self.assertEqual(
            obj.is_equal(check_obj, True), expected[1],
            'Mismatch in is_equal/strict, expected %s' % expected[1])

        self.assertEqual(obj.is_covered(check_obj), expected[2],
                         'Mismatch in is_covered, expected %s' % expected[2])
        self.assertEqual(
            obj.is_covered(check_obj, True, True), expected[3],
            'Mismatch in is_covered/exact, expected %s' % expected[3])
コード例 #6
0
ファイル: test-include.py プロジェクト: youngker/apparmor
    def _run_test(self, rawrule, expected):
        self.assertTrue(IncludeRule.match(rawrule))
        obj = IncludeRule.parse(rawrule)
        clean = obj.get_clean()
        raw = obj.get_raw()

        self.assertEqual(expected.strip(), clean, 'unexpected clean rule')
        self.assertEqual(rawrule.strip(), raw, 'unexpected raw rule')
コード例 #7
0
ファイル: test-include.py プロジェクト: youngker/apparmor
    def _check_invalid_rawrule(self, rawrule, matches_regex=False):
        obj = None
        self.assertEqual(IncludeRule.match(rawrule), matches_regex)
        with self.assertRaises(AppArmorException):
            obj = IncludeRule.parse(rawrule)

        self.assertIsNone(obj,
                          'IncludeRule handed back an object unexpectedly')
コード例 #8
0
 def test_dedup_inc_ie_1(self):
     self.pl.add_inc_ie('/etc/apparmor.d/bin.foo',
                        IncludeRule.parse('include <tunables/global>'))
     self.pl.add_inc_ie(
         '/etc/apparmor.d/bin.foo',
         IncludeRule.parse(
             '#include if exists <tunables/global>  # comment'))
     self.pl.add_inc_ie(
         '/etc/apparmor.d/bin.foo',
         IncludeRule.parse('   #include         <tunables/global>    '))
     deleted = self.pl.delete_preamble_duplicates('/etc/apparmor.d/bin.foo')
     self.assertEqual(deleted, 2)
     self.assertEqual(list(self.pl.files.keys()),
                      ['/etc/apparmor.d/bin.foo'])
     self.assertEqual(self.pl.get_clean('/etc/apparmor.d/bin.foo'),
                      ['include <tunables/global>', ''])
     self.assertEqual(self.pl.get_raw('/etc/apparmor.d/bin.foo'),
                      ['include <tunables/global>', ''])
コード例 #9
0
ファイル: test-include.py プロジェクト: youngker/apparmor
 def _run_test(self, rawrule, expected):
     self.assertTrue(IncludeRule.match(
         rawrule))  # the above invalid rules still match the main regex!
     with self.assertRaises(expected):
         IncludeRule.parse(rawrule)
コード例 #10
0
ファイル: test-include.py プロジェクト: youngker/apparmor
 def _run_test(self, rawrule, expected):
     self.assertTrue(IncludeRule.match(rawrule))
     obj = IncludeRule.parse(rawrule)
     self.assertEqual(rawrule.strip(), obj.raw_rule)
     self._compare_obj(obj, expected)