Exemplo n.º 1
0
                tests.append(
                    [file_with_path, True]
                )  # True is a dummy testresult, parsing of the *.out files is done while running the tests

            elif file.endswith('.out') or file.endswith(
                    '.err') or file.endswith('.profile'):
                pass
            else:
                raise Exception(
                    'Found unknown file %s in libapparmor test_multi' % file)

    return tests


# if a logfile is given as parameter, print the resulting profile and exit (with $? = 42 to make sure tests break if the caller accidently hands over a parameter)
if __name__ == '__main__' and len(sys.argv) == 2:
    print(logfile_to_profile(sys.argv[1])[1])
    exit(42)

# still here? That means a normal test run
print('Testing libapparmor test_multi tests...')
TestLibapparmorTestMulti.tests = find_test_multi(
    '../../libraries/libapparmor/testsuite/test_multi/')
TestLogToProfile.tests = find_test_multi(
    '../../libraries/libapparmor/testsuite/test_multi/')

setup_aa(apparmor.aa)
setup_all_loops(__name__)
if __name__ == '__main__':
    unittest.main(verbosity=1)
        self.parse_function = aa.parse_mount_rule

class AAParseMountTest(BaseAAParseMountTest):
    tests = [
        ('mount,', 'mount base keyword rule'),
        ('mount -o ro,', 'mount ro rule'),
        ('mount -o rw /dev/sdb1 -> /mnt/external,', 'mount rw with mount point'),
    ]

class AAParseRemountTest(BaseAAParseMountTest):
    tests = [
        ('remount,', 'remount base keyword rule'),
        ('remount -o ro,', 'remount ro rule'),
        ('remount -o ro /,', 'remount ro with mountpoint'),
    ]

class AAParseUmountTest(BaseAAParseMountTest):
    tests = [
        ('umount,', 'umount base keyword rule'),
        ('umount /mnt/external,', 'umount with mount point'),
        ('unmount,', 'unmount base keyword rule'),
        ('unmount /mnt/external,', 'unmount with mount point'),
    ]

setup_aa(aa)
if __name__ == '__main__':
    setup_regex_tests(AAParseMountTest)
    setup_regex_tests(AAParseRemountTest)
    setup_regex_tests(AAParseUmountTest)
    unittest.main(verbosity=2)
Exemplo n.º 3
0
    print('Searching for parser simple_tests... (this will take a while)')

    for root, dirs, files in os.walk(profile_dir):
        relpath = os.path.relpath(root, profile_dir)

        if relpath == '.':
            # include files are checked as part of the profiles that include them (also, they don't contain EXRESULT)
            dirs.remove('includes')
            dirs.remove('include_tests')
            dirs.remove('includes-preamble')

        for file in files:
            file_with_path = os.path.join(root, file)
            if not apparmor.is_skippable_file(file) and relpath != '.':
                skipped += parse_test_profiles(file_with_path)

    if skipped:
        print('Skipping %s test profiles listed in skip_startswith.' % skipped)

    print('Running %s parser simple_tests...' %
          len(TestParseParserTests.tests))


setup_aa(apparmor)
profile_dir = os.path.abspath('../../parser/tst/simple_tests/')
find_and_setup_test_profiles(profile_dir)

setup_all_loops(__name__)
if __name__ == '__main__':
    unittest.main(verbosity=1)
Exemplo n.º 4
0
    def test_i18n(self):
        self.assertEqual('Test string - do not translate',
                         _('Test string - do not translate'))

    def test_aa_conf(self):
        confdir = os.getenv('__AA_CONFDIR')
        if confdir:
            self.assertEqual(aa.conf.CONF_DIR, confdir)
        else:
            self.assertEqual(aa.conf.CONF_DIR, '/etc/apparmor')

    def test_aa_ui_info(self):
        aaui.UI_Info('Test string')
        self.assertEqual(sys.stdout.getvalue(), 'Test string\n')

    def test_aa_ui_info_json(self):
        aaui.set_json_mode()
        sys.stdout.getvalue()
        aaui.UI_Info('Test string')
        self.assertEqual(
            sys.stdout.getvalue(),
            '{"dialog": "apparmor-json-version","data": "2.12"}\n{"dialog": "info","data": "Test string"}\n'
        )
        aaui.set_text_mode()


setup_aa(aa)  # Wrapper for aa.init_aa()
setup_all_loops(__name__)
if __name__ == '__main__':
    unittest.main(verbosity=1)