2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00

[2/9] Add strip_parenthesis() to regex.py

Some dbus rule conditionals come with optional parenthesis. Instead of
making the regex even more complicated, use a small function to strip
those parenthesis.

Also add some tests for strip_parenthesis() to test-regex.py.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
This commit is contained in:
Christian Boltz
2016-05-23 23:12:07 +02:00
parent 2e2aa861d2
commit 18b5894888
2 changed files with 28 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ import unittest
from common_test import AATest, setup_all_loops
from apparmor.common import AppArmorBug, AppArmorException
from apparmor.regex import strip_quotes, parse_profile_start_line, re_match_include, RE_PROFILE_START, RE_PROFILE_CAP, RE_PROFILE_PTRACE, RE_PROFILE_SIGNAL
from apparmor.regex import strip_parenthesis, strip_quotes, parse_profile_start_line, re_match_include, RE_PROFILE_START, RE_PROFILE_CAP, RE_PROFILE_PTRACE, RE_PROFILE_SIGNAL
class AARegexTest(AATest):
@@ -501,6 +501,24 @@ class TestInvalid_re_match_include(AATest):
re_match_include(params)
class TestStripParenthesis(AATest):
tests = [
('foo', 'foo' ),
('(foo)', 'foo' ),
('( foo )', 'foo' ),
('(foo', '(foo' ),
('foo )', 'foo )' ),
('foo ()', 'foo ()' ),
('()', '' ),
('( )', '' ),
('(())', '()' ),
(' (foo)', '(foo)' ), # parenthesis not first char, whitespace stripped nevertheless
('(foo) ', '(foo)' ), # parenthesis not last char, whitespace stripped nevertheless
]
def _run_test(self, params, expected):
self.assertEqual(strip_parenthesis(params), expected)
class TestStripQuotes(AATest):
def test_strip_quotes_01(self):
self.assertEqual('foo', strip_quotes('foo'))