Commit graph

47 commits

Author SHA1 Message Date
Steve Beattie
3a5106527c utils tests: restructure signal parse tests
Convert the signal parse tests to use common AAParseTest super class in
common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:36:11 -07:00
Steve Beattie
b05cc0f36f utils tests: restructure ptrace parse tests
Convert the ptrace parse tests to use common AAParseTest super class
in common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:32:59 -07:00
Steve Beattie
e8d7dcd321 utils tests: restructure pivotroot parse tests
Convert the pivotroot parse tests to use common AAParseTest super
class in common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:31:09 -07:00
Steve Beattie
37adff769c utils tests: restructure mount parse tests
Convert the mount parse tests to use common AAParseTest super class in
common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:28:18 -07:00
Steve Beattie
59b5b8bab6 Subject: utils tests: restructure DBUS parse tests
Convert the DBUS parse tests to use common AAParseTest super class in
common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:26:19 -07:00
Steve Beattie
365b6d603c utils tests: restructure Unix Parse tests
This patch abstracts out parse tests into a super class to inherit from
and converts the af_unix parse tests to use the super class.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:24:57 -07:00
Steve Beattie
b86d83759a Subject: utils tests: assign regex function at test setup
This patch moves the assignment of the regex function into the unittest
setUp() function rather than at script load time. If for some reason
the python utils library does not define the relevant function, without
this patch the script fails entirely; with it, each individual test
class that depends on the missing regex will fail each test case.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:22:04 -07:00
Steve Beattie
6d34893d4d utils: add limited support for af_unix rules
This patch adds limited support for af_unix rules in the python
utilities, of the "don't touch them, but don't throw a python backtrace
when coming across them, either" variety. Testcases are added as well.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:18:33 -07:00
Steve Beattie
72cde9a4f4 utils/tests: fix bashisms in runtests-py2.sh
Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-09-03 13:00:33 -07:00
Jamie Strandboge
502e992c42 Update perl abstraction, logprof.conf, severity.db and tests for Debian/Ubuntu
perl multiarch paths

Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-08-20 19:14:24 -05:00
Seth Arnold
0ba4c8cd7e Ensure the that the {**,} and {,**} regexs are being properly parsed by
the Python tools.

Signed-off-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-08-14 10:51:42 -07:00
Christian Boltz
37ca3dd556 add some more globbing tests for globs with extension, including
filenames that contain a * wildcard and a .* regex wildcard.

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-07-28 20:16:04 +02:00
Steve Beattie
ab2ac92ecf utils: make all tests consistent in verbosity
This patch adjusts the verbosity of several of the utils tests,
to make them all consistently verbose.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-07-25 17:49:06 -07:00
Christian Boltz
dd3b6a8d4a Set PYTHONPATH=.. in runtests-py3.sh to make sure the tests use the in-
tree python modules.

Also remove "sys.path.append('../')" (and now-unused "import sys") from 
all tests that contain it for consistency and to make testing with the 
installed modules possible (even if we don't have a USE_SYSTEM option 
yet).


Acked-by: Steve Beattie <steve@nxnw.org>
2014-07-22 21:25:25 +02:00
Christian Boltz
a04a6bfdaf change severity_test.py and minitools_test.py to use the in-tree
profiles instead of the system profiles in /etc/apparmor.d/

