Commit graph

37 commits

Author SHA1 Message Date
Christian Boltz
0d5ae170d4
Add parser_sanity-no-gen target to run simple_tests
... without all the profiles generated by the gen-*.py scripts.

This target is meant for local manual testing, especially when working
on additional simple_tests profiles.

It makes local testing much faster (15 seconds for ~2k profiles vs.
several minutes for the additional ~70k profiles generated by gen-*.py)

Needless to say that the CI should continue to use the parser_sanity
target that includes all the generated profiles.
2024-09-10 22:31:11 +02:00
John Johansen
acc6ba1cb7 libapparmor: fix handling of failed symlink traversal
Ideally we would have a flag or something so the caller could choose
to handle symlinks, or traverse them. But since all callers currently
don't handle symlinks just handle them in the iterator.

Beyond fixing the early termination due to a failed symlink this also
fixes another case of failure in one job cause dir based loads to
terminate early. Which can result in partial loads.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/215
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/850
Signed-off-by: John Johansen <john.johansen@canonical.com>
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-02-27 00:55:41 -08:00
Christian Boltz
2b00d21e2e
Rewrite gen-dbus in python
The generated files are exactly the same.
2021-04-25 18:31:38 +02:00
Christian Boltz
6b96a9badc
Convert gen-xtrans from perl to python
The generated files are exactly the same, but the code is a bit more
readable.

Additional differences:
- added test_gen_list() to verify the result of gen_list()
- null_target has a non-empty value to avoid that it gets skipped in
  loops as empty value
- invert_save has an additional entry for ''
- copyright header added (based on git log of gen-xtrans.pl)
2020-10-26 00:28:16 +01:00
Steve Beattie
5574af0390
parser tests: convert makefile error tests to python script
Make the error and warning message tests a first class test script; in
gitlab CI, failures would not necessarily result in output being
captured.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/522
2020-05-08 15:44:41 -07:00
Steve Beattie
08c6c6eecf parser error tests: add filename profile deprecation checks
This add a couple of tests for
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/506

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-05-05 02:16:23 -07:00
Christian Boltz
e9b25c4969
make simple.pl / parser make check output more useful
Instead of printing the (useless) numbers of no-longer-failing tests
marked as TODO, let `prove` print out the actual test names.

A side effect is that really unfixed TODOs and disabled tests get
printed (lists about 10 tests), but that's much better than having to
hunt down the no-longer-failing TODOs.

This change will print out lines like (the first one is still a TODO,
the second one got fixed at some time)

```
not ok 71447 - TODO: ./simple_tests//vars/vars_profile_name_13.sd: reference variables that are the profile name and attachment # TODO Unfixed testcase.
ok 71448 - TODO: ./simple_tests//vars/vars_profile_name_14.sd: reference variables in rules that also have alternations # TODO Unfixed testcase.
```

before printing the test summary.
2018-09-18 21:42:14 +02:00
Christian Boltz
5a18fd7c89
use empty parser/tst/parser.conf in all parser tests
Without this, the system-wide parser.conf gets used, which causes test
failures if for example caching is enabled and the cache dir isn't
writeable for the user running the tests.
2018-09-16 21:58:28 +02:00
Tyler Hicks
19c6c3310b all: Use the MAKE variable
https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.html

We should be using the $(MAKE) variable when calling the make command
from Makefiles since we use Makefile recursion.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2017-11-01 23:22:53 +00:00
Steve Beattie
573cfb6b04 fix two issues for older releases
The following patch addresses two issues on older releases:

1) In trunk commit 2911, the line 'undefine VERBOSE' was added to
   parser/tst/Makefile so that the equality tests would not generate
   verbose output when $VERBOSE != 1. Unfortunately, the 'undefine'
   keyword was not introduced in GNU Make until version 3.82. On
   distro releases like Ubuntu 12.04 LTS that include versions of Make
   older than that, make check and make clean abort when VERBOSE is
   not set to 1. The patch fixes that by setting VERBOSE to a zero
   length string if does not already equal 1.

2) In trunk commit 2923, a workaround for systemd as init was added
   to the pivot_root regression test. The workaround included a
   call to ps(1) to determine if systemd is pid 1. Unfortunately,
   in older versions of the procps package (such as the version in
   Ubuntu 12.04 LTS), 'ps -hp1' emits the warning

     Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html

   The patch below converts the ps call to 'ps hp1' which does not
   generate the warning.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2015-03-31 02:46:45 -07:00
Steve Beattie
cecbcb0912 parser: make equality.sh honor env variable VERBOSE
- make the verbose output of equality.sh honor whether or not
  the environment variable VERBOSE is set

- thereby making the output verbose when 'make check V=1' or 'make
  check VERBOSE=1' is given from within the parser/ directory. This
  will make distribution packagers happy when diagnosing build
  failures caused by test failures.

- if verbose output is not emitted and the tests were successful, emit
  a newline before printing PASS.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2015-03-23 11:45:45 -07:00
