IncludeRule: sort files in included directory

... instead of relying on the filesystem(!) ordering, which will look
random to both users and unittests.

Also partially revert the test changes from
c5a7bcd50e /
https://gitlab.com/apparmor/apparmor/-/merge_requests/548 -
sorting the result only in the tests is a bad idea.
This commit is contained in:
Christian Boltz 2020-05-28 20:17:29 +02:00
parent d29bf02d7b
commit c4db85c66a
Failed to generate hash of commit
2 changed files with 3 additions and 3 deletions

View file

@ -138,7 +138,7 @@ class IncludeRule(BaseRule):
files = []
if os.path.isdir(full_path):
for path in os.listdir(full_path):
for path in sorted(os.listdir(full_path)):
if is_skippable_file(path):
continue

View file

@ -360,7 +360,7 @@ class IncludeFullPathsTest(AATest):
os.mkdir(empty_dir, 0o755)
tests = [
# @@ will be replaced with self.profile_dir; if multiple entries, need to be sorted
# @@ will be replaced with self.profile_dir
('include <abstractions/base>', ['@@/abstractions/base'] ),
# ('include "foo"', ['@@/foo'] ), # TODO: adjust logic to honor quoted vs. magic paths (and allow quoted relative paths in re_match_include_parse())
('include "/foo/bar"', ['/foo/bar'] ),
@ -376,7 +376,7 @@ class IncludeFullPathsTest(AATest):
exp2.append(path.replace('@@', self.profile_dir))
obj = IncludeRule._parse(params)
self.assertEqual(sorted(obj.get_full_paths(self.profile_dir)), exp2)
self.assertEqual(obj.get_full_paths(self.profile_dir), exp2)
## --- tests for IncludeRuleset --- #