~apparmor-dev/apparmor/apparmor-ubuntu-citrain-trusty

« back to all changes in this revision

Viewing changes to utils/test/severity_test.py

  • Committer: Seth Arnold
  • Date: 2014-03-12 02:05:16 UTC
  • mto: This revision was merged to the branch mainline in revision 1496.
  • Revision ID: seth.arnold@canonical.com-20140312020516-zjike3pmw6hi861h
[ Jamie Strandboge ]
 * debian/debhelper/dh_apparmor: exit with error if aa-easyprof does not
   exist
 * debian/control: drop Depends on apparmor-easyprof to Suggests for
   dh-apparmor
[ Seth Arnold, Jamie Strandboge, Steve Beattie, John Johansen, Tyler Hicks ]
* New upstream snapshot (LP: #1278702, #1061693, #1285653) dropping very
  large Ubuntu delta and fixing the following bugs:
  - Adjust fonts abstraction for libthai (LP: #1278702)
  - Support translated XDG user directories (LP: #1061693)
  - Adjust abstractions/web-data to include /var/www/html (LP: #1285653)
    Refresh 0002-add-debian-integration-to-lighttpd.patch to include
    /etc/lighttpd/conf-available/*.conf
  - Adjust debian/libapparmor1.symbols to reflect new upstream versioning
    for the aa_query_label() function
  - Raise exceptions in Python bindings when something fails
* ship new Python replacements for previous Perl-based tools
  - debian/apparmor-utils.install: remove usr/share/perl5/Immunix/*.pm and add
    usr/sbin/aa-autodep, usr/sbin/aa-cleanprof and usr/sbin/aa-mergeprof
  - debian/control:
    + remove various Perl dependencies
    + add python-apparmor and python3-apparmor
    + python3-apparmor Breaks: apparmor-easyprof to move the file since it
      ships dist-packages/apparmor/__init__.py now
  - debian/apparmor-utils.manpages: ship new manpages for aa-cleanprof and
    aa-mergeprof
  - debian/rules: build and install Python tools
* debian/apparmor.install:
  - install apparmorfs, dovecot, kernelvars, securityfs, sys,
    and xdg-user-dirs tunables and xdg-user-dirs.d directory
* debian/apparmor.dirs:
  - install /etc/apparmor.d/tunables/xdg-user-dirs.d
* debian/apparmor.postinst: create xdg-user-dirs.d
* debian/apparmor.postrm: remove xdg-user-dirs.d
* Remaining patches:
  - 0001-add-chromium-browser.patch
  - 0002-add-debian-integration-to-lighttpd.patch
  - 0003-ubuntu-manpage-updates.patch
  - 0004-libapparmor-layout-deb.patch (renamed from 0008)
  - 0005-libapparmor-mention-dbus-method-in-getcon-man.patch (renamed from
    0068)
  - 0006-etc-writable.patch (renamed from 0070)
  - 0007-aa-utils_are_bilingual.patch (renamed from 0077)
  - 0008-remove-ptrace.patch
  - 0009-convert-to-rules.patch
  - 0010-list-fns.patch
  - 0011-parse-mode.patch
  - 0012-add-decimal-interp.patch
  - 0013-policy_mediates.patch
  - 0014-fix-failpath.patch
  - 0015-feature_file.patch
  - 0016-fix-network.patch
  - 0017-aare-to-class.patch
  - 0018-add-mediation-unix.patch
  - 0019-parser_version.patch
  - 0020-caching.patch
  - 0021-label-class.patch
  - 0022-signal.patch
  - 0023-fix-lexer-debug.patch
  - 0024-ptrace.patch
  - 0025-use-diff-encode.patch
  - 0026-fix-serialize.patch
  - 0027-fix-af.patch
  - 0028-opt_arg.patch
  - 0029-tests-cond-dbus.patch
  - 0030-tests.diff
* Move manpages from libapparmor1 to libapparmor-dev
  - debian/libapparmor-dev.manpages: install aa_change_hat.2,
    aa_change_profile.2, aa_find_mountpoint.2, aa_getcon.2
  - debian/control: libapparmor-dev Replaces: and Breaks: libapparmor1
* Move /usr/lib/python3/dist-packages/apparmor/__init__.py from
  apparmor-easyprof to python3-apparmor
  - debian/control: python3-apparmor Breaks: apparmor-easyprof
  - debian/apparmor-easyprof.install: remove
    usr/lib/python*.*/site-packages/apparmor*
* New profiles and abstractions:
  - debian/apparmor.install: tunables/dovecot, tunables/kernelvars,
    tunables/xdg-user-dirs, tunables/xdg-user-dirs.d
* Test merge from upstream new pyutils branch (rev 2385)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ----------------------------------------------------------------------
 
2
#    Copyright (C) 2013 Kshitij Gupta <kgupta8592@gmail.com>
 
3
#
 
4
#    This program is free software; you can redistribute it and/or
 
5
#    modify it under the terms of version 2 of the GNU General Public
 
6
#    License as published by the Free Software Foundation.
 
7
#
 
8
#    This program is distributed in the hope that it will be useful,
 
9
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
#    GNU General Public License for more details.
 
12
#
 
13
# ----------------------------------------------------------------------
 
14
import os
 
15
import shutil
 
16
import sys
 
17
import unittest
 
18
 
 
19
sys.path.append('../')
 
20
 
 
21
import apparmor.severity as severity
 
22
from apparmor.common import AppArmorException
 
23
 
 
24
class Test(unittest.TestCase):
 
25
 
 
26
    def setUp(self):
 
27
        #copy the local profiles to the test directory
 
28
        if os.path.exists('./profiles'):
 
29
            shutil.rmtree('./profiles')
 
30
        shutil.copytree('/etc/apparmor.d/', './profiles/', symlinks=True)
 
31
 
 
32
    def tearDown(self):
 
33
        #Wipe the local profiles from the test directory
 
34
        shutil.rmtree('./profiles')
 
35
 
 
36
    def testRank_Test(self):
 
37
        sev_db = severity.Severity('severity.db')
 
38
        rank = sev_db.rank('/usr/bin/whatis', 'x')
 
39
        self.assertEqual(rank, 5, 'Wrong rank')
 
40
        rank = sev_db.rank('/etc', 'x')
 
41
        self.assertEqual(rank, 10, 'Wrong rank')
 
42
        rank = sev_db.rank('/dev/doublehit', 'x')
 
43
        self.assertEqual(rank, 0, 'Wrong rank')
 
44
        rank = sev_db.rank('/dev/doublehit', 'rx')
 
45
        self.assertEqual(rank, 4, 'Wrong rank')
 
46
        rank = sev_db.rank('/dev/doublehit', 'rwx')
 
47
        self.assertEqual(rank, 8, 'Wrong rank')
 
48
        rank = sev_db.rank('/dev/tty10', 'rwx')
 
49
        self.assertEqual(rank, 9, 'Wrong rank')
 
50
        rank = sev_db.rank('/var/adm/foo/**', 'rx')
 
51
        self.assertEqual(rank, 3, 'Wrong rank')
 
52
        rank = sev_db.rank('CAP_KILL')
 
53
        self.assertEqual(rank, 8, 'Wrong rank')
 
54
        rank = sev_db.rank('CAP_SETPCAP')
 
55
        self.assertEqual(rank, 9, 'Wrong rank')
 
56
        self.assertEqual(sev_db.rank('/etc/apparmor/**', 'r') , 6,  'Invalid Rank')
 
57
        self.assertEqual(sev_db.rank('/etc/**', 'r') , 10,  'Invalid Rank')
 
58
 
 
59
        # Load all variables for /sbin/klogd and test them
 
60
        sev_db.load_variables('profiles/sbin.klogd')
 
61
        self.assertEqual(sev_db.rank('@{PROC}/sys/vm/overcommit_memory', 'r'), 6, 'Invalid Rank')
 
62
        self.assertEqual(sev_db.rank('@{HOME}/sys/@{PROC}/overcommit_memory', 'r'), 10, 'Invalid Rank')
 
63
        self.assertEqual(sev_db.rank('/overco@{multiarch}mmit_memory', 'r'), 10, 'Invalid Rank')
 
64
 
 
65
        sev_db.unload_variables()
 
66
 
 
67
        sev_db.load_variables('profiles/usr.sbin.dnsmasq')
 
68
        self.assertEqual(sev_db.rank('@{PROC}/sys/@{TFTP_DIR}/overcommit_memory', 'r'), 6, 'Invalid Rank')
 
69
        self.assertEqual(sev_db.rank('@{PROC}/sys/vm/overcommit_memory', 'r'), 6, 'Invalid Rank')
 
70
        self.assertEqual(sev_db.rank('@{HOME}/sys/@{PROC}/overcommit_memory', 'r'), 10, 'Invalid Rank')
 
71
        self.assertEqual(sev_db.rank('/overco@{multiarch}mmit_memory', 'r'), 10, 'Invalid Rank')
 
72
 
 
73
        #self.assertEqual(sev_db.rank('/proc/@{PID}/maps', 'rw'), 9, 'Invalid Rank')
 
74
 
 
75
    def testInvalid(self):
 
76
        sev_db = severity.Severity('severity.db')
 
77
        rank = sev_db.rank('/dev/doublehit', 'i')
 
78
        self.assertEqual(rank, 10, 'Wrong')
 
79
        try:
 
80
            severity.Severity('severity_broken.db')
 
81
        except AppArmorException:
 
82
            pass
 
83
        rank =  sev_db.rank('CAP_UNKOWN')
 
84
        rank =  sev_db.rank('CAP_K*')
 
85
 
 
86
 
 
87
 
 
88
if __name__ == "__main__":
 
89
    #import sys;sys.argv = ['', 'Test.testName']
 
90
    unittest.main()