|
@@ -227,3 +227,103 @@ class TestZookeeperServer(RMFTestCase):
|
|
|
owner = 'zookeeper',
|
|
|
group = 'hadoop',
|
|
|
)
|
|
|
+
|
|
|
+ @patch("resource_management.libraries.functions.security_commons.build_expectations")
|
|
|
+ @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem")
|
|
|
+ @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties")
|
|
|
+ @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor")
|
|
|
+ @patch("resource_management.libraries.script.Script.put_structured_out")
|
|
|
+ def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock):
|
|
|
+ # Test that function works when is called with correct parameters
|
|
|
+ import status_params
|
|
|
+
|
|
|
+ security_params = {}
|
|
|
+ security_params['zookeeper_jaas'] = {}
|
|
|
+ security_params['zookeeper_jaas']['Server'] = {}
|
|
|
+ security_params['zookeeper_jaas']['Server']['keyTab'] = 'path/to/zookeeper/service/keytab'
|
|
|
+ security_params['zookeeper_jaas']['Server']['principal'] = 'zookeeper_keytab'
|
|
|
+ result_issues = []
|
|
|
+ props_value_check = None
|
|
|
+ props_empty_check = ['Server/keyTab', 'Server/principal']
|
|
|
+ props_read_check = ['Server/keyTab']
|
|
|
+
|
|
|
+ get_params_mock.return_value = security_params
|
|
|
+ validate_security_config_mock.return_value = result_issues
|
|
|
+
|
|
|
+ self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py",
|
|
|
+ classname = "ZookeeperServer",
|
|
|
+ command = "security_status",
|
|
|
+ config_file = "secured.json",
|
|
|
+ hdp_stack_version = self.STACK_VERSION,
|
|
|
+ target = RMFTestCase.TARGET_COMMON_SERVICES
|
|
|
+ )
|
|
|
+
|
|
|
+ build_exp_mock.assert_called_with('zookeeper_jaas', props_value_check, props_empty_check, props_read_check)
|
|
|
+ put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"})
|
|
|
+ self.assertTrue(cached_kinit_executor_mock.call_count, 2)
|
|
|
+ cached_kinit_executor_mock.assert_called_with(status_params.kinit_path_local,
|
|
|
+ status_params.zk_user,
|
|
|
+ security_params['zookeeper_jaas']['Server']['keyTab'],
|
|
|
+ security_params['zookeeper_jaas']['Server']['principal'],
|
|
|
+ status_params.hostname,
|
|
|
+ status_params.tmp_dir,
|
|
|
+ 30)
|
|
|
+
|
|
|
+ # Testing that the exception throw by cached_executor is caught
|
|
|
+ cached_kinit_executor_mock.reset_mock()
|
|
|
+ cached_kinit_executor_mock.side_effect = Exception("Invalid command")
|
|
|
+
|
|
|
+ try:
|
|
|
+ self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py",
|
|
|
+ classname = "ZookeeperServer",
|
|
|
+ command = "security_status",
|
|
|
+ config_file = "secured.json",
|
|
|
+ hdp_stack_version = self.STACK_VERSION,
|
|
|
+ target = RMFTestCase.TARGET_COMMON_SERVICES
|
|
|
+ )
|
|
|
+ except:
|
|
|
+ self.assertTrue(True)
|
|
|
+
|
|
|
+ # Testing with a security_params which doesn't contains zookeeper_jaas
|
|
|
+ empty_security_params = {}
|
|
|
+ cached_kinit_executor_mock.reset_mock()
|
|
|
+ get_params_mock.reset_mock()
|
|
|
+ put_structured_out_mock.reset_mock()
|
|
|
+ get_params_mock.return_value = empty_security_params
|
|
|
+
|
|
|
+ self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py",
|
|
|
+ classname = "ZookeeperServer",
|
|
|
+ command = "security_status",
|
|
|
+ config_file = "secured.json",
|
|
|
+ hdp_stack_version = self.STACK_VERSION,
|
|
|
+ target = RMFTestCase.TARGET_COMMON_SERVICES
|
|
|
+ )
|
|
|
+ put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."})
|
|
|
+
|
|
|
+ # Testing with not empty result_issues
|
|
|
+ result_issues_with_params = {}
|
|
|
+ result_issues_with_params['zookeeper_jaas']="Something bad happened"
|
|
|
+
|
|
|
+ validate_security_config_mock.reset_mock()
|
|
|
+ get_params_mock.reset_mock()
|
|
|
+ validate_security_config_mock.return_value = result_issues_with_params
|
|
|
+ get_params_mock.return_value = security_params
|
|
|
+
|
|
|
+ self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py",
|
|
|
+ classname = "ZookeeperServer",
|
|
|
+ command = "security_status",
|
|
|
+ config_file = "secured.json",
|
|
|
+ hdp_stack_version = self.STACK_VERSION,
|
|
|
+ target = RMFTestCase.TARGET_COMMON_SERVICES
|
|
|
+ )
|
|
|
+ put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
|
|
|
+
|
|
|
+ # Testing with security_enable = false
|
|
|
+ self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py",
|
|
|
+ classname = "ZookeeperServer",
|
|
|
+ command = "security_status",
|
|
|
+ config_file = "default.json",
|
|
|
+ hdp_stack_version = self.STACK_VERSION,
|
|
|
+ target = RMFTestCase.TARGET_COMMON_SERVICES
|
|
|
+ )
|
|
|
+ put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
|