[apparmor] [patch] add tests for aamode.py
Christian Boltz
apparmor at cboltz.de
Thu Nov 27 13:06:11 UTC 2014
Hello,
Am Mittwoch, 26. November 2014 schrieb Steve Beattie:
> On Thu, Nov 27, 2014 at 12:29:12AM +0100, Christian Boltz wrote:
> > this patch adds tests for sub_str_to_mode() and split_log_mode() in
> > aamode.py. These are the functions that Peter's patch changes.
> >
> > Those tests were written with the "old" functions in place (without
> > Peter's patch) to make sure they match the current behaviour.
> (I do wonder what happens with split_log_mode('r::w::r') )
Depends ;-)
With the old code:
# python3
Python 3.4.1 (default, May 23 2014, 17:48:28) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from apparmor.aamode import split_log_mode
>>> split_log_mode('r::w::r')
('r', 'w::r')
With Peter's patch:
# python3
Python 3.4.1 (default, May 23 2014, 17:48:28) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from apparmor.aamode import split_log_mode
>>> split_log_mode('r::w::r')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/cb/apparmor/HEAD-clean/utils/apparmor/aamode.py", line
106, in split_log_mode
user, other = mode.split("::")
ValueError: too many values to unpack (expected 2)
The only function that calls split_log_mode() is str_to_mode() in
aamode.py. str_to_mode() doesn't do any validation of the result, so
raising an exception sounds like the better way.
Hmm, we should add a test for this too (fails with the old code, passes
with Peter's patch applied):
=== modified file 'utils/test/test-aamode.py'
--- utils/test/test-aamode.py 2014-11-27 12:54:22 +0000
+++ utils/test/test-aamode.py 2014-11-27 12:58:02 +0000
@@ -26,6 +26,9 @@
self.assertEqual(split_log_mode('r::w'), ('r', 'w'))
def test_split_log_mode_6(self):
self.assertEqual(split_log_mode('rw::rw'), ('rw', 'rw'))
+ def test_split_log_mode_invalid(self):
+ with self.assertRaises(ValueError):
+ split_log_mode('r::w::r')
class AamodeTest_sub_str_to_mode(unittest.TestCase):
def test_sub_str_to_mode_1(self):
Regards,
Christian Boltz
--
SOAP is really now just called "SOAP", I think they've dropped the
"Simple..." bit from the name as it can be anything but simple.
[http://codepoets.co.uk/using-soap-and-xmlrpc-php5-newbies-findings]
More information about the AppArmor
mailing list