Steve Beattie
7a42de3eae parser: add build option for coverage (v3)
This patch adds a parser make variable and a make target for building
the compiler with coverage compilation flags. With this, coverage
information can be generated by running tests/test suites against the
built parser and run through tools like gcovr.

Patch History:
  v1: initial version
  v2: refreshed/no change
  v3: address feedback from sarnold:
      - mark coverage target as phony
      - correct missing '.' typo in clean target
      - make coverage extensions consistent in clean targets

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2013-12-06 05:31:11 -08:00
Steve Beattie
73a5f13175 parser: mark valgrind test target as phony
Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-By: Christian Boltz <apparmor@cboltz.de>
2013-12-03 15:37:57 -08:00
Steve Beattie
cfd8478ba4 parser - use new caching test script
This patch:
 - incorporates the new python caching test into the make check/make
   caching target, and removes the older shell based test script
 - adjusts the python scripts to give verbose output when the VERBOSE
   flag is set
 - reorders the tests so that the tests that take a shorter amount of
   time to run come first, leaving the language sanity test with its
   69000+ testcases last

Patch history:
  v1: initial revision
  v2: add gen_xtrans/gen_dbus dependency to valgrind test
  v3: drop gen_xtrans/gen_dbus as that was committed as a separate fix

Acked-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2013-11-27 21:25:06 -08:00
Tyler Hicks
89bae9e64b parser: Add gen_dbus test target to the .PHONY list
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2013-11-04 08:54:08 -08:00
Steve Beattie
5593678542 parser tests - fix dependency for parallel builds
The parser sanity test make target does not directly depend on the make
targets that generate the tests consumed by the sanity test, leading to
runs that did not verify all the test cases when make check is invoked
with parallelism (e.g. make check -j4). This patch against trunk fixes
the issue.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2013-10-31 12:04:12 -07:00
Steve Beattie
5c2bea1b4f parser - add simple valgrind wrapper tests
This patch adds a test wrapper that runs valgrind on the parser over the
simple_tests tree (or other directory tree if passed on the command
line). An alternate parser location can also be passed on the command
line.

Like the libapparmor python bindings test, this test uses a bit of magic
to generate tests that doesn't work with auto-detecting test utilities
like nose.

Running valgrind on the parser over all 69000+ testcases takes several
hours, so while this patch includes a make target 'make valgrind', it
does not add it to the set of tests run when 'make check' is called.
Perhaps a 'make extra-tests' target is in order.

Patch history:
  v1: - initial version.
  v2: - add some valgrind suppressions for overaggressive 4 byte reads
        past the end of allocated storage (not completed).
  v3: - add ability to dump valgrind suppressions to stdout, to use
        diagnosis runs of valgrind for determining whether a given
        failure is a false positive or not.
      - correctly return 0 on a successful run and an error code if one
        or more test cases fail.
      - point LD_LIBRARY_PATH at the in-tree libapparmor build.
      - split out some utility functions into testlib.py, for possible
        use by other to be written test scripts
  v4: - convert optparse to argparse

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com> (for v2 version)
2013-10-15 17:06:26 -07:00
Steve Beattie
aa53ef66e2 parser - build against in-tree libapparmor
With trunk commit 2205 "use libapparmor's find mountpoint fn",
the parser now builds against and uses libapparmor at runtime. However,
it currently builds against the system installed libapparmor library and
header files, which fails if either aren't installed, and is thus
painful for bootstrapping in a new environment.

Instead, the parser, like pam_apparmor and mod_apparmor, should build
against the in-tree libapparmor header and library. This patch does
that and adjusts the tests to point LD_LIBRARY_PATH at the location
of the built library as well.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2013-10-15 16:46:18 -07:00
Tyler Hicks
7c817bde70 parser: Binary profile equality tests for DBus rules
This test is to verify that a list of profiles compile down into the
same binary representation. This is useful, for example, when testing a
rule syntax that includes permission aliases, as well as implied and
explicit accesses.
    
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2013-07-31 09:22:11 -07:00
Tyler Hicks
670a1815ed parser: Regression tests for DBus rules
This is a test in the style of gen-xtrans.pl that attempts to run
through the most commonly constructed DBus rules. It also attempts to
run through some common mistakes to ensure that the parser fails
appropriately.
    
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2013-07-31 09:20:56 -07:00
Steve Beattie
4791fb1bc8 Subject: parameterize parser tests to support different binaries
This patch replaces the hardcoded path to the in-tree apparmor parser
in several of the script based test scripts with the APPARMOR_PARSER
environment variable, keeping the hardcoded location as the default.
It also adds support for overriding the location of the parser via the
same environment variable. The make infrastructure is updated to use
this, though uses a different variable (PARSER) to drive it.

Thus 'make check PARSER=/some/path/to/an/alternate/apparmor_parser'
will run all the parser tests on that binary. This is useful for
running the testsuite in an automated post-install environment.
(It should be noted that doing so will still build and run the unit
test binaries based on the source tree.)

