Commit graph

597 commits

Author SHA1 Message Date
Mark Grassi
084e35e3be Change apparmor.common.combine_profname arguments from list to tuple literals. 2022-09-11 21:56:26 -04:00
Mark Grassi
c7d1d5ea93 Rename BaseRule's _parse() method to _create_instance() 2022-09-10 19:54:35 -04:00
Mark Grassi
accc2debe9 Rename BaseRule's parse() method to create_instance() 2022-09-10 19:54:35 -04:00
Mark Grassi
380bed3c9b Replace exit() with sys.exit(). 2022-08-28 22:40:28 -04:00
Mark Grassi
e754e8aed7 Narrow broad except statements. 2022-08-27 17:58:51 +00:00
Mark Grassi
46a2be31a7 Remove outdated/incorrect comment. 2022-08-21 11:15:07 -04:00
Mark Grassi
854602c0d9 Use the fact that empty sequences are false. 2022-08-21 11:15:07 -04:00
Mark Grassi
68e3f12c2c Avoid escaping quotation marks where possible. 2022-08-21 11:15:07 -04:00
Mark Grassi
c57138f255 Order imports and module-level dunder name assignments. 2022-08-21 11:15:07 -04:00
Mark Grassi
ea3fb60007 Break lines before binary operators. 2022-08-21 11:15:07 -04:00
Mark Grassi
ef2e6c62e7 Ensure variables inside functions are lower_case_with_underscores. 2022-08-21 11:15:07 -04:00
Mark Grassi
dc384c48a8 Use triple double-quoted strings for docstrings. 2022-08-21 11:15:07 -04:00
Mark Grassi
de3aa3c5f0 Correct misspelling. 2022-08-21 11:15:07 -04:00
Mark Grassi
f590a66e50 Remove redundant backslashes, and unnecessary semicolons and pass statements. 2022-08-21 11:15:07 -04:00
Mark Grassi
813c831468 Ensure non-membership tests are "not in". 2022-08-21 11:15:07 -04:00
Mark Grassi
96f7121944 Fix most PEP 8 whitespace, indentation, and major line length violations. 2022-08-21 11:15:07 -04:00
Mark Grassi
e4f88cc3a8 Indent line continuations per PEP 8. 2022-08-21 11:15:07 -04:00
Mark Grassi
aff9bb8f81 Ensure no bool comparisons use equality comparisons. 2022-08-21 11:15:07 -04:00
Mark Grassi
62f99465e9 Ensure all None comparisons use is or is not. 2022-08-21 11:15:07 -04:00
Christian Boltz
5a2fb8569c
Set (instead of compare) exresult
Interestingly this accidentally worked because `if exresult` is true for
both a non-empty string ("PASS") as well as a real `True` value.

Found by Mark Grassi as part of
https://gitlab.com/apparmor/apparmor/-/merge_requests/906
2022-08-14 12:33:56 +02:00
Christian Boltz
c0b5d90848 Merge Resolve "Python: Ensure opened files are closed."
This MR closes #239. In the temporary file commit, `tempfile.NamedTemporaryFile` is preferred over `tempfile.mkstemp` because it allows for simpler use of context managers and lets you choose what mode to open the file in. Also in this commit, note that in `aa.py` and `easyprof.py` destination files are now written directly, instead of writing to temp files and then renaming them.

Closes #239
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/898
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-20 19:34:16 +00:00
Ben Greiner
d442584a0a reviewed edits 2022-07-19 21:47:02 +02:00
Mark Grassi
cf6606d380 Ensure opened temporary files are closed. 2022-07-17 21:52:55 -04:00
Ben Greiner
47d68dac0f use new build_platlib path with setuptools >= 61.2 2022-07-16 17:47:18 +02:00
Mark Grassi
44c814e76c Update code coverage settings. 2022-07-06 13:29:32 -04:00
Mark Grassi
df97cf89bd Remove Python 2 support. 2022-06-29 20:41:38 -04:00
Mark Grassi
7581c9e113 Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
Mark Grassi
ca9920cf92 Avoid unnecessary memory copies when enlarging lists. 2022-06-26 12:06:22 +00:00
Christian Boltz
50a45c6a39 Merge Ensure opened files are closed.
This partially addresses issue #239. There are still some remaining instances where opened files are not properly closed, e.g. the `NamedTemporaryFile` in `utils/apparmor/config.py`.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/885
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-22 17:20:49 +00:00
Mark Grassi
c255968e63 Fix spelling and grammar errors. 2022-06-18 16:14:45 -04:00
Mark Grassi
bf819bc8e6 Ensure opened files are closed. 2022-06-18 14:40:58 -04:00
Christian Boltz
39f4132ab9
make test-aa-notify test_help_contents () less strict
Python 3.10 generates a slightly different --help output.