Acked-by: Steve Beattie <steve@nxnw.org>
2014-07-17 15:59:57 +02:00
Christian Boltz
5f8b035a71 change runtests-py*.sh (scripts for manually running the utils/test/*.py
testcases) to
- sleep 10 seconds after each failed test to make failures more annoying
  ^W^W^W^Wgive people a chance to read failure details
- print a list of failed tests at the end

Also avoid duplicate code by letting runtests-py2.sh call runtests-py3.sh.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-07-17 15:47:18 +02:00
Tyler Hicks
d2b62fff47 utils: Handle unmount rules
Bug: https://bugs.launchpad.net/bugs/1325109

The parser will accept rules with either umount or unmount rule types.
The utils should follow suite.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-06-03 16:23:30 -05:00
Christian Boltz
e83d05e521 test the mountains and pay the dbusdriver a pivot_rootbeer
(in a more serious version: add some tests for dbus, *mount, signal, 
ptrace and pivot_root and make sure a space after the keyword is enforced.
The tools shouldn't accept a "dbusdriver" or "pivot_rootbeer" rule. ;-)

Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-04-26 13:10:44 +02:00
Tyler Hicks
876e30a3c5 utils: Simplify newly added test-regex_matches tests
Remove duplicated test code by adding a simple way for regex test
classes to declare a regex to use and a list of tuples consisting of
(line, expected_result). The setup_regex_tests() method generates test
methods for each tuple in a classes list. The test methods are based on
the regex_test() method, which performs the regex search and compares
the results to the expected_result.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-04-23 16:41:44 -05:00
Tyler Hicks
bd129145ad utils: Clean up file rule parsing
This patch backs out most of the changes from r2448 in favor of a better
approach.

The optional "file" keyword is handled under the pre-existing
RE_PROFILE_PATH_ENTRY regex and a new regex, RE_PROFILE_BARE_FILE_ENTRY,
is created for handling bare file rules.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-04-23 16:28:17 -05:00
Tyler Hicks
432bf597ae utils: Basic support for pivot_root rules
Bug: https://bugs.launchpad.net/bugs/1298678

This patch does bare bones parsing of pivot_root rules and stores the raw
strings for writing them out later. It is meant to be a simple change to
prevent aa.py from emitting a traceback when encountering pivot_root rules.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-By: Christian Boltz <apparmor@cboltz.de>
2014-04-23 15:41:03 -05:00
Tyler Hicks
496502b150 utils: Basic support for ptrace rules
Bug: https://bugs.launchpad.net/bugs/1300317

This patch does bare bones parsing of ptrace rules and stores the raw
strings for writing them out later. It is meant to be a simple change to
prevent aa.py from emitting a traceback when encountering ptrace rules.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-By: Christian Boltz <apparmor@cboltz.de>
2014-04-23 15:40:20 -05:00
Tyler Hicks
81c6fc9ff1 utils: Basic support for signal rules
Bug: https://bugs.launchpad.net/bugs/1300316

This patch does bare bones parsing of signal rules and stores the raw
strings for writing them out later. It is meant to be a simple change to
prevent aa.py from emitting a traceback when encountering signal rules.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-By: Christian Boltz <apparmor@cboltz.de>
2014-04-23 15:39:14 -05:00
Tyler Hicks
54a24c2b6a utils: Basic support for file prefix in path rules
Bug: https://bugs.launchpad.net/bugs/1295346

Add the ability to read and write path rules containing the file prefix.
This also includes bare "file," rules.

The ALL global is updated to include a preceding NUL char to eliminate
possibilities of a real file path colliding with the ALL global.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-04-03 21:58:59 -05:00
Steve Beattie
3ecb969a12 utils: add simple capability regex tests
This patch adds some simple tests of the capability regex in
apparmor/aa.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-03-20 12:38:37 -07:00
Tyler Hicks
e5d9d541f6 utils: Add very limited support for mount rules
Bug: https://bugs.launchpad.net/bugs/1294825

This patch is inspired by sbeattie's patch to add limited dbus rule
support. It adds does very dumb parsing of mount rules. Basically, it
stores mount, remount, and umount rules as raw strings wrapped in a
class.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-03-20 14:25:42 -05:00
Steve Beattie
d0edb879b8 utils/easyprof: fix regression test when apparmor-easyprof is not installed
Bug: https://bugs.launchpad.net/bugs/1294848

This patch fixes the testsuite for aa-easyprof when the easyprof
utilities and configuration files are not installed in the system.
What was happening was that verify_manifest was calling parse_args()
without the synthetic arguments created by the test case and passing
the result to AppArmorEasyProfile(). Because parse_args() didn't
have the synthetic arguments, it would parse the actual command line
arguments passed to the testscript, which of course didn't specify the
alternate configuration file location. This would work when easyprof
had been installed in the system, because the fallback configuration
file in /etc/apparmor/easyprof.conf would exist and specify template
and policy group locations. Without that, though, the tests would abort
due to not knowing the location of the templates and policy groups.

This patch fixes the issue by passing the synthetic argument list
to verify_manifest, which uses that when calling parse_args(). A
debugging statement that states which conffile is being used when
AppArmorEasyProfile is being instantiated.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-03-19 22:02:53 -07:00
Steve Beattie
579aa7cb3e utils: add simple parsing of multi-line rules [v3]
D-Bus rules in particular seem to get written as multi-line rules. This
patch adds very simple hackish support for multiple lines. Essentially,
what it does is if the parsing of a line doesn't match anything and
falls all the way through, it saves the line and prepends it to the next
line that occurs in the profile, but *only* if the line does not have a
trailing comma to indicate the end of a rule. If the trailing comma
exists, then it assumes that it's a rule that it doesn't understand and
aborts.

With this patch, the simpler tools (aa-enforce, aa-complain, etc.) can
parse policies containing multi-line rules to an extent and continue to
function correctly. Again, aa-logprof and aa-genprof may have issues on
the writing back of profiles, so some assistance testing here would be
appreciated.

Some testcases are added to exercise the regex that looks for a rule
with a trailing comma but can still handle rules that have (,) or {,}
in them.

Patch history:
  v1 - initial version
  v2 - simplify and rearrange rule-ending comma search regex, since
       we only care about the trailing comma
     - add a new regex to search for trailing comments to filter out
     - simplify reset of lastline variable
     - restructure tests into a new script, and add more tests
  v3 - add additional testcases, most of which are problematic and thus
       commented out :(

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-03-07 10:04:57 -08:00
Steve Beattie
0e33e27401 utils: add very limited dbus rule support
This patch adds very limited support for very dumb parsing of dbus
rules. Basically, it stores dbus rules as raw strings wrapped in
a class.

There's class structure to indicate how I'd like to see fuller future
support for dbus rules to be implemented and act as a guidepost for
how to handle most rules, moving away from the giant structure of
nested dictionaries. A stub test script is included as well, with a
modification to the make check target to set the PYTHONPATH to point
in the right place.

With this patch, aa-audit, aa-autodep, aa-complain, aa-disable,
and aa-enforce all function for me. aa-logprof and aa-genprof have
functionality issues for me at the moment (one of them dumps a
backtrace even without this patch), and I'm not sure the writing out
of dbus rules is completely implemented for modified profiles.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-03-07 09:58:54 -08:00
Steve Beattie
daf437f4e3 utils: don't delete tmpdir when debugging test-aa-easyprof.py
It's not useful to report the location of the temporary directory for
each test if you're going to immediately delete it.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-03-06 10:30:14 -08:00
Steve Beattie
07bcb79b1d utils: use realpath of tmpdir in test-aa-easyprof.py
The relative directory tests in test-aa-easyprof.py were failing when
TMPDIR pointed to a directory that was a symlink, because the generated
tmpdir path was not the same as the realpath that easyprof resolved to.
This patch sets the tmpdir to the realpath of the result of the
tempfile.mkdtemp() to avoid the issue.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-03-05 13:13:39 -08:00
Steve Beattie
6ceb2030f9 utils: more verbose fail messages for relative dir tests in test-aa-easyprof.py
Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-03-05 13:12:12 -08:00
Steve Beattie
6cf4cbea21 utils: remove aa-enforce '--remove' option
This patch removes the '--remove' option on aa-enforce as well as from
the man page. It also removes the test entry that contains it, but I
don't think this is entirely correct because I think the second half
of the test is dependent on the (now deleted) first half of the test.

(It also removes a missed reference to --revert in the aa-disable man
page.)

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-03-03 14:59:47 -08:00
Steve Beattie
3575ca4ac9 utils: remove aa-disable non-functional '-r' option
This patch removes the non-funcional -r option for aa-disable, as
well as the test and manpage documentation for it.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-03-03 13:29:32 -08:00
Steve Beattie
4f8dea0db8 utils: make test-aa-easyprof.py cope with UsrMove
The test-aa-easyprof.py script has '/bin/ls' hardcoded as a path;
however, on systems that have undergone UsrMove, this is a symlink to
/usr/bin/ls. This patch fixes the issue by getting the realpath of
/bin/ls and storing it as an instance field.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-03-03 13:26:41 -08:00
Kshitij Gupta
781d237798 Fix tests for new tools.
Update path to tools in minitools_test.py
Fix assert values in config_test.py

Signed-off: Kshitij Gupta <kgupta8592@gmail.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-02-28 16:09:00 +05:30
Steve Beattie
5045d74716 utils: add common symlink to test/ clean target, to compensate for
packaging systems that do a make clean while trying to represent
changes.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-02-27 16:47:06 -08:00
Steve Beattie
0dede73da8 utils: fix path in test-aadecode.py and push make check into the test/
subdirectory.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-02-27 16:23:35 -08:00
Steve Beattie
7fab3a7a69 Sync with trunk. 2014-02-14 14:47:18 -08:00
Seth Arnold
b432cf45c9 Add aa-easyprof and easyprof.py and related pieces from the Ubuntu
apparmor packaging.

These were originally 0030-easyprof-sdk.patch and
0037-easyprof-sdk-pt2.patch. Jamie posted an updated
0030-easyprof-sdk_v2.patch and I squashed both patches into one commit.

Acked-By: Jamie Strandboge <jamie@canonical.com>
2014-02-13 17:53:40 -08:00
Steve Beattie
f54a574ee4 utils/: fix last make check failure, though the new utils tests need to
be added in (but they have failures themselves currently)
2014-02-13 11:32:36 -08:00
Steve Beattie
32e0931588 Fix up execute permissions that were lost in the merger for some reason. 2014-02-12 16:59:27 -08:00
Steve Beattie
f989dd0132 Merge in Kshitij Gupta <kgupta8592@gmail.com>'s rewrite of the
logprof/genprof and related utilities in python. Because the branch that
was worked on was not based on the apparmor tree, not all of the history
can be maintained for files that are not newly created or entirely
rewritten in the branch.

(This merge also includes a subsequent commit to the branch
I was merging from which includes my missed bzr add of
utils/apparmor/translations.py)
2014-02-12 15:54:00 -08:00
Steve Beattie
8e70fdcdfd Subject: aa-decode test script v3
This patch adds a test script/driver for the aa-decode utility. The only
change from the previous versions is to support overriding the location
of the aa-decode to test via the APPARMOR_DECODE environment variable
and documenting the utils/ tests in the top level README.

The aa-decode test can be run directly from the commandline in the utils
directory like so:

  test/test-aa-decode.py -v

Signed-off-by: Steve Beattie <sbeattie@ubuntu.com>
Acked-By: Christian Boltz <apparmor@cboltz.de>
2012-11-05 17:27:20 -08:00
Dmitrijs Ledkovs
dac3c00862 Initial port to python3 for utilities. 2012-06-11 17:56:21 +01:00
Jamie Strandboge
d418a16703 mark easyprof and easyprof test scripts as executable 2012-05-09 11:05:07 -07:00
Jamie Strandboge
1db463f4de This patchset is broken into 4 parts:
* the application, library, documentation and installation script
* the initial templates and policy groups. This will undoubtedly need
  refinement as we get feedback from users. Initial policy is based on Ubuntu's
  Application Review Board (ARB) requirements[2].
* tests for the library
* Makefile integration

Templates are stored in /usr/share/apparmor/easyprof/templates and policy
groups in /usr/share/apparmor/easyprof/policygroups. This can be adjusted via
/etc/apparmor/easyprof.conf.

The aa-easyprof.pod has complete documentation on usage with some
additional information in utils/easyprof/README (mostly duplicated
here).

Testing can be performed in a number of ways:
$ cd utils ; make check # runs unit tests and pyflakes

Unit tests manually:
$ ./test/test-aa-easyprof.py

In source manual testing:
$ ./aa-easyprof --templates-dir=./easyprof/templates \
                --policy-groups-dir=./easyprof/policygroups \
                ... \
                /opt/foo/bin/foo

Post-install manual testing:
$ make DESTDIR=/tmp/test PERLDIR=/tmp/test/usr/share/perl5/Immunix install
$ cd /tmp/test
$ PYTHONPATH=/tmp/test/usr/local/.../dist-packages ./usr/bin/aa-easyprof \
    --templates-dir=/tmp/test/usr/share/apparmor/easyprof/templates \
    --policy-groups-dir=/tmp/test/usr/share/apparmor/easyprof/policygroups \
    /opt/bin/foo

(you may also adjust /tmp/test/etc/apparmor/easyprof.conf to avoid
specifying --templates-dir and --policy-groups-dir).

Committing this now based on conversation with John and Steve.

Acked-By: Jamie Strandboge <jamie@canonical.com>
2012-05-07 22:37:48 -07:00