Hello, Am Montag, 1. Februar 2016, 11:50:49 CET schrieb Seth Arnold: > On Mon, Feb 01, 2016 at 07:35:07PM +0100, Christian Boltz wrote: > > --- utils/test/test-aa.py 2016-01-26 22:22:14.660008000 +0100 > > +++ utils/test/test-aa.py 2016-02-01 18:53:10.085684909 +0100
> > +import apparmor.aa as aa # needed to set global vars in some tests > Most of this looked good but I'm a bit worried about the global > variables. Could they be referenced via apparmor.aa.<whatever> > instead? I think that'd lead to better comprehension two years from > now.. Yes, that's possible ;-) - it makes the import a bit shorter ("as aa" gets removed) and the usage a bit longer ("apparmor.aa.cfg...") Here's v2 with this changed: [ 66-add-tests-for-get_output-and-get_reqs.diff ] --- utils/test/test-aa.py 2016-01-26 22:22:14.660008000 +0100 +++ utils/test/test-aa.py 2016-02-01 18:53:10.085684909 +0100 @@ -14,8 +14,9 @@ from common_test import read_file, write_file import os -from apparmor.aa import (check_for_apparmor, get_interpreter_and_abstraction, create_new_profile, +import apparmor.aa # needed to set global vars in some tests +from apparmor.aa import (check_for_apparmor, get_output, get_reqs, get_interpreter_and_abstraction, create_new_profile, get_profile_flags, set_profile_flags, is_skippable_file, is_skippable_dir, parse_profile_start, parse_profile_data, separate_vars, store_list_var, write_header, var_transform, serialize_parse_profile_start) @@ -72,6 +73,26 @@ mounts = write_file(self.tmpdir, 'mounts', self.MOUNTS_WITH_SECURITYFS % self.tmpdir) self.assertEqual('%s/security/apparmor' % self.tmpdir, check_for_apparmor(filesystems, mounts)) +class AATest_get_output(AATest): + tests = [ + (['./fake_ldd', '/AATest/lib64/libc-2.22.so'], (0, [' /AATest/lib64/ld-linux-x86-64.so.2 (0x0000556858473000)', ' linux-vdso.so.1 (0x00007ffe98912000)'] )), + (['./fake_ldd', '/tmp/aa-test-foo'], (0, [' not a dynamic executable'] )), + (['./fake_ldd', 'invalid'], (1, [''] )), # stderr is not part of output + ] + def _run_test(self, params, expected): + self.assertEqual(get_output(params), expected) + +class AATest_get_reqs(AATest): + tests = [ + ('/AATest/bin/bash', ['/AATest/lib64/libreadline.so.6', '/AATest/lib64/libtinfo.so.6', '/AATest/lib64/libdl.so.2', '/AATest/lib64/libc.so.6', '/AATest/lib64/ld-linux-x86-64.so.2']), + ('/tmp/aa-test-foo', []), + ] + + def _run_test(self, params, expected): + apparmor.aa.cfg['settings']['ldd'] = './fake_ldd' + + self.assertEqual(get_reqs(params), expected) + class AaTest_create_new_profile(AATest): tests = [ # file content expected interpreter expected abstraction (besides 'base') --- utils/test/fake_ldd 2016-02-01 19:22:59.738008345 +0100 +++ utils/test/fake_ldd 2016-02-01 19:23:58.781645883 +0100 @@ -0,0 +1,56 @@ +#!/usr/bin/python3 + +import sys + +if len(sys.argv) != 2: + raise Exception('wrong number of arguments in fake_ldd') + +if sys.argv[1] == '/AATest/bin/bash': + print(' linux-vdso.so.1 (0x00007ffcf97f4000)') + print(' libreadline.so.6 => /AATest/lib64/libreadline.so.6 (0x00007f2c41324000)') + print(' libtinfo.so.6 => /AATest/lib64/libtinfo.so.6 (0x00007f2c410f9000)') + print(' libdl.so.2 => /AATest/lib64/libdl.so.2 (0x00007f2c40ef5000)') + print(' libc.so.6 => /AATest/lib64/libc.so.6 (0x00007f2c40b50000)') + print(' /AATest/lib64/ld-linux-x86-64.so.2 (0x000055782c473000)') + +elif sys.argv[1] == '/AATest/lib64/ld-2.22.so': + print(' linux-vdso.so.1 (0x00007ffcf97f4000)') + +elif sys.argv[1] == '/AATest/lib64/libc-2.22.so': + print(' /AATest/lib64/ld-linux-x86-64.so.2 (0x0000556858473000)') + print(' linux-vdso.so.1 (0x00007ffe98912000)') + +elif sys.argv[1] == '/AATest/lib64/libdl.so.2': + print(' linux-vdso.so.1 (0x00007ffec2538000)') + print(' libc.so.6 => /AATest/lib64/libc.so.6 (0x00007f8865346000)') + print(' /AATest/lib64/ld-linux-x86-64.so.2 (0x0000560c3bcee000)') + +elif sys.argv[1] == '/AATest/lib64/libtinfo.so.6': + print(' linux-vdso.so.1 (0x00007fff30518000)') + print(' libc.so.6 => /AATest/lib64/libc.so.6 (0x00007fb6f2ea3000)') + print(' /AATest/lib64/ld-linux-x86-64.so.2 (0x00005631fe8d3000)') + +elif sys.argv[1] == '/AATest/lib64/libreadline.so.6': + print(' linux-vdso.so.1 (0x00007ffcb5b62000)') + print(' libtinfo.so.6 => /AATest/lib64/libtinfo.so.6 (0x00007f2a4ed07000)') + print(' libc.so.6 => /AATest/lib64/libc.so.6 (0x00007f2a4e961000)') + print(' /AATest/lib64/ld-linux-x86-64.so.2 (0x000055f749c89000)') + +elif sys.argv[1] == '/AATest/lib64/ld-linux-x86-64.so.2': + print(' statically linked') + +elif sys.argv[1] == '/AATest/lib64/libc.so.6': + print(' /AATest/lib64/ld-linux-x86-64.so.2 (0x000055b65f7a9000)') + print(' linux-vdso.so.1 (0x00007ffde132b000)') + + +elif sys.argv[1].startswith('/tmp/aa-test-'): # test file generated by test-aa.py + print(' not a dynamic executable') + +elif sys.argv[1] == 'TEMPLATE': + print('') + print('') + print('') + +else: + raise Exception('unknown parameter in fake_ldd: %s' % sys.argv[1]) Regards, Christian Boltz -- > (Windows XP welches auch installiert ist läuft aber ohne Probleme) Musst Du nicht erwähnen, eine Mail so zu versauen, geht in der Regel nur mit Outlook. [> Stephan Papst und Manfred Tremmel in suse-linux]
signature.asc
Description: This is a digitally signed message part.
-- AppArmor mailing list AppArmor@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor