Merge SeverityVarsTest: Make order of variable replacements constant

... using [] instead of {}

This should keep the order of checking (and therefore code coverage)
constant, and should fix the randomly appearing partial coverage in
severity.py handle_variable_rank(). In some random cases (depending in
which order the replacements were done and checked for their severity),
the coverage report indicated that the 'elif' condition was never false.

Note: This is only "coverage cosmetics". In "real users", it doesn't
matter in which order the variable replacements are checked because the
result doesn't depend on the ordering.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/790
Acked-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen 2021-08-20 21:52:23 +00:00
commit 572c342a2b

View file

@ -89,13 +89,14 @@ class SeverityVarsTest(SeverityBaseTest):
def _run_test(self, params, expected):
vars = {
'@{HOME}': {'@{HOMEDIRS}/*/', '/root/'},
'@{HOMEDIRS}': {'/home/', '/storage/'},
'@{multiarch}': {'*-linux-gnu*'},
'@{TFTP_DIR}': {'/var/tftp /srv/tftpboot'},
'@{PROC}': {'/proc/'},
'@{somepaths}': {'/home/foo/downloads', '@{HOMEDIRS}/foo/.ssh/'},
'@{strangevar}': ['/srv/', '/proc/'], # Note: using [] instead of {} is intentional to keep order of checking (and therefore code coverage) constant
# Note: using [] instead of {} is intentional to keep order of checking (and therefore code coverage) constant
'@{HOME}': ['@{HOMEDIRS}/*/', '/root/'],
'@{HOMEDIRS}': ['/home/', '/storage/'],
'@{multiarch}': ['*-linux-gnu*'],
'@{TFTP_DIR}': ['/var/tftp /srv/tftpboot'],
'@{PROC}': ['/proc/'],
'@{somepaths}': ['/home/foo/downloads', '@{HOMEDIRS}/foo/.ssh/'],
'@{strangevar}': ['/srv/', '/proc/'],
}
self.sev_db.set_variables(vars)
self._simple_severity_w_perm(params[0], params[1], expected)