2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-09-01 06:45:38 +00:00

[16/38] move glob_path() and glob_path_ext() to AARE

glob_path() and glob_path_ext() modify a (path) regex, so move them to
AARE. Also change them to use self.regex instead of the newpath
parameter, and to return a new AARE object.

While on it, also add several tests to test-aare.py.


Note: There are still glob_path() and glob_path_ext() calls in aa.py,
but those calls are in a (since the middle of this patch series) dead
code section. pyflakes will complain about them nevertheless ;-)



Acked-by: Steve Beattie <steve@nxnw.org>
This commit is contained in:
Christian Boltz
2016-10-01 19:56:31 +02:00
parent ee7560d6ef
commit 9d6b525899
3 changed files with 162 additions and 49 deletions

View File

@@ -243,6 +243,117 @@ class TestAAREDeepcopy(AATest):
self.assertEqual(params.orig_regex, dup.orig_regex)
self.assertEqual(params.orig_regex, dup.orig_regex)
class TestAAREglobPath(AATest):
tests = [
# _run_test() will also run each test with '/' appended
# regex expected AARE.regex
('/foo/bar/baz**', '/foo/bar/**'),
('/foo/bar/**baz', '/foo/bar/**'),
('/foo/bar/fo**baz', '/foo/bar/**'),
('/foo/bar/**foo**', '/foo/bar/**'),
('/foo/bar/**f?o**', '/foo/bar/**'),
('/foo/bar/**fo[a-z]**', '/foo/bar/**'),
('/foo/bar/baz', '/foo/bar/*'),
('/foo/bar/baz*', '/foo/bar/*'),
('/foo/bar/*baz', '/foo/bar/*'),
('/foo/bar/fo*baz', '/foo/bar/*'),
('/foo/bar/*foo*', '/foo/bar/*'),
('/foo/bar/b[a-z]z', '/foo/bar/*'),
('/foo/bar/{bar,baz}', '/foo/bar/*'),
('/foo/bar/{bar,ba/z}', '/foo/bar/{bar,ba/*'), # XXX
('/foo/*/baz', '/foo/*/*'),
('/foo/bar/**', '/foo/**'),
('/foo/bar/*', '/foo/**'),
('/foo/**/*', '/foo/**'),
('/foo/*/**', '/foo/**'),
('/foo/*/*', '/foo/**'),
]
def _run_test(self, params, expected):
# test for files
oldpath = AARE(params, True)
newpath = oldpath.glob_path()
self.assertEqual(expected, newpath.regex)
# test for directories
oldpath = AARE(params + '/', True)
newpath = oldpath.glob_path()
self.assertEqual(expected + '/', newpath.regex)
class TestAAREglobPathWithExt(AATest):
tests = [
# _run_test() will also run each test with '/' appended
# regex expected AARE.regex
# no extension - shouldn't change
('/foo/bar/baz**', '/foo/bar/baz**'),
('/foo/bar/**baz', '/foo/bar/**baz'),
('/foo/bar/fo**baz', '/foo/bar/fo**baz'),
('/foo/bar/**foo**', '/foo/bar/**foo**'),
('/foo/bar/**f?o**', '/foo/bar/**f?o**'),
('/foo/bar/**fo[a-z]**', '/foo/bar/**fo[a-z]**'),
('/foo/bar/baz', '/foo/bar/baz'),
('/foo/bar/baz*', '/foo/bar/baz*'),
('/foo/bar/*baz', '/foo/bar/*baz'),
('/foo/bar/fo*baz', '/foo/bar/fo*baz'),
('/foo/bar/*foo*', '/foo/bar/*foo*'),
('/foo/bar/b[a-z]z', '/foo/bar/b[a-z]z'),
('/foo/bar/{bar,baz}', '/foo/bar/{bar,baz}'),
('/foo/bar/{bar,ba/z}', '/foo/bar/{bar,ba/z}'),
('/foo/*/baz', '/foo/*/baz'),
('/foo/bar/**', '/foo/bar/**'),
('/foo/bar/*', '/foo/bar/*'),
('/foo/**/*', '/foo/**/*'),
('/foo/*/**', '/foo/*/**'),
('/foo/*/*', '/foo/*/*'),
# with extension added
('/foo/bar/baz**.xy', '/foo/bar/**.xy'),
('/foo/bar/**baz.xy', '/foo/bar/**.xy'),
('/foo/bar/fo**baz.xy', '/foo/bar/**.xy'),
('/foo/bar/**foo**.xy', '/foo/bar/**.xy'),
('/foo/bar/**f?o**.xy', '/foo/bar/**.xy'),
('/foo/bar/**fo[a-z]**.xy', '/foo/bar/**.xy'),
('/foo/bar/baz.xy', '/foo/bar/*.xy'),
('/foo/bar/baz*.xy', '/foo/bar/*.xy'),
('/foo/bar/*baz.xy', '/foo/bar/*.xy'),
('/foo/bar/fo*baz.xy', '/foo/bar/*.xy'),
('/foo/bar/*foo*.xy', '/foo/bar/*.xy'),
('/foo/bar/b[a-z]z.xy', '/foo/bar/*.xy'),
('/foo/bar/{bar,baz}.xy', '/foo/bar/*.xy'),
('/foo/bar/{bar,ba/z}.xy', '/foo/bar/{bar,ba/*.xy'), # XXX
('/foo/*/baz.xy', '/foo/*/*.xy'),
('/foo/bar/**.xy', '/foo/**.xy'),
('/foo/bar/*.xy', '/foo/**.xy'),
('/foo/**/*.xy', '/foo/**.xy'),
('/foo/*/**.xy', '/foo/**.xy'),
('/foo/*/*.xy', '/foo/**.xy'),
]
def _run_test(self, params, expected):
# test for files
oldpath = AARE(params, True)
newpath = oldpath.glob_path_withext()
self.assertEqual(expected, newpath.regex)
# test for directories - should be kept unchanged
oldpath = AARE(params + '/', True)
newpath = oldpath.glob_path_withext()
self.assertEqual(params + '/', newpath.regex) # note that we compare to params, not expected here
setup_all_loops(__name__)
if __name__ == '__main__':