Module: check_mk
Branch: master
Commit: 760ff05cf10fabe7f3a8c9a95cd771d8a5047953
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=760ff05cf10fab…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 10 11:21:15 2017 +0100
Tests: Added tests for setuid binaries and werk saving/loading
Change-Id: I29796f2ea2a0ab0d89c2864e68a1a62d9240f023
---
lib/werks.py | 6 +++-
tests/lib/test_werks.py | 60 +++++++++++++++++++++++++++++++++++++++
tests/omd/test_setuid_binaries.py | 24 ++++++++++++++++
3 files changed, 89 insertions(+), 1 deletion(-)
diff --git a/lib/werks.py b/lib/werks.py
index 07b5e3d..c5fa43c 100644
--- a/lib/werks.py
+++ b/lib/werks.py
@@ -44,9 +44,13 @@ except NameError:
_ = lambda x: x # Fake i18n when not available
+def _compiled_werks_path():
+ return cmk.paths.share_dir + "/werks/werks"
+
+
def load():
werks = {}
- for werk_id, werk in json.load(open(cmk.paths.share_dir +
"/werks/werks")).items():
+ for werk_id, werk in json.load(open(_compiled_werks_path())).items():
werks[int(werk_id)] = werk
return werks
diff --git a/tests/lib/test_werks.py b/tests/lib/test_werks.py
new file mode 100644
index 0000000..3451cea
--- /dev/null
+++ b/tests/lib/test_werks.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+import os
+
+import testlib
+import cmk.werks
+
+def test_load():
+ werks = cmk.werks.load()
+ assert len(werks) > 1000
+
+
+def test_regular_werks(site):
+ werks = cmk.werks.load()
+
+ regular_werks = [ id for id in werks.keys() if id < 7500 ]
+ assert len(regular_werks) > 1000
+
+
+def test_enterprise_werks(site):
+ werks = cmk.werks.load()
+
+ enterprise_werks = [ id for id in werks.keys() if id >= 8000 ]
+
+ if site.version.edition() == "raw":
+ assert not enterprise_werks
+ else:
+ assert enterprise_werks
+
+
+# TODO: cmk omd werks are currently missing
+#def test_cmk_omd_werks(site):
+# werks = cmk.werks.load()
+#
+# cmk_omd_werks = [ id for id in werks.keys() if id >= 7500 and id < 8000 ]
+# assert cmk_omd_werks
+
+def test_write_precompiled_werks(tmpdir, site, monkeypatch):
+ tmp_path = "%s" % tmpdir.join("test-werks")
+
+ cmk_werks = cmk.werks.load_raw_files(os.path.join(testlib.cmk_path(),
".werks"))
+ assert len(cmk_werks) > 1000
+ assert [ w for w in cmk_werks.keys() if w >= 7500 ] == []
+
+ if site.version.edition() == "raw":
+ cmc_werks = cmk.werks.load_raw_files(os.path.join(testlib.cmc_path(),
".werks"))
+ assert len(cmc_werks) > 1000
+ assert [ w for w in cmc_werks.keys() if w < 8000 ] == []
+
+ werks = {}
+ werks.update(cmk_werks)
+ if site.version.edition() == "raw":
+ werks.update(cmc_werks)
+
+ cmk.werks.write_precompiled_werks(tmp_path, werks)
+
+ monkeypatch.setattr(cmk.werks, "_compiled_werks_path", lambda: tmp_path)
+ werks_loaded = cmk.werks.load()
+
+ assert werks == werks_loaded
diff --git a/tests/omd/test_setuid_binaries.py b/tests/omd/test_setuid_binaries.py
new file mode 100644
index 0000000..82a9363
--- /dev/null
+++ b/tests/omd/test_setuid_binaries.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+import os
+import stat
+
+def test_setuid_binaries(site):
+ setuid_binaries = [
+ "bin/mkeventd_open514",
+ "lib/nagios/plugins/check_dhcp",
+ "lib/nagios/plugins/check_icmp",
+ ]
+
+ if site.version.edition() == "enterprise":
+ setuid_binaries += [
+ "lib/cmc/icmpreceiver",
+ "lib/cmc/icmpsender",
+ ]
+
+ for rel_path in setuid_binaries:
+ path = os.path.join(site.root, rel_path)
+ assert os.path.exists(path)
+ assert os.stat(path).st_mode & stat.S_ISUID == stat.S_ISUID, \
+ "Missing setuid bit on %s" % path