From: Michal 'vorner' Vaner Date: Sat, 28 Jul 2012 16:31:21 +0000 (+0200) Subject: [2113] Check the MasterFiles params X-Git-Tag: trac2351_base~97^2~7^2~2^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=28d84a9af289a4fbbdef1eb7da8e3674dc0de9af;p=thirdparty%2Fkea.git [2113] Check the MasterFiles params They are skipped in the ClientList, so not checked at all. --- diff --git a/src/bin/cfgmgr/plugins/datasrc_config_plugin.py b/src/bin/cfgmgr/plugins/datasrc_config_plugin.py index 2cd0e7a3fa..88fbc61bec 100644 --- a/src/bin/cfgmgr/plugins/datasrc_config_plugin.py +++ b/src/bin/cfgmgr/plugins/datasrc_config_plugin.py @@ -19,6 +19,8 @@ from bind10_config import PLUGIN_PATHS import isc.dns import isc.datasrc import json +import os.path + spec = module_spec_from_file(path_search('datasrc.spec', PLUGIN_PATHS)) def check(config): @@ -42,12 +44,26 @@ def check(config): return str(irc) dlist = isc.datasrc.ConfigurableClientList(rr_class) + client_config = classes.get(rr_class_str) try: - dlist.configure(json.dumps(classes.get(rr_class_str)), - False) + dlist.configure(json.dumps(client_config), False) except isc.datasrc.Error as dse: return str(dse) + for client in client_config: + if client['type'] == 'MasterFiles': + if not client.get('cache-enable', False): + return 'The cache must be enabled in MasterFiles type' + params = client.get('params') + if type(params) != dict: + return 'Params of MasterFiles must be a named set' + for name in params: + try: + isc.dns.Name(name) + except Exception as e: # There are many related exceptions + return str(e) + if not os.path.exists(params[name]): + return "Master file " + params[name] + " does not exist" return None def load(): diff --git a/src/bin/cfgmgr/plugins/tests/datasrc_test.py b/src/bin/cfgmgr/plugins/tests/datasrc_test.py index 5d87a16929..26d5fe77a6 100644 --- a/src/bin/cfgmgr/plugins/tests/datasrc_test.py +++ b/src/bin/cfgmgr/plugins/tests/datasrc_test.py @@ -17,6 +17,7 @@ import sys import os sys.path.extend(os.environ["B10_TEST_PLUGIN_DIR"].split(':')) +import isc.log import datasrc_config_plugin import unittest @@ -95,5 +96,55 @@ class DatasrcTest(unittest.TestCase): "type": "No such type" }]}) + def test_invalid_mem_params(self): + """ + The client list skips in-memory sources. So we check it locally that + invalid things are rejected. + """ + # The 'params' key is mandatory for MasterFiles + self.reject({"IN": [{ + "type": "MasterFiles", + "cache-enable": True + }]}) + # The cache must be enabled + self.reject({"IN": [{ + "type": "MasterFiles", + "cache-enable": False, + "params": {} + }]}) + self.reject({"IN": [{ + "type": "MasterFiles", + "params": {} + }]}) + # Bad params type + self.reject({"IN": [{ + "type": "MasterFiles", + "cache-enable": True, + "params": [] + }]}) + # Bad name + self.reject({"IN": [{ + "type": "MasterFiles", + "cache-enable": True, + "params": { + "example....org.": '/file/does/not/exist' + } + }]}) + + def test_no_such_file_mem(self): + """ + We also check the existance of master files. Not the actual content, + though. + """ + self.reject({"IN": [{ + "type": "MasterFiles", + "cache-enable": True, + "params": { + "example.org.": '/file/does/not/exist' + } + }]}) + if __name__ == '__main__': - unittest.main() + isc.log.init("bind10") + isc.log.resetUnitTestRootLogger() + unittest.main()