~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to utils/test/test-regex_matches.py

  • Committer: Package Import Robot
  • Author(s): Steve Beattie
  • Date: 2015-07-23 01:57:43 UTC
  • mfrom: (1.1.32)
  • Revision ID: package-import@ubuntu.com-20150723015743-q1nfat496q3d8rcm
Tags: 2.10-0ubuntu1
* Update to apparmor 2.10
  - libapparmor added functions to ease loading profile cache files to
    help support systemd on-demand load of policy (LP: #1385414)
  - apparmor parser: fixed policy generation to allow matching
    embedded NULs in abstract unix socket names (LP: #1413410)
  - aa-status: don't traceback when not permitted to read current
    set of apparmor policy (LP: #1466768)
  - aa-logprof: don't crash on policies that have an #include of a
    directory (LP: #1471425)
  - aa-logprof: fix crash when network rejections occur when file
    operations are performed on network sockets (LP: #1466812)
* dropped reproducible-pdf.patch, incorporated upstream
* debian/patches/tests-fix_sysctl_test.patch: fix sysctl test failure
  with 4.1 kernel and newer.
* debian/control: add alternate dependency on linux-initramfs-tool
  (LP: #1109029)
* debian/libapparmor1.symbols: update symbols file for added symbols
  in libapparmor

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import apparmor.aa as aa
13
13
import unittest
14
14
from common_test import AATest, setup_all_loops
15
 
from apparmor.common import AppArmorBug
 
15
from apparmor.common import AppArmorBug, AppArmorException
16
16
 
17
 
from apparmor.regex import strip_quotes, parse_profile_start_line, RE_PROFILE_START
 
17
from apparmor.regex import strip_quotes, parse_profile_start_line, re_match_include, RE_PROFILE_START, RE_PROFILE_CAP
18
18
 
19
19
 
20
20
class AARegexTest(AATest):
203
203
class AARegexCapability(AARegexTest):
204
204
    '''Tests for RE_PROFILE_CAP'''
205
205
 
206
 
    def setUp(self):
207
 
        self.regex = aa.RE_PROFILE_CAP
 
206
    def AASetup(self):
 
207
        self.regex = RE_PROFILE_CAP
208
208
 
209
209
    tests = [
210
210
        ('   capability net_raw,', (None, None, 'net_raw', 'net_raw', None)),
218
218
class AARegexPath(AARegexTest):
219
219
    '''Tests for RE_PROFILE_PATH_ENTRY'''
220
220
 
221
 
    def setUp(self):
 
221
    def AASetup(self):
222
222
        self.regex = aa.RE_PROFILE_PATH_ENTRY
223
223
 
224
224
    tests = [
237
237
class AARegexBareFile(AARegexTest):
238
238
    '''Tests for RE_PROFILE_BARE_FILE_ENTRY'''
239
239
 
240
 
    def setUp(self):
 
240
    def AASetup(self):
241
241
        self.regex = aa.RE_PROFILE_BARE_FILE_ENTRY
242
242
 
243
243
    tests = [
255
255
class AARegexDbus(AARegexTest):
256
256
    '''Tests for RE_PROFILE_DBUS'''
257
257
 
258
 
    def setUp(self):
 
258
    def AASetup(self):
259
259
        self.regex = aa.RE_PROFILE_DBUS
260
260
 
261
261
    tests = [
271
271
class AARegexMount(AARegexTest):
272
272
    '''Tests for RE_PROFILE_MOUNT'''
273
273
 
274
 
    def setUp(self):
 
274
    def AASetup(self):
275
275
        self.regex = aa.RE_PROFILE_MOUNT
276
276
 
277
277
    tests = [
295
295
class AARegexSignal(AARegexTest):
296
296
    '''Tests for RE_PROFILE_SIGNAL'''
297
297
 
298
 
    def setUp(self):
 
298
    def AASetup(self):
299
299
        self.regex = aa.RE_PROFILE_SIGNAL
300
300
 
301
301
    tests = [
321
321
class AARegexPtrace(AARegexTest):
322
322
    '''Tests for RE_PROFILE_PTRACE'''
323
323
 
324
 
    def setUp(self):
 
324
    def AASetup(self):
325
325
        self.regex = aa.RE_PROFILE_PTRACE
326
326
 
327
327
    tests = [
343
343
class AARegexPivotRoot(AARegexTest):
344
344
    '''Tests for RE_PROFILE_PIVOT_ROOT'''
345
345
 
346
 
    def setUp(self):
 
346
    def AASetup(self):
347
347
        self.regex = aa.RE_PROFILE_PIVOT_ROOT
348
348
 
349
349
    tests = [
370
370
class AARegexUnix(AARegexTest):
371
371
    '''Tests for RE_PROFILE_UNIX'''
372
372
 
373
 
    def setUp(self):
 
373
    def AASetup(self):
374
374
        self.regex = aa.RE_PROFILE_UNIX
375
375
 
376
376
    tests = [
395
395
class AANamedRegexProfileStart_2(AANamedRegexTest):
396
396
    '''Tests for RE_PROFILE_START'''
397
397
 
398
 
    def setUp(self):
 
398
    def AASetup(self):
399
399
        self.regex = RE_PROFILE_START
400
400
 
401
401
    tests = [
403
403
        ('/bin/foo /bin/bar', False), # missing 'profile' keyword
404
404
        ('profile {', False), # no attachment
405
405
        ('   profile foo bar /foo {', False), # missing quotes around "foo bar"
 
406
        ('bin/foo {', False), # not starting with '/'
 
407
        ('"bin/foo" {', False), # not starting with '/', quoted version
406
408
 
407
409
        ('   /foo {',                     { 'plainprofile': '/foo',    'namedprofile': None,          'attachment': None,     'flags': None,       'comment': None }),
408
410
        ('   "/foo" {',                   { 'plainprofile': '"/foo"',  'namedprofile': None,          'attachment': None,     'flags': None,       'comment': None }),
415
417
        ('   /foo (complain) {',          { 'plainprofile': '/foo',    'namedprofile': None,          'attachment': None,     'flags': 'complain', 'comment': None }),
416
418
        ('   /foo flags=(complain) {',    { 'plainprofile': '/foo',    'namedprofile': None,          'attachment': None,     'flags': 'complain', 'comment': None }),
417
419
        ('   /foo (complain) { # x',      { 'plainprofile': '/foo',    'namedprofile': None,          'attachment': None,     'flags': 'complain', 'comment': '# x'}),
 
420
        ('   /foo flags = ( complain ){#',{ 'plainprofile': '/foo',    'namedprofile': None,          'attachment': None,     'flags': ' complain ', 'comment': '#'}),
418
421
 
419
422
        ('   /foo {',                     { 'plainprofile': '/foo',     'namedprofile': None,   'leadingspace': '   ' }),
420
423
        ('/foo {',                        { 'plainprofile': '/foo',     'namedprofile': None,   'leadingspace': ''    }),
435
438
        ('   profile "foo bar" /foo {',   { 'profile': 'foo bar', 'profile_keyword': True,  'plainprofile': None, 'namedprofile': 'foo bar','attachment': '/foo', 'flags': None,    'comment': None }),
436
439
        ('   /foo (complain) {',          { 'profile': '/foo',    'profile_keyword': False, 'plainprofile': '/foo', 'namedprofile': None,   'attachment': None,   'flags': 'complain', 'comment': None }),
437
440
        ('   /foo flags=(complain) {',    { 'profile': '/foo',    'profile_keyword': False, 'plainprofile': '/foo', 'namedprofile': None,   'attachment': None,   'flags': 'complain', 'comment': None }),
 
441
        ('   /foo flags = ( complain ){', { 'profile': '/foo',    'profile_keyword': False, 'plainprofile': '/foo', 'namedprofile': None,   'attachment': None,   'flags': ' complain ', 'comment': None }),
438
442
        ('   /foo (complain) { # x',      { 'profile': '/foo',    'profile_keyword': False, 'plainprofile': '/foo', 'namedprofile': None,   'attachment': None,   'flags': 'complain', 'comment': '# x'}),
439
443
 
440
444
        ('   /foo {',                     { 'profile': '/foo',    'plainprofile': '/foo', 'namedprofile': None,  'leadingspace': '   ' }),
463
467
        with self.assertRaises(AppArmorBug):
464
468
            parse_profile_start_line(line, 'somefile')
465
469
 
 
470
class Test_re_match_include(AATest):
 
471
    tests = [
 
472
        ('#include <abstractions/base>',            'abstractions/base'         ),
 
473
        ('#include <abstractions/base> # comment',  'abstractions/base'         ),
 
474
        ('#include<abstractions/base>#comment',     'abstractions/base'         ),
 
475
        ('   #include    <abstractions/base>  ',    'abstractions/base'         ),
 
476
        ('include <abstractions/base>',             'abstractions/base'         ), # not supported by parser
 
477
        # ('include foo',                           'foo'                       ), # XXX not supported in tools yet
 
478
        # ('include /foo/bar',                      '/foo/bar'                  ), # XXX not supported in tools yet
 
479
        # ('include "foo"',                         'foo'                       ), # XXX not supported in tools yet
 
480
        # ('include "/foo/bar"',                    '/foo/bar'                  ), # XXX not supported in tools yet
 
481
        (' some #include <abstractions/base>',      None,                       ),
 
482
        ('  /etc/fstab r,',                         None,                       ),
 
483
    ]
 
484
 
 
485
    def _run_test(self, params, expected):
 
486
        self.assertEqual(re_match_include(params), expected)
 
487
 
 
488
class TestInvalid_re_match_include(AATest):
 
489
    tests = [
 
490
        ('#include <>',                             AppArmorException   ),
 
491
        ('#include <  >',                           AppArmorException   ),
 
492
    ]
 
493
 
 
494
    def _run_test(self, params, expected):
 
495
        with self.assertRaises(expected):
 
496
            re_match_include(params)
 
497
 
466
498
 
467
499
class TestStripQuotes(AATest):
468
500
    def test_strip_quotes_01(self):