mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-04 00:05:14 +00:00
replace RE_PROFILE_START
Replace RE_PROFILE_START with RE_PROFILE_START_2 and adjust all code sections that used RE_PROFILE_START_2. The only real change is that test_get_flags_invalid_01 and test_get_flags_invalid_02 now expect AppArmorException instead of AppArmorBug. Acked-by: Steve Beattie <steve@nxnw.org> for trunk
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# Copyright (C) 2013 Kshitij Gupta <kgupta8592@gmail.com>
|
# Copyright (C) 2013 Kshitij Gupta <kgupta8592@gmail.com>
|
||||||
# Copyright (C) 2014 Christian Boltz <apparmor@cboltz.de>
|
# Copyright (C) 2014-2015 Christian Boltz <apparmor@cboltz.de>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of version 2 of the GNU General Public
|
# modify it under the terms of version 2 of the GNU General Public
|
||||||
@@ -26,7 +26,6 @@ RE_OWNER = '(?P<owner>owner\s+)?' # optionally: <owner>
|
|||||||
RE_EOL = '\s*(?P<comment>#.*?)?\s*$' # optional whitespace, optional <comment>, optional whitespace, end of the line
|
RE_EOL = '\s*(?P<comment>#.*?)?\s*$' # optional whitespace, optional <comment>, optional whitespace, end of the line
|
||||||
RE_COMMA_EOL = '\s*,' + RE_EOL # optional whitespace, comma + RE_EOL
|
RE_COMMA_EOL = '\s*,' + RE_EOL # optional whitespace, comma + RE_EOL
|
||||||
|
|
||||||
RE_PROFILE_START = re.compile('^\s*("?(/.+?)"??|(profile\s+"?(.+?)"??))\s+((flags=)?\((.+)\)\s+)?\{' + RE_EOL)
|
|
||||||
RE_PROFILE_END = re.compile('^\s*\}' + RE_EOL)
|
RE_PROFILE_END = re.compile('^\s*\}' + RE_EOL)
|
||||||
RE_PROFILE_CAP = re.compile(RE_AUDIT_DENY + 'capability(?P<capability>(\s+\S+)+)?' + RE_COMMA_EOL)
|
RE_PROFILE_CAP = re.compile(RE_AUDIT_DENY + 'capability(?P<capability>(\s+\S+)+)?' + RE_COMMA_EOL)
|
||||||
RE_PROFILE_LINK = re.compile(RE_AUDIT_DENY + 'link\s+(((subset)|(<=))\s+)?([\"\@\/].*?"??)\s+->\s*([\"\@\/].*?"??)' + RE_COMMA_EOL)
|
RE_PROFILE_LINK = re.compile(RE_AUDIT_DENY + 'link\s+(((subset)|(<=))\s+)?([\"\@\/].*?"??)\s+->\s*([\"\@\/].*?"??)' + RE_COMMA_EOL)
|
||||||
@@ -62,7 +61,7 @@ RE_HAS_COMMENT_SPLIT = re.compile('^(?P<not_comment>' + __re_no_or_quoted_hash +
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
RE_PROFILE_START_2 = re.compile(
|
RE_PROFILE_START = re.compile(
|
||||||
'^(?P<leadingspace>\s*)' +
|
'^(?P<leadingspace>\s*)' +
|
||||||
'(' +
|
'(' +
|
||||||
'(?P<plainprofile>(/\S+|"[^"]+"))' + # just a path
|
'(?P<plainprofile>(/\S+|"[^"]+"))' + # just a path
|
||||||
@@ -73,7 +72,7 @@ RE_PROFILE_START_2 = re.compile(
|
|||||||
RE_EOL)
|
RE_EOL)
|
||||||
|
|
||||||
def parse_profile_start_line(line, filename):
|
def parse_profile_start_line(line, filename):
|
||||||
matches = RE_PROFILE_START_2.search(line)
|
matches = RE_PROFILE_START.search(line)
|
||||||
|
|
||||||
if not matches:
|
if not matches:
|
||||||
raise AppArmorBug('The given line from file %(filename)s is not the start of a profile: %(line)s' % { 'filename': filename, 'line': line } )
|
raise AppArmorBug('The given line from file %(filename)s is not the start of a profile: %(line)s' % { 'filename': filename, 'line': line } )
|
||||||
|
@@ -92,10 +92,10 @@ class AaTest_get_profile_flags(AaTestWithTempdir):
|
|||||||
self._test_get_flags('/foo flags=(complain, audit)', 'complain, audit')
|
self._test_get_flags('/foo flags=(complain, audit)', 'complain, audit')
|
||||||
|
|
||||||
def test_get_flags_invalid_01(self):
|
def test_get_flags_invalid_01(self):
|
||||||
with self.assertRaises(AppArmorBug):
|
with self.assertRaises(AppArmorException):
|
||||||
self._test_get_flags('/foo ()', None)
|
self._test_get_flags('/foo ()', None)
|
||||||
def test_get_flags_invalid_02(self):
|
def test_get_flags_invalid_02(self):
|
||||||
with self.assertRaises(AppArmorBug):
|
with self.assertRaises(AppArmorException):
|
||||||
self._test_get_flags('/foo flags=()', None)
|
self._test_get_flags('/foo flags=()', None)
|
||||||
def test_get_flags_invalid_03(self):
|
def test_get_flags_invalid_03(self):
|
||||||
with self.assertRaises(AppArmorException):
|
with self.assertRaises(AppArmorException):
|
||||||
|
@@ -14,7 +14,7 @@ import unittest
|
|||||||
from common_test import AATest, setup_all_tests
|
from common_test import AATest, setup_all_tests
|
||||||
from apparmor.common import AppArmorBug
|
from apparmor.common import AppArmorBug
|
||||||
|
|
||||||
from apparmor.regex import strip_quotes, parse_profile_start_line, RE_PROFILE_START_2
|
from apparmor.regex import strip_quotes, parse_profile_start_line, RE_PROFILE_START
|
||||||
|
|
||||||
|
|
||||||
class AARegexTest(AATest):
|
class AARegexTest(AATest):
|
||||||
@@ -393,10 +393,10 @@ class AARegexUnix(AARegexTest):
|
|||||||
]
|
]
|
||||||
|
|
||||||
class AANamedRegexProfileStart_2(AANamedRegexTest):
|
class AANamedRegexProfileStart_2(AANamedRegexTest):
|
||||||
'''Tests for RE_PROFILE_START_2'''
|
'''Tests for RE_PROFILE_START'''
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.regex = RE_PROFILE_START_2
|
self.regex = RE_PROFILE_START
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
('/bin/foo ', False), # no '{'
|
('/bin/foo ', False), # no '{'
|
||||||
|
Reference in New Issue
Block a user