mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 06:16:03 +00:00
update python tools to support includes with absolute paths
For now we only allow quoted absolute paths without spaces in the name due to: - 1738877: include rules don't handle files with spaces in the name - 1738879: include rules don't handle absolute paths without quotes in some versions of parser - 1738880: include rules don't handle relative paths in some versions of the parser
This commit is contained in:
@@ -437,17 +437,27 @@ class TestInvalid_parse_profile_start_line(AATest):
|
||||
|
||||
class Test_re_match_include(AATest):
|
||||
tests = [
|
||||
('#include <abstractions/base>', 'abstractions/base' ),
|
||||
('#include <abstractions/base>', 'abstractions/base' ), # magic path
|
||||
('#include <abstractions/base> # comment', 'abstractions/base' ),
|
||||
('#include<abstractions/base>#comment', 'abstractions/base' ),
|
||||
(' #include <abstractions/base> ', 'abstractions/base' ),
|
||||
('include <abstractions/base>', 'abstractions/base' ), # not supported by parser
|
||||
# ('include foo', 'foo' ), # XXX not supported in tools yet
|
||||
# ('include /foo/bar', '/foo/bar' ), # XXX not supported in tools yet
|
||||
# ('include "foo"', 'foo' ), # XXX not supported in tools yet
|
||||
# ('include "/foo/bar"', '/foo/bar' ), # XXX not supported in tools yet
|
||||
(' some #include <abstractions/base>', None, ),
|
||||
('#include "/foo/bar"', '/foo/bar' ), # absolute path
|
||||
('#include "/foo/bar" # comment', '/foo/bar' ),
|
||||
('#include "/foo/bar"#comment', '/foo/bar' ),
|
||||
(' #include "/foo/bar" ', '/foo/bar' ),
|
||||
('include <abstractions/base>', 'abstractions/base' ), # magic path
|
||||
('include <abstractions/base> # comment', 'abstractions/base' ),
|
||||
('include<abstractions/base>#comment', 'abstractions/base' ),
|
||||
(' include <abstractions/base> ', 'abstractions/base' ),
|
||||
('include "/foo/bar"', '/foo/bar' ), # absolute path
|
||||
('include "/foo/bar" # comment', '/foo/bar' ),
|
||||
('include "/foo/bar"#comment', '/foo/bar' ),
|
||||
(' include "/foo/bar" ', '/foo/bar' ),
|
||||
|
||||
(' some #include <abstractions/base>', None, ), # non-matching
|
||||
(' /etc/fstab r,', None, ),
|
||||
('/usr/include r,', None, ),
|
||||
('/include r,', None, ),
|
||||
]
|
||||
|
||||
def _run_test(self, params, expected):
|
||||
@@ -455,8 +465,53 @@ class Test_re_match_include(AATest):
|
||||
|
||||
class TestInvalid_re_match_include(AATest):
|
||||
tests = [
|
||||
('#include <>', AppArmorException ),
|
||||
('#include <>', AppArmorException ), # '#include'
|
||||
('#include < >', AppArmorException ),
|
||||
('#include ""', AppArmorException ),
|
||||
('#include " "', AppArmorException ),
|
||||
('#include', AppArmorException ),
|
||||
('#include ', AppArmorException ),
|
||||
('#include "foo"', AppArmorException ), # LP: 1738880 (relative)
|
||||
('#include "foo" # comment', AppArmorException ),
|
||||
('#include "foo"#comment', AppArmorException ),
|
||||
(' #include "foo" ', AppArmorException ),
|
||||
('#include "foo/bar"', AppArmorException ),
|
||||
('#include "foo/bar" # comment', AppArmorException ),
|
||||
('#include "foo/bar"#comment', AppArmorException ),
|
||||
(' #include "foo/bar" ', AppArmorException ),
|
||||
('#include foo', AppArmorException ), # LP: 1738879 (no quotes)
|
||||
('#include foo/bar', AppArmorException ),
|
||||
('#include /foo/bar', AppArmorException ),
|
||||
('#include foo bar', AppArmorException ), # LP: 1738877 (space in name)
|
||||
('#include foo bar/baz', AppArmorException ),
|
||||
('#include "foo bar"', AppArmorException ),
|
||||
('#include /foo bar', AppArmorException ),
|
||||
('#include "/foo bar"', AppArmorException ),
|
||||
('#include "foo bar/baz"', AppArmorException ),
|
||||
|
||||
('include <>', AppArmorException ), # 'include'
|
||||
('include < >', AppArmorException ),
|
||||
('include ""', AppArmorException ),
|
||||
('include " "', AppArmorException ),
|
||||
('include', AppArmorException ),
|
||||
('include ', AppArmorException ),
|
||||
('include "foo"', AppArmorException ), # LP: 1738880 (relative)
|
||||
('include "foo" # comment', AppArmorException ),
|
||||
('include "foo"#comment', AppArmorException ),
|
||||
(' include "foo" ', AppArmorException ),
|
||||
('include "foo/bar"', AppArmorException ),
|
||||
('include "foo/bar" # comment', AppArmorException ),
|
||||
('include "foo/bar"#comment', AppArmorException ),
|
||||
(' include "foo/bar" ', AppArmorException ),
|
||||
('include foo', AppArmorException ), # LP: 1738879 (no quotes)
|
||||
('include foo/bar', AppArmorException ),
|
||||
('include /foo/bar', AppArmorException ),
|
||||
('include foo bar', AppArmorException ), # LP: 1738877 (space in name)
|
||||
('include foo bar/baz', AppArmorException ),
|
||||
('include "foo bar"', AppArmorException ),
|
||||
('include /foo bar', AppArmorException ),
|
||||
('include "/foo bar"', AppArmorException ),
|
||||
('include "foo bar/baz"', AppArmorException ),
|
||||
]
|
||||
|
||||
def _run_test(self, params, expected):
|
||||
|
Reference in New Issue
Block a user