ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [09/50] [abbrv] ambari git commit: AMBARI-14485 Unable to reconfigure truststore with ambari-server setup-security (dsen)
Date Mon, 04 Jan 2016 21:38:02 GMT
AMBARI-14485 Unable to reconfigure truststore with ambari-server setup-security (dsen)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9c6f7490
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9c6f7490
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9c6f7490

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 9c6f7490d5d4c8365c00c860fb3aacf554ab7bad
Parents: 30e6c68
Author: Dmytro Sen <dsen@apache.org>
Authored: Mon Dec 28 17:20:42 2015 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Mon Dec 28 17:20:42 2015 +0200

----------------------------------------------------------------------
 .../src/main/python/ambari_server/setupHttps.py |  22 ++--
 .../src/test/python/TestAmbariServer.py         | 103 ++++++++++++++++---
 2 files changed, 102 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9c6f7490/ambari-server/src/main/python/ambari_server/setupHttps.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/setupHttps.py b/ambari-server/src/main/python/ambari_server/setupHttps.py
index c9fe421..4e95999 100644
--- a/ambari-server/src/main/python/ambari_server/setupHttps.py
+++ b/ambari-server/src/main/python/ambari_server/setupHttps.py
@@ -82,7 +82,7 @@ SRVR_ONE_WAY_SSL_PORT = "8440"
 GANGLIA_HTTPS = 'ganglia.https'
 
 
-def get_truststore_path(properties):
+def get_and_persist_truststore_path(properties):
   truststore_path = properties.get_property(SSL_TRUSTSTORE_PATH_PROPERTY)
   if not truststore_path:
     SSL_TRUSTSTORE_PATH_DEFAULT = get_value_from_properties(properties, SSL_TRUSTSTORE_PATH_PROPERTY)
@@ -98,7 +98,7 @@ def get_truststore_path(properties):
 
   return truststore_path
 
-def get_truststore_type(properties):
+def get_and_persist_truststore_type(properties):
   truststore_type = properties.get_property(SSL_TRUSTSTORE_TYPE_PROPERTY)
   if not truststore_type:
     SSL_TRUSTSTORE_TYPE_DEFAULT = get_value_from_properties(properties, SSL_TRUSTSTORE_TYPE_PROPERTY,
"jks")
@@ -113,7 +113,7 @@ def get_truststore_type(properties):
 
   return truststore_type
 
-def get_truststore_password(properties):
+def get_and_persist_truststore_password(properties):
   truststore_password = properties.get_property(SSL_TRUSTSTORE_PASSWORD_PROPERTY)
   isSecure = get_is_secure(properties)
   if truststore_password:
@@ -462,9 +462,19 @@ def setup_truststore(import_cert=False):
     properties = get_ambari_properties()
 
     if get_YN_input("Do you want to configure a truststore [y/n] (y)? ", True):
-      truststore_type = get_truststore_type(properties)
-      truststore_path = get_truststore_path(properties)
-      truststore_password = get_truststore_password(properties)
+
+      #Re-configuration enabled only for option "Setup truststore"
+      if not import_cert and properties.get_property(SSL_TRUSTSTORE_TYPE_PROPERTY)\
+        and get_YN_input(
+            "The truststore is already configured. Do you want to re-configure "
+            "the truststore [y/n] (y)? ", True):
+        properties.removeProp(SSL_TRUSTSTORE_TYPE_PROPERTY)
+        properties.removeProp(SSL_TRUSTSTORE_PATH_PROPERTY)
+        properties.removeProp(SSL_TRUSTSTORE_PASSWORD_PROPERTY)
+
+      truststore_type = get_and_persist_truststore_type(properties)
+      truststore_path = get_and_persist_truststore_path(properties)
+      truststore_password = get_and_persist_truststore_password(properties)
 
       if import_cert:
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9c6f7490/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index fde647a..970bcab 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -1904,21 +1904,21 @@ class TestAmbariServer(TestCase):
   @patch("ambari_server.setupHttps.get_validated_filepath_input")
   @patch("ambari_server.setupHttps.get_validated_string_input")
   @patch("ambari_server.setupHttps.run_os_command")
