2016-10-01 20:57:09 +02:00
|
|
|
#! /usr/bin/python3
|
2015-12-17 23:33:36 +01:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Christian Boltz <apparmor@cboltz.de>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of version 2 of the GNU General Public
|
|
|
|
# License published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2022-08-07 20:32:07 -04:00
|
|
|
from apparmor.common import AppArmorBug, combine_profname, split_name
|
|
|
|
from common_test import AATest, setup_all_loops
|
2015-12-17 23:33:36 +01:00
|
|
|
|
2022-08-07 12:26:24 -04:00
|
|
|
|
2019-05-04 20:49:27 +02:00
|
|
|
class AaTest_split_name(AATest):
|
2022-06-18 14:30:49 -04:00
|
|
|
tests = (
|
2022-08-07 12:26:24 -04:00
|
|
|
# full profile name expected parts
|
|
|
|
('foo', ('foo', 'foo')),
|
|
|
|
('foo//bar', ('foo', 'bar')),
|
|
|
|
('foo//bar//baz', ('foo', 'bar')), # XXX nested child profiles get cut off
|
2022-06-18 14:30:49 -04:00
|
|
|
)
|
2019-05-04 20:49:27 +02:00
|
|
|
|
|
|
|
def _run_test(self, params, expected):
|
|
|
|
self.assertEqual(split_name(params), expected)
|
|
|
|
|
2022-08-07 12:26:24 -04:00
|
|
|
|
2020-12-25 13:21:39 +01:00
|
|
|
class AaTest_combine_profname(AATest):
|
2022-06-18 14:30:49 -04:00
|
|
|
tests = (
|
2022-08-07 12:26:24 -04:00
|
|
|
# name parts expected full profile name
|
2022-09-10 17:57:09 -04:00
|
|
|
(('foo',), 'foo'),
|
|
|
|
(('foo', 'bar'), 'foo//bar'),
|
|
|
|
(('foo', 'bar', 'baz'), 'foo//bar//baz'),
|
|
|
|
(('foo', 'bar', None), 'foo//bar'),
|
|
|
|
(('foo', 'bar', 'baz', None), 'foo//bar//baz'),
|
2022-06-18 14:30:49 -04:00
|
|
|
)
|
2020-12-25 13:21:39 +01:00
|
|
|
|
|
|
|
def _run_test(self, params, expected):
|
|
|
|
self.assertEqual(combine_profname(params), expected)
|
|
|
|
|
|
|
|
def test_wrong_type(self):
|
|
|
|
with self.assertRaises(AppArmorBug):
|
|
|
|
combine_profname('foo')
|
|
|
|
|
2015-12-17 23:33:36 +01:00
|
|
|
|
|
|
|
setup_all_loops(__name__)
|
|
|
|
if __name__ == '__main__':
|
2018-04-08 20:18:30 +02:00
|
|
|
unittest.main(verbosity=1)
|