2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-30 13:58:22 +00:00

move globbing tests to test-aare.py

aa_test.py doesn't run in 'make check' because its filename doesn't
match the 'test-*.py' pattern.

Move tests for globbing ("plain" globbing and globbing with ext) to
test-aare.py to make sure those tests actually run.

Note: This isn't an exact move - I adjusted some of the tests to make
them more useful, and added some more tests.

Also, glob_path() and glob_path_withext() no longer exist in aa.py.
They moved to the AARE class as part of the FileRule patch series.


Acked-by: Steve Beattie <steve@nxnw.org>
This commit is contained in:
Christian Boltz 2016-10-10 23:07:16 +02:00
parent 65844a5e1f
commit 93d1539f4f
2 changed files with 60 additions and 47 deletions

View File

@ -38,53 +38,6 @@ class Test(unittest.TestCase):
def test_loadinclude(self):
apparmor.aa.loadincludes()
def test_path_globs(self):
globs = {
'/foo/': '/*/',
'/foo': '/*',
'/b*': '/*',
'/*b': '/*',
'/*': '/*',
'/*/': '/*/',
'/*.foo/': '/*/',
'/**.foo/': '/**/',
'/foo/*/': '/**/',
'/usr/foo/*': '/usr/**',
'/usr/foo/**': '/usr/**',
'/usr/foo/bar**': '/usr/foo/**',
'/usr/foo/**bar': '/usr/foo/**',
'/usr/bin/foo**bar': '/usr/bin/**',
'/usr/foo/**/bar': '/usr/foo/**/*',
'/usr/foo/**/*': '/usr/foo/**',
'/usr/foo/*/bar': '/usr/foo/*/*',
'/usr/bin/foo*bar': '/usr/bin/*',
'/usr/bin/*foo*': '/usr/bin/*',
'/usr/foo/*/*': '/usr/foo/**',
'/usr/foo/*/**': '/usr/foo/**',
'/**': '/**',
'/**/': '/**/'
}
for path in globs.keys():
self.assertEqual(apparmor.aa.glob_path(path), globs[path], 'Unexpected glob generated for path: %s'%path)
def test_path_withext_globs(self):
globs = {
'/foo/bar': '/foo/bar',
'/foo/**/bar': '/foo/**/bar',
'/foo.bar': '/*.bar',
'/*.foo': '/*.foo' ,
'/usr/*.bar': '/**.bar',
'/usr/**.bar': '/**.bar',
'/usr/foo**.bar': '/usr/**.bar',
'/usr/foo*.bar': '/usr/*.bar',
'/usr/fo*oo.bar': '/usr/*.bar',
'/usr/*foo*.bar': '/usr/*.bar',
'/usr/**foo.bar': '/usr/**.bar',
'/usr/*foo.bar': '/usr/*.bar',
'/usr/foo.b*': '/usr/*.b*'
}
for path in globs.keys():
self.assertEqual(apparmor.aa.glob_path_withext(path), globs[path], 'Unexpected glob generated for path: %s'%path)
def test_modes_to_string(self):

View File

@ -275,6 +275,27 @@ class TestAAREglobPath(AATest):
('/foo/*/**', '/foo/**'),
('/foo/*/*', '/foo/**'),
('/foo', '/*',),
('/b*', '/*',),
('/*b', '/*',),
('/*', '/*',),
('/*.foo', '/*',),
('/**.foo', '/**',),
('/foo/*', '/**',),
('/usr/foo/*', '/usr/**',),
('/usr/foo/**', '/usr/**',),
('/usr/foo/bar**', '/usr/foo/**',),
('/usr/foo/**bar', '/usr/foo/**',),
('/usr/bin/foo**bar', '/usr/bin/**',),
('/usr/foo/**/bar', '/usr/foo/**/*',),
('/usr/foo/**/*', '/usr/foo/**',),
('/usr/foo/*/bar', '/usr/foo/*/*',),
('/usr/bin/foo*bar', '/usr/bin/*',),
('/usr/bin/*foo*', '/usr/bin/*',),
('/usr/foo/*/*', '/usr/foo/**',),
('/usr/foo/*/**', '/usr/foo/**',),
('/**', '/**',),
]
def _run_test(self, params, expected):
@ -319,6 +340,23 @@ class TestAAREglobPathWithExt(AATest):
('/foo/*/**', '/foo/*/**'),
('/foo/*/*', '/foo/*/*'),
('/*', '/*'),
('/**', '/**'),
('/foo/bar', '/foo/bar'),
('/foo/**/bar', '/foo/**/bar'),
('/foo.bar', '/*.bar'),
('/*.foo', '/*.foo' ),
('/usr/*.bar', '/**.bar'),
('/usr/**.bar', '/**.bar'),
('/usr/foo**.bar', '/usr/**.bar'),
('/usr/foo*.bar', '/usr/*.bar'),
('/usr/fo*oo.bar', '/usr/*.bar'),
('/usr/*foo*.bar', '/usr/*.bar'),
('/usr/**foo.bar', '/usr/**.bar'),
('/usr/*foo.bar', '/usr/*.bar'),
('/usr/foo.b*', '/usr/*.b*'),
# with extension added
('/foo/bar/baz**.xy', '/foo/bar/**.xy'),
('/foo/bar/**baz.xy', '/foo/bar/**.xy'),
@ -344,6 +382,28 @@ class TestAAREglobPathWithExt(AATest):
('/foo/**/*.xy', '/foo/**.xy'),
('/foo/*/**.xy', '/foo/**.xy'),
('/foo/*/*.xy', '/foo/**.xy'),
('/*.foo', '/*.foo'),
('/**.foo', '/**.foo'),
('/foo.baz', '/*.baz'),
('/b*.baz', '/*.baz'),
('/*b.baz', '/*.baz'),
('/foo/*.baz', '/**.baz'),
('/usr/foo/*.baz', '/usr/**.baz'),
('/usr/foo/**.baz', '/usr/**.baz'),
('/usr/foo/bar**.baz', '/usr/foo/**.baz'),
('/usr/foo/**bar.baz', '/usr/foo/**.baz'),
('/usr/bin/foo**bar.baz', '/usr/bin/**.baz'),
('/usr/foo/**/bar.baz', '/usr/foo/**/*.baz'),
('/usr/foo/**/*.baz', '/usr/foo/**.baz'),
('/usr/foo/*/bar.baz', '/usr/foo/*/*.baz'),
('/usr/bin/foo*bar.baz', '/usr/bin/*.baz'),
('/usr/bin/*foo*.baz', '/usr/bin/*.baz'),
('/usr/foo/*/*.baz', '/usr/foo/**.baz'),
('/usr/foo/*/**.baz', '/usr/foo/**.baz'),
]
def _run_test(self, params, expected):