-  @patch("ambari_server.setupHttps.get_truststore_type")
+  @patch("ambari_server.setupHttps.get_and_persist_truststore_type")
   @patch("__builtin__.open")
   @patch("ambari_server.setupHttps.find_properties_file")
   @patch("ambari_server.setupHttps.run_component_https_cmd")
   @patch("ambari_server.setupHttps.get_delete_cert_command")
-  @patch("ambari_server.setupHttps.get_truststore_password")
-  @patch("ambari_server.setupHttps.get_truststore_path")
+  @patch("ambari_server.setupHttps.get_and_persist_truststore_password")
+  @patch("ambari_server.setupHttps.get_and_persist_truststore_path")
   @patch("ambari_server.setupHttps.get_YN_input")
   @patch("ambari_server.setupHttps.get_ambari_properties")
   @patch("ambari_server.setupHttps.find_jdk")
   def test_setup_truststore(self, find_jdk_mock, get_ambari_properties_mock, get_YN_input_mock,
-                                 get_truststore_path_mock, get_truststore_password_mock,
+                                 get_and_persist_truststore_path_mock, get_and_persist_truststore_password_mock,
                                  get_delete_cert_command_mock, run_component_https_cmd_mock,
                                  find_properties_file_mock, open_mock,
-                                 get_truststore_type_mock, run_os_command_mock,
+                                 get_and_persist_truststore_type_mock, run_os_command_mock,
                                  get_validated_string_input_mock,
                                  get_validated_filepath_input_mock):
     out = StringIO.StringIO()
@@ -1956,13 +1956,13 @@ class TestAmbariServer(TestCase):
     find_jdk_mock.return_value = "/jdk_path"
     p.get_property.side_effect = ["true"]
     get_YN_input_mock.side_effect = [True,True]
-    get_truststore_path_mock.return_value = "/truststore_path"
-    get_truststore_password_mock.return_value = "/truststore_password"
+    get_and_persist_truststore_path_mock.return_value = "/truststore_path"
+    get_and_persist_truststore_password_mock.return_value = "/truststore_password"
     get_delete_cert_command_mock.return_value = "rm -f"
     setup_truststore(True)
 
-    self.assertTrue(get_truststore_path_mock.called)
-    self.assertTrue(get_truststore_password_mock.called)
+    self.assertTrue(get_and_persist_truststore_path_mock.called)
+    self.assertTrue(get_and_persist_truststore_password_mock.called)
     self.assertTrue(get_delete_cert_command_mock.called)
     self.assertTrue(find_properties_file_mock.called)
     self.assertTrue(open_mock.called)
@@ -1970,8 +1970,8 @@ class TestAmbariServer(TestCase):
     self.assertTrue(run_component_https_cmd_mock.called)
 
     p.process_pair.reset_mock()
-    get_truststore_path_mock.reset_mock()
-    get_truststore_password_mock.reset_mock()
+    get_and_persist_truststore_path_mock.reset_mock()
+    get_and_persist_truststore_password_mock.reset_mock()
     get_delete_cert_command_mock.reset_mock()
     find_properties_file_mock.reset_mock()
     open_mock.reset_mock()
@@ -1981,9 +1981,9 @@ class TestAmbariServer(TestCase):
     get_YN_input_mock.side_effect = [True,True]
     setup_truststore(True)
 
-    self.assertTrue(get_truststore_type_mock.called)
-    self.assertTrue(get_truststore_path_mock.called)
-    self.assertTrue(get_truststore_password_mock.called)
+    self.assertTrue(get_and_persist_truststore_type_mock.called)
+    self.assertTrue(get_and_persist_truststore_path_mock.called)
+    self.assertTrue(get_and_persist_truststore_password_mock.called)
     self.assertTrue(get_delete_cert_command_mock.called)
     self.assertTrue(find_properties_file_mock.called)
     self.assertTrue(open_mock.called)
@@ -1993,9 +1993,9 @@ class TestAmbariServer(TestCase):
     self.assertTrue(get_validated_filepath_input_mock.called)
 
     p.process_pair.reset_mock()
