Module: check_mk
Branch: master
Commit: 9ee71ecaa0766c2051728736e5158aab07c67c25
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9ee71ecaa0766c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Sep 6 13:17:16 2016 +0200
Moved file permission check from git hook to test
---
tests/general/test_permissions.py | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/tests/general/test_permissions.py b/tests/general/test_permissions.py
new file mode 100644
index 0000000..4fea257
--- /dev/null
+++ b/tests/general/test_permissions.py
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+# encoding: utf-8
+
+import os
+import glob
+from testlib import cmk_path
+
+def is_executable(path):
+ return os.path.isfile(path) and os.access(path, os.X_OK)
+
+def is_not_executable(path):
+ return os.path.isfile(path) and not os.access(path, os.X_OK)
+
+permissions = [
+ # globbing pattern check function, excludes
+ ('doc/treasures/active_checks/*', is_executable, ['Makefile',
'check_mkevents.cc']),
+ ('agents/special/*', is_executable, []),
+ ('agents/check_mk_agent.*', is_executable,
['check_mk_agent.spec']),
+ ('agents/plugins/*', is_executable, ['README']),
+ ('checks/*', is_not_executable, []),
+ ('checkman/*', is_not_executable, []),
+ ('inventory/*', is_not_executable, []),
+ ('pnp-templates/*', is_not_executable, []),
+ ('notifications/*', is_executable, ['README',
'debug']),
+ ('bin/*', is_executable, ['Makefile',
'mkevent.cc', 'mkeventd_open514.cc']),
+]
+
+def test_permissions():
+ for pattern, check_func, excludes in permissions:
+ for f in glob.glob("%s/%s" % (cmk_path(), pattern)):
+ if f.split('/')[-1] in excludes:
+ continue
+ assert check_func(f), "%s has wrong permissions (%r)" % \
+ (f, check_func)