Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Support the new security-override semantics #222
Merged
Jump to file or symbol
Failed to load files and symbols.
| @@ -14,6 +14,7 @@ | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| +import copy | ||
| import logging | ||
| import os | ||
| import unittest | ||
| @@ -614,6 +615,88 @@ def test_license_version_without_license_raises_exception(self): | ||
| self.assertEqual(raised.exception.message, expected_message, | ||
| msg=self.data) | ||
| + def test_valid_security_policy_for_apps(self): | ||
| + self.data['apps'] = { | ||
| + 'app1': { | ||
| + 'command': 'binary', | ||
| + 'security-policy': { | ||
| + 'seccomp': 'file.seccomp', | ||
| + 'apparmor': 'file.apparmor', | ||
| + }, | ||
| + }, | ||
| + } | ||
| + | ||
| + snapcraft.yaml._validate_snapcraft_yaml(self.data) | ||
| + | ||
| + def test_valid_security_override_for_apps(self): | ||
| + self.data['apps'] = { | ||
| + 'app1': { | ||
| + 'command': 'binary', | ||
| + 'security-override': { | ||
| + 'read-paths': ['path1', 'path2'], | ||
| + 'write-paths': ['path1', 'path2'], | ||
| + 'abstractions': ['abstraction1', 'abstraction2'], | ||
| + 'syscalls': ['open', 'close'], | ||
| + }, | ||
| + }, | ||
| + } | ||
| + | ||
| + snapcraft.yaml._validate_snapcraft_yaml(self.data) | ||
| + | ||
| + def test_valid_security_template_for_apps(self): | ||
| + self.data['apps'] = { | ||
| + 'app1': { | ||
| + 'command': 'binary', | ||
| + 'security-template': 'unconfined', | ||
| + }, | ||
| + } | ||
| + | ||
| + snapcraft.yaml._validate_snapcraft_yaml(self.data) | ||
| + | ||
| + def test_valid_caps_for_apps(self): | ||
| + self.data['apps'] = { | ||
| + 'app1': { | ||
| + 'command': 'binary', | ||
| + 'caps': ['cap1', 'cap2'], | ||
| + }, | ||
| + } | ||
| + | ||
| + snapcraft.yaml._validate_snapcraft_yaml(self.data) | ||
| + | ||
| + def test_invalid_security_override_combinations(self): | ||
| + self.data['apps'] = { | ||
| + 'app1': { | ||
| + 'command': 'binary', | ||
| + 'security-override': { | ||
| + 'read-paths': ['path1', 'path2'], | ||
| + 'write-paths': ['path1', 'path2'], | ||
| + 'abstractions': ['abstraction1', 'abstraction2'], | ||
| + 'syscalls': ['open', 'close'], | ||
| + }, | ||
| + 'caps': ['cap1', 'cap2'], | ||
| + 'security-policy': { | ||
| + 'seccomp': 'file.seccomp', | ||
| + 'apparmor': 'file.apparmor', | ||
| + }, | ||
| + 'security-template': 'undefined', | ||
| + }, | ||
| + } | ||
sergiusens
Collaborator
|
||
| + | ||
| + with self.subTest(key='all'): | ||
| + with self.assertRaises(Exception) as r: | ||
| + snapcraft.yaml._validate_snapcraft_yaml(self.data) | ||
| + | ||
| + self.assertTrue('is not allowed' in str(r.exception)) | ||
| + | ||
| + for sec in ['security-override', 'security-template', 'caps']: | ||
| + data = copy.deepcopy(self.data) | ||
| + del data['apps']['app1'][sec] | ||
| + with self.subTest(key=sec): | ||
| + with self.assertRaises(Exception) as r: | ||
| + snapcraft.yaml._validate_snapcraft_yaml(data) | ||
| + | ||
| + self.assertTrue('is not allowed' in str(r.exception)) | ||
| + | ||
| class TestFilesets(tests.TestCase): | ||
You're missing three combos here, right? Worth adding them?