2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 14:25:52 +00:00

MountRule: make get_clean() more readable

... by getting rid of two mostly-identical, big return statements.

Also add tests for bare umound and remount rules to ensure full test
coverage.
This commit is contained in:
Christian Boltz
2024-03-03 13:09:43 +01:00
parent 5e4c4a0cb3
commit 8c026077d6
2 changed files with 23 additions and 17 deletions

View File

@@ -181,25 +181,29 @@ class MountRule(BaseRule):
fstype = ' fstype%s(%s)' % (wrap_in_with_spaces(self.is_fstype_equal), ', '.join(sorted(self.fstype))) if not self.all_fstype else ''
options = ' options%s(%s)' % (wrap_in_with_spaces(self.is_options_equal), ', '.join(sorted(self.options))) if not self.all_options else ''
source = ""
dest = ""
if self.operation == 'mount':
return ('%s%s%s%s%s%s%s,%s' % ( self.modifiers_str(),
space,
self.operation,
fstype,
options,
" " + str(self.source.regex) if not self.all_source else '',
" -> " + str(self.dest.regex) if not self.all_dest else '',
self.comment,
))
if not self.all_source:
source = " " + str(self.source.regex)
if not self.all_dest:
dest = " -> " + str(self.dest.regex)
else:
return ('%s%s%s%s%s%s,%s' % ( self.modifiers_str(),
space,
self.operation,
fstype,
options,
" " + str(self.dest.regex) if not self.all_dest else '',
self.comment,
))
if not self.all_dest:
dest = " " + str(self.dest.regex)
return ('%s%s%s%s%s%s%s,%s' % ( self.modifiers_str(),
space,
self.operation,
fstype,
options,
source,
dest,
self.comment,
))
def _is_covered_localvars(self, other_rule):
if self.operation != other_rule.operation:

View File

@@ -157,7 +157,9 @@ class MountTestClean(AATest):
(' mount fstype in ( sysfs , procfs ) , ', 'mount fstype in (procfs, sysfs),'),
(' mount options in ( rw ) , ', 'mount options in (rw),'),
(' mount options in ( rw , noatime ) , ', 'mount options in (noatime, rw),'),
(' umount , ', 'umount,'),
(' umount /foo , ', 'umount /foo,'),
(' remount , ', 'remount,'),
(' remount /foo , ', 'remount /foo,'),
)