Fixes https://gitlab.com/apparmor/apparmor/-/issues/220
2022-02-15 19:39:32 +01:00
intrigeri
368625a9d3 utils/test/README.md: document not-totally-obvious cross-tree semi-dependency
Thanks to @cboltz for the explanation.
2022-02-13 21:02:58 +00:00
intrigeri
af76d98fce utils/test/: drop support for running with Python 2 2022-02-13 19:43:48 +00:00
Georgia Garcia
21e5a721ab replace deprecated distutils with setuptools
Adds python3 setuptools as a build dependency for libapparmor

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/202
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/813
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-11-11 20:23:35 -03:00
Christian Boltz
1da0305c89
Add tests for sane_timestamp
Ensure that pre-2000 and post-2050 dates get rejected, and something in
between gets accepted.

This also extends coverage to 100% - before, the post-2050 branch was
not covered.
2021-10-24 17:24:43 +02:00
Christian Boltz
63f1a58bef
Add truncated and ancient wtmp example to tests
A too-small file can't contain something useful.

Also, a wtmp file with a timestamp from pre-2000 is beyond what you'd
expect on a 2021 system.
2021-10-24 17:24:43 +02:00
Christian Boltz
255716b90a
Add support for reading s390x and aarch64 wtmp file
Both aarch64 and s390x have a bigger wtmp record size (16 bytes more
than x86_64, 400 bytes total).

The byte position of the timestamp is also different on each
architecture. To make things even more interesting, s390x is big endian.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1181155
2021-10-24 17:24:43 +02:00
Christian Boltz
905b89a5c7
Add unittest for get_last_login_timestamp
... starting with a x86_64 wtmp example file
2021-10-24 14:23:53 +02:00
Christian Boltz
0ee225b498
import hasher from apparmor.common
... instead of indirectly using it via apparmor.aa
2021-08-24 22:48:19 +02:00
Christian Boltz
c09e0b6ef3
import is_skippable_file from apparmor.common
... instead of indirectly using it via apparmor.aa
2021-08-24 22:47:39 +02:00
Christian Boltz
8b2fe01c7d
aa-easyprof: use AppArmorException from apparmor.common
... instead of keeping an own version of it witht the exact same code
and a TODO note to use the one from common.

Also adjust the aa-easyprof tests to directly import AppArmorException
from apparmor.common.
2021-08-24 22:35:59 +02:00
John Johansen
5068f54cf1 Merge ProfileStorage: Store empty xattrs as empty string
... instead of None.

This avoids the need to allow type changes (None vs. str).

Also adjust the tests accordingly.

While on it, simplify the tests for attachment.

attachment is always a str, therefore adjust the test to expect an empty
str ('') instead of None - and later converting that None to ''.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/786
Acked-by: John Johansen <john.johansen@canonical.com>
2021-08-20 21:55:22 +00:00
Christian Boltz
d4b17ef904
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.
2021-08-19 12:52:56 +02:00
Christian Boltz
e69f46ac3f
ProfileStorage: simplify tests for attachment
attachment is always a str, therefore adjust the test to expect an empty
str ('') instead of None - and later converting that None to ''.
2021-08-16 19:59:05 +02:00
Christian Boltz
337ebcd032
ProfileStorage: Store empty xattrs as empty string
... instead of None.

This avoids the need to allow type changes (None vs. str).

Also adjust the tests accordingly.
2021-08-16 19:59:02 +02:00
Christian Boltz
26d7c13f94
Add option to skip reading specific profiles
If a profile uses features not supported by the tools yet, add a
skiplist to (hopefully temporarily) exclude it from the tests.

This is meant to avoid blocking usage of new features in profiles.

When doing a release, the skip lists should be empty.
2021-07-13 21:09:36 +02:00
Christian Boltz
b02c59a730
Test if active and extra profiles can be parsed by the tools
The added test makes sure that the python code can parse all profiles
shipped with AppArmor. If this fails, read_profiles() /
read_inactive_profiles() will raise an exception.

Checking for the number of read profiles is mostly done to ensure
*something* is read (to make sure an empty or non-existing directory
won't make the test useless).
2021-07-13 21:09:36 +02:00
Christian Boltz
92883d7e6c
Fix extra profiles path in utils/test/logprof.conf 2021-07-13 21:09:35 +02:00
Christian Boltz
8d9e2489a2
Generate and keep html in utils coverage-regression
We sometimes have random coverage changes that are not reproducible and
therefore hard to debug.

Generate html coverage as part of make coverage-regression, and keep the
resulting utils/test/htmlcov/ as artifact to make debugging easier.

coverage-html needs JS files from various libjs-* packages, install them
in before_script
2021-07-13 18:40:59 +02:00