|
@@ -467,3 +467,105 @@ class TestHbaseRegionServer(RMFTestCase):
|
|
user = 'hbase')
|
|
user = 'hbase')
|
|
|
|
|
|
self.assertNoMoreResources()
|
|
self.assertNoMoreResources()
|
|
|
|
+
|
|
|
|
+ @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['hbase-site'] = {}
|
|
|
|
+ security_params['hbase-site']['hbase.regionserver.keytab.file'] = '/path/to/hbase_keytab'
|
|
|
|
+ security_params['hbase-site']['hbase.regionserver.kerberos.principal'] = 'hbase_principal'
|
|
|
|
+
|
|
|
|
+ result_issues = []
|
|
|
|
+ props_value_check = {"hbase.security.authentication": "kerberos",
|
|
|
|
+ "hbase.security.authorization": "true"}
|
|
|
|
+ props_empty_check = ["hbase.regionserver.keytab.file",
|
|
|
|
+ "hbase.regionserver.kerberos.principal"]
|
|
|
|
+
|
|
|
|
+ props_read_check = ["hbase.regionserver.keytab.file"]
|
|
|
|
+
|
|
|
|
+ get_params_mock.return_value = security_params
|
|
|
|
+ validate_security_config_mock.return_value = result_issues
|
|
|
|
+
|
|
|
|
+ self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hbase_regionserver.py",
|
|
|
|
+ classname = "HbaseRegionServer",
|
|
|
|
+ command = "security_status",
|
|
|
|
+ config_file="secured.json",
|
|
|
|
+ hdp_stack_version = self.STACK_VERSION,
|
|
|
|
+ target = RMFTestCase.TARGET_COMMON_SERVICES
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ build_exp_mock.assert_called_with('hbase-site', props_value_check, props_empty_check, props_read_check)
|
|
|
|
+ put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"})
|
|
|
|
+ cached_kinit_executor_mock.called_with(status_params.kinit_path_local,
|
|
|
|
+ status_params.hbase_user,
|
|
|
|
+ security_params['hbase-site']['hbase.regionserver.keytab.file'],
|
|
|
|
+ security_params['hbase-site']['hbase.regionserver.kerberos.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/hbase_regionserver.py",
|
|
|
|
+ classname = "HbaseRegionServer",
|
|
|
|
+ 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 hbase-site
|
|
|
|
+ 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/hbase_regionserver.py",
|
|
|
|
+ classname = "HbaseRegionServer",
|
|
|
|
+ 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['hbase-site']="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/hbase_regionserver.py",
|
|
|
|
+ classname = "HbaseRegionServer",
|
|
|
|
+ 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/hbase_regionserver.py",
|
|
|
|
+ classname = "HbaseRegionServer",
|
|
|
|
+ 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"})
|