Signed-off-by: Steve Beattie <sbeattie@ubuntu.com>
Acked-By: John Johansen <john.johansen@canonical.com>
2012-11-05 17:22:37 -08:00
John Johansen
5e361a4a05 Fix dfa minimization to deal with exec conflicts
Minimization was failing because it was too agressive.  It was minimizing
as if there was only 1 accept condition.  This allowed it to remove more
states but at the cost of loosing unique permission sets, they where
being combined into single commulative perms.  This means that audit,
deny, xtrans, ... info on one path would be applied to all other paths
that it was combined with during minimization.

This means that we need to retain the unique accept states, not allowing
them to be combined into a single state.  To do this we put each unique
permission set into its own partition at the start of minimization.

The states within a partition have the  same permissions and can be combined
within the other states in the partition as the loss of unique path
information is will not result in a conflict.

This is similar to what perm hashing used to do but deny information is
still being correctly applied and carried.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2012-03-09 04:20:19 -08:00
Steve Beattie
d4c4cbe62b It's possible that git doesn't like to create empty directories, so
create the generated_* directories themselves if they don't exist before
running the script to generate them.

Also modify the default invocation of prove to add -f, which reports the
details of failing test cases.
2011-08-09 01:10:19 -07:00
Kees Cook
1644ce31e7 Description: Improve generated test readability and build-time cleanup.
Author: Kees Cook <kees@debian.org>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2011-05-02 13:36:55 -07:00
Kees Cook
a6dc414f57 adjust line offset now that $Id$ was removed 2010-12-20 13:06:54 -08:00
John Johansen
77be2c450f Add the safe xtransition key word
Currently apparmor provides the unsafe keyword to indicate an xtransition
is not scrubbing its environment variables.  This can be used to be
explicit about which transition are unsafe instead of relying on people
remembering which of px Px is safe or unsafe.

Add the orthogonal keyword safe to allow specifying a transition is
safe.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-12-20 11:58:05 -08:00
John Johansen
a29078ac04 Add auto generation of tests to verify leading and trailing perms for xrules
Test the leading permission form of an xrule against its trailing permission
form, to verify that they are generating the same xtransition and thus
don't conflict (assumes xtransition conflict checking is working).
  eg.
    px /foo,
    /foo px,

should generate the same rule and thus not result in any conflicts

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-12-20 11:54:27 -08:00
John Johansen
851b7655c1 Add auto generation of xtransition conflict tests
All the combiniation of xtransition conflics where not well represented in
the regression test suite.  Instead of relying on multiple static test
files, automatically generate all possible conflicts.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-12-20 11:53:52 -08:00
Kees Cook
862836548d Fix write_cache to not be a privileged operation so that the caching tests
can be added to the build. Update caching tests to detect non-ns-resolution
filesystems and back off on the timing test.
2010-09-14 12:45:34 -07:00
Steve Beattie
2d2897f426 This patch adds a couple of additional lineno reporting testcases:
* a non-include related syntax error (errors/modefail.sd)
  * multiple successful includes followed by a failed include
    (errors/multi_include.sd)

It also fixes two issues with the parser's line counting:

  * the count began at 0 (demonstrated by the first testcase's error
    being reporting on one line less than it should be), and

  * an extra line increment when includes were detected (demonstrated
    by the second testcase's error being reported at a line beyond the
    correct linenumber.

The existing testcases did not catch these because they were all
based on the first include in the file failing and so the start of
the count from 0 counteracted the extra counted line.
2010-06-25 12:43:48 -07:00
Kees Cook
7cfc7e1133 add correct line number and filename tracking for error conditions (LP: #588014)
Bug: https://launchpad.net/bugs/588014
2010-06-04 18:47:44 -07:00
Steve Beattie
90c9b5c0cd This patch fixes the apparmor parser tst Makefile to not use popd/pushd
bashisms which were in place to get around PWD not getting set
correctly. Instead, fix the simple.pl script to call pwd directly.
Based on feedback from PLD/Arkadiusz Miskiewicz <arekm@maven.pl>.
2006-12-15 08:10:25 +00:00
Steve Beattie
08a4b5ce52 Set svn keyword properties on a couple of missed files. 2006-05-31 21:44:14 +00:00
Steve Beattie
dd2d41bae8 Make the build process significantly quieter with respect to the unit
and regression tests to avoid developer confusion.
2006-05-31 21:30:50 +00:00
Steve Beattie
84ff459a53 Default to using the parser in the parent directory, and build it if it
doesn't exist.
2006-05-02 17:19:50 +00:00
Steve Beattie
1b56f269dd This change does a few things:
- adds a distinct includes/ subdirectory, populated with a couple of
    files that test profiles can include. We purposefully choose to use
    a different directory structure than the shipped profile set so that
    changes to it will not break our tests.
  - modifies the existing test profiles to take advantage of the
    includes/ directory.
  - modifies tst/Makefile with pushd/popd to get around some pwd
    limitations in the parser (that need to be fixed).
2006-05-02 16:15:41 +00:00
Steve Beattie
bc9d0ee80b MOve the parser regression tests to the parser package itself. 2006-04-13 20:38:37 +00:00
Renamed from tests/regression/parser/Makefile (Browse further)