-    get_truststore_type_mock.reset_mock()
-    get_truststore_path_mock.reset_mock()
-    get_truststore_password_mock.reset_mock()
+    get_and_persist_truststore_type_mock.reset_mock()
+    get_and_persist_truststore_path_mock.reset_mock()
+    get_and_persist_truststore_password_mock.reset_mock()
     get_delete_cert_command_mock.reset_mock()
     find_properties_file_mock.reset_mock()
     open_mock.reset_mock()
@@ -2003,6 +2003,75 @@ class TestAmbariServer(TestCase):
     run_os_command_mock.reset_mock()
     get_validated_filepath_input_mock.reset_mock()
     pass
+  
+  @patch("__builtin__.open")
+  @patch("ambari_commons.logging_utils.get_silent")
+  @patch("ambari_server.setupHttps.find_jdk")
+  @patch("ambari_server.setupHttps.get_ambari_properties")
+  @patch("ambari_server.setupHttps.get_YN_input")
+  @patch("ambari_server.setupHttps.get_and_persist_truststore_type")
+  @patch("ambari_server.setupHttps.get_and_persist_truststore_path")
+  @patch("ambari_server.setupHttps.get_and_persist_truststore_password")
+  @patch("ambari_server.setupHttps.find_properties_file")
+  @patch("ambari_server.setupHttps.get_validated_string_input")
+  @patch("ambari_server.setupHttps.run_os_command")
+  @patch("ambari_server.setupHttps.get_validated_filepath_input")
+  @patch("ambari_server.setupHttps.get_import_cert_command")
+  @patch("ambari_server.setupHttps.run_component_https_cmd")
+  def test_reconfigure_truststore(self, run_component_https_cmd_mock, 
+            get_import_cert_command_mock,
+            get_validated_filepath_input_mock, run_os_command_mock,
+            get_validated_string_input_mock, find_properties_file_mock, 
+            get_and_persist_truststore_password_mock, get_and_persist_truststore_path_mock,
+            get_and_persist_truststore_type_mock, get_YN_input_mock,
+            get_ambari_properties_mock, find_jdk_mock, get_silent_mock,
+            open_mock):
+    
+    def reset_mocks():
+      open_mock.reset_mock()
+      find_jdk_mock.reset_mock()
+      get_ambari_properties_mock.reset_mock()
+      get_YN_input_mock.reset_mock()
+      get_and_persist_truststore_type_mock.reset_mock()
+      get_and_persist_truststore_path_mock.reset_mock()
+      get_and_persist_truststore_password_mock.reset_mock() 
+      find_properties_file_mock.reset_mock()
+      get_validated_string_input_mock.reset_mock()
+      run_os_command_mock.reset_mock()
+      get_validated_filepath_input_mock.reset_mock() 
+      get_import_cert_command_mock.reset_mock()
+      run_component_https_cmd_mock.reset_mock()
+            
+    #Test preconditions
+    get_silent_mock.return_value = False
+    find_jdk_mock.return_value = "/path"
+
+    #Reconfiguration allowed by the user
+    reset_mocks()
+    get_YN_input_mock.side_effect = [True, True, True]
+    setup_truststore()
+    self.assertTrue(get_and_persist_truststore_type_mock.called)
+    self.assertTrue(get_and_persist_truststore_path_mock.called)
+    self.assertTrue(get_and_persist_truststore_password_mock.called)
+    
+    #Reconfiguration disallowed by the user
+    reset_mocks()
+    get_YN_input_mock.side_effect = [True, False]
+    setup_truststore()
+    self.assertTrue(get_and_persist_truststore_type_mock.called)
+    self.assertTrue(get_and_persist_truststore_path_mock.called)
+    self.assertTrue(get_and_persist_truststore_password_mock.called)
+    
+    #Reconfiguration should be disabled when 'import_cert' flag is 'True'
+    reset_mocks()
+    get_YN_input_mock.side_effect = [True, True]
+    setup_truststore(True)
+    self.assertTrue(get_and_persist_truststore_type_mock.called)
+    self.assertTrue(get_and_persist_truststore_path_mock.called)
+    self.assertTrue(get_and_persist_truststore_password_mock.called)
+    self.assertTrue(get_import_cert_command_mock.called)
+    
+    pass
 
   @patch("ambari_server.setupHttps.adjust_directory_permissions")
   @patch("ambari_server.setupHttps.read_ambari_user")


Mime
View raw message