You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by wu...@apache.org on 2022/11/21 15:37:56 UTC

[ambari] branch trunk updated: AMBARI-25495: Extend the set of headers from server's response (#3532)

This is an automated email from the ASF dual-hosted git repository.

wuzhiguo pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 01dd596025 AMBARI-25495: Extend the set of headers from server's response (#3532)
01dd596025 is described below

commit 01dd596025384a86fc3afddf9f6168b1762f8dc7
Author: Zhiguo Wu <wu...@apache.org>
AuthorDate: Mon Nov 21 23:37:49 2022 +0800

    AMBARI-25495: Extend the set of headers from server's response (#3532)
---
 .../ambari/server/configuration/Configuration.java | 37 ++++++++
 .../security/AbstractSecurityHeaderFilter.java     | 14 +++
 .../security/AmbariServerSecurityHeaderFilter.java |  1 +
 .../security/AmbariViewsSecurityHeaderFilter.java  |  1 +
 .../ambari/server/agent/TestHeartbeatHandler.java  |  3 +-
 .../AmbariServerSecurityHeaderFilterTest.java      |  2 +
 ambari-server/src/test/python/TestAmbariServer.py  | 99 +++++++++++-----------
 ambari-server/src/test/python/TestMpacks.py        | 15 ++--
 ambari-server/src/test/python/TestOSCheck.py       | 11 +--
 .../src/test/python/TestSetupTrustedProxy.py       | 13 +--
 10 files changed, 128 insertions(+), 68 deletions(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 087ca70232..5191b3ca05 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -2233,6 +2233,13 @@ public class Configuration {
   public static final ConfigurationProperty<String> HTTP_X_XSS_PROTECTION_HEADER_VALUE = new ConfigurationProperty<>(
       "http.x-xss-protection", "1; mode=block");
 
+  /**
+   * The value that will be used to set the {@code Content-Security-Policy} HTTP response header.
+   */
+  @Markdown(description = "The value that will be used to set the `Content-Security-Policy` HTTP response header.")
+  public static final ConfigurationProperty<String> HTTP_CONTENT_SECURITY_POLICY_HEADER_VALUE = new ConfigurationProperty<>(
+      "http.content-security-policy", "");
+
   /**
    * The value that will be used to set the {@code X-Content-Type} HTTP response header.
    */
@@ -2287,6 +2294,14 @@ public class Configuration {
   public static final ConfigurationProperty<String> VIEWS_HTTP_X_XSS_PROTECTION_HEADER_VALUE = new ConfigurationProperty<>(
       "views.http.x-xss-protection", "1; mode=block");
 
+  /**
+   * The value that will be used to set the {@code Content-Security-Policy}
+   * HTTP response header for Ambari View requests.
+   */
+  @Markdown(description = "The value that will be used to set the `Content-Security-Policy` HTTP response header for Ambari View requests.")
+  public static final ConfigurationProperty<String> VIEWS_HTTP_CONTENT_SECURITY_POLICY_HEADER_VALUE = new ConfigurationProperty<>(
+      "views.http.content-security-policy", "");
+
   /**
    * The value that will be used to set the {@code X-Content-Type} HTTP response header.
    * HTTP response header for Ambari View requests.
@@ -3701,6 +3716,17 @@ public class Configuration {
     return getProperty(HTTP_X_XSS_PROTECTION_HEADER_VALUE);
   }
 
+  /**
+   * Get the value that should be set for the <code>Content-Security-Policy</code> HTTP response header for Ambari Server UI.
+   * <p/>
+   * By default this will be empty.
+   *
+   * @return the Content-Security-Policy value - null or "" indicates that the value is not set
+   */
+  public String getContentSecurityPolicyHTTPResponseHeader() {
+    return getProperty(HTTP_CONTENT_SECURITY_POLICY_HEADER_VALUE);
+  }
+
   /**
    * Get the value that should be set for the <code>X-Content-Type</code> HTTP response header for Ambari Server UI.
    * <p/>
@@ -3808,6 +3834,17 @@ public class Configuration {
     return getProperty(VIEWS_HTTP_X_XSS_PROTECTION_HEADER_VALUE);
   }
 
+  /**
+   * Get the value that should be set for the <code>Content-Security-Policy</code> HTTP response header for Ambari Views.
+   * <p/>
+   * By default this will be empty.
+   *
+   * @return the Content-Security-Policy value - null or "" indicates that the value is not set
+   */
+  public String getViewsContentSecurityPolicyHTTPResponseHeader() {
+    return getProperty(VIEWS_HTTP_CONTENT_SECURITY_POLICY_HEADER_VALUE);
+  }
+
   /**
    * Get the value that should be set for the <code>X-Content-Type</code> HTTP response header for Ambari Views.
    * <p/>
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/AbstractSecurityHeaderFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/AbstractSecurityHeaderFilter.java
index b8631f821f..4099612c4a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/AbstractSecurityHeaderFilter.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/AbstractSecurityHeaderFilter.java
@@ -53,6 +53,7 @@ public abstract class AbstractSecurityHeaderFilter implements Filter {
   protected final static String STRICT_TRANSPORT_HEADER = "Strict-Transport-Security";
   protected final static String X_FRAME_OPTIONS_HEADER = "X-Frame-Options";
   protected final static String X_XSS_PROTECTION_HEADER = "X-XSS-Protection";
+  protected final static String CONTENT_SECURITY_POLICY_HEADER = "Content-Security-Policy";
   protected final static String X_CONTENT_TYPE_HEADER = "X-Content-Type-Options";
   protected final static String CACHE_CONTROL_HEADER = "Cache-Control";
   protected final static String PRAGMA_HEADER = "Pragma";
@@ -90,6 +91,10 @@ public abstract class AbstractSecurityHeaderFilter implements Filter {
    * The value for the X-XSS-Protection HTTP response header.
    */
   private String xXSSProtectionHeader = Configuration.HTTP_X_XSS_PROTECTION_HEADER_VALUE.getDefaultValue();
+  /**
+   * The value for the Content-Security-Policy HTTP response header.
+   */
+  private String contentSecurityPolicyHeader = Configuration.HTTP_CONTENT_SECURITY_POLICY_HEADER_VALUE.getDefaultValue();
   /**
    * The value for the Content-Type HTTP response header.
    */
@@ -162,6 +167,10 @@ public abstract class AbstractSecurityHeaderFilter implements Filter {
     this.xXSSProtectionHeader = xXSSProtectionHeader;
   }
 
+  protected void setContentSecurityPolicyHeader(String contentSecurityPolicyHeader) {
+    this.contentSecurityPolicyHeader = contentSecurityPolicyHeader;
+  }
+
   protected void setXContentTypeHeader(String xContentTypeHeader) {
     this.xContentTypeHeader = xContentTypeHeader;
   }
@@ -197,6 +206,11 @@ public abstract class AbstractSecurityHeaderFilter implements Filter {
         httpServletResponse.setHeader(X_XSS_PROTECTION_HEADER, xXSSProtectionHeader);
       }
 
+      // Conditionally set the Content-Security-Policy HTTP response header if a value is supplied
+      if (!StringUtils.isEmpty(contentSecurityPolicyHeader)) {
+        httpServletResponse.setHeader(CONTENT_SECURITY_POLICY_HEADER, contentSecurityPolicyHeader);
+      }
+
       // Conditionally set the X-Content-Type HTTP response header if a value is supplied
       if (!StringUtils.isEmpty(xContentTypeHeader)) {
         httpServletResponse.setHeader(X_CONTENT_TYPE_HEADER, xContentTypeHeader);
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariServerSecurityHeaderFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariServerSecurityHeaderFilter.java
index f9dc2aa778..8d093661e4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariServerSecurityHeaderFilter.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariServerSecurityHeaderFilter.java
@@ -47,6 +47,7 @@ public class AmbariServerSecurityHeaderFilter extends AbstractSecurityHeaderFilt
     setStrictTransportSecurity(configuration.getStrictTransportSecurityHTTPResponseHeader());
     setxFrameOptionsHeader(configuration.getXFrameOptionsHTTPResponseHeader());
     setxXSSProtectionHeader(configuration.getXXSSProtectionHTTPResponseHeader());
+    setContentSecurityPolicyHeader(configuration.getContentSecurityPolicyHTTPResponseHeader());
     setXContentTypeHeader(configuration.getXContentTypeHTTPResponseHeader());
     setCacheControlHeader(configuration.getCacheControlHTTPResponseHeader());
     setPragmaHeader(configuration.getPragmaHTTPResponseHeader());
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariViewsSecurityHeaderFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariViewsSecurityHeaderFilter.java
index 02fb4b3236..6b755fe2fd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariViewsSecurityHeaderFilter.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/AmbariViewsSecurityHeaderFilter.java
@@ -43,6 +43,7 @@ public class AmbariViewsSecurityHeaderFilter extends AbstractSecurityHeaderFilte
     setStrictTransportSecurity(configuration.getViewsStrictTransportSecurityHTTPResponseHeader());
     setxFrameOptionsHeader(configuration.getViewsXFrameOptionsHTTPResponseHeader());
     setxXSSProtectionHeader(configuration.getViewsXXSSProtectionHTTPResponseHeader());
+    setContentSecurityPolicyHeader(configuration.getViewsContentSecurityPolicyHTTPResponseHeader());
     setXContentTypeHeader(configuration.getViewsXContentTypeHTTPResponseHeader());
     setCacheControlHeader(configuration.getViewsCacheControlHTTPResponseHeader());
     setPragmaHeader(configuration.getViewsPragmaHTTPResponseHeader());
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
index f8cf31a5ee..2e43853591 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
@@ -82,6 +82,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.audit.AuditLogger;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.events.publishers.AgentCommandsPublisher;
+import org.apache.ambari.server.events.publishers.STOMPUpdatePublisher;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.OrmTestHelper;
@@ -181,7 +182,7 @@ public class TestHeartbeatHandler {
     injector.getInstance(GuiceJpaInitializer.class);
     clusters = injector.getInstance(Clusters.class);
     injector.injectMembers(this);
-    EasyMock.replay(auditLogger);
+    EasyMock.replay(auditLogger, injector.getInstance(STOMPUpdatePublisher.class));
   }
 
   @After
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/AmbariServerSecurityHeaderFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/AmbariServerSecurityHeaderFilterTest.java
index e8d3bfd96e..a2db5ceb50 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/AmbariServerSecurityHeaderFilterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/AmbariServerSecurityHeaderFilterTest.java
@@ -40,6 +40,7 @@ public class AmbariServerSecurityHeaderFilterTest extends AbstractSecurityHeader
     map.put(AbstractSecurityHeaderFilter.STRICT_TRANSPORT_HEADER, Configuration.HTTP_STRICT_TRANSPORT_HEADER_VALUE.getKey());
     map.put(AbstractSecurityHeaderFilter.X_FRAME_OPTIONS_HEADER, Configuration.HTTP_X_FRAME_OPTIONS_HEADER_VALUE.getKey());
     map.put(AbstractSecurityHeaderFilter.X_XSS_PROTECTION_HEADER, Configuration.HTTP_X_XSS_PROTECTION_HEADER_VALUE.getKey());
+    map.put(AbstractSecurityHeaderFilter.CONTENT_SECURITY_POLICY_HEADER, Configuration.HTTP_CONTENT_SECURITY_POLICY_HEADER_VALUE.getKey());
     map.put(AbstractSecurityHeaderFilter.X_CONTENT_TYPE_HEADER, Configuration.HTTP_X_CONTENT_TYPE_HEADER_VALUE.getKey());
     map.put(AbstractSecurityHeaderFilter.CACHE_CONTROL_HEADER, Configuration.HTTP_CACHE_CONTROL_HEADER_VALUE.getKey());
     map.put(AbstractSecurityHeaderFilter.PRAGMA_HEADER, Configuration.HTTP_PRAGMA_HEADER_VALUE.getKey());
@@ -50,6 +51,7 @@ public class AmbariServerSecurityHeaderFilterTest extends AbstractSecurityHeader
     map.put(AbstractSecurityHeaderFilter.STRICT_TRANSPORT_HEADER, Configuration.HTTP_STRICT_TRANSPORT_HEADER_VALUE.getDefaultValue());
     map.put(AbstractSecurityHeaderFilter.X_FRAME_OPTIONS_HEADER, Configuration.HTTP_X_FRAME_OPTIONS_HEADER_VALUE.getDefaultValue());
     map.put(AbstractSecurityHeaderFilter.X_XSS_PROTECTION_HEADER, Configuration.HTTP_X_XSS_PROTECTION_HEADER_VALUE.getDefaultValue());
+    map.put(AbstractSecurityHeaderFilter.CONTENT_SECURITY_POLICY_HEADER, Configuration.HTTP_CONTENT_SECURITY_POLICY_HEADER_VALUE.getDefaultValue());
     map.put(AbstractSecurityHeaderFilter.X_CONTENT_TYPE_HEADER, Configuration.HTTP_X_CONTENT_TYPE_HEADER_VALUE.getDefaultValue());
     map.put(AbstractSecurityHeaderFilter.CACHE_CONTROL_HEADER, Configuration.HTTP_CACHE_CONTROL_HEADER_VALUE.getDefaultValue());
     map.put(AbstractSecurityHeaderFilter.PRAGMA_HEADER, Configuration.HTTP_PRAGMA_HEADER_VALUE.getDefaultValue());
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index 7089ecf070..0b6a2ee31e 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -67,55 +67,56 @@ with patch.object(platform, "linux_distribution", return_value = MagicMock(retur
       with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}):
         with patch("platform.linux_distribution", return_value = os_distro_value):
           with patch("os.symlink"):
-            with patch("glob.glob", return_value = ['/etc/init.d/postgresql-9.3']):
-              _ambari_server_ = __import__('ambari-server')
-              with patch("__builtin__.open"):
-                from ambari_commons.firewall import Firewall
-                from ambari_commons.os_check import OSCheck, OSConst
-                from ambari_commons.os_family_impl import OsFamilyImpl, OsFamilyFuncImpl
-                from ambari_commons.exceptions import FatalException, NonFatalException
-                from ambari_commons.logging_utils import get_verbose, set_verbose, get_silent, set_silent, get_debug_mode, \
-                  print_info_msg, print_warning_msg, print_error_msg
-                from ambari_commons.os_utils import run_os_command, search_file, set_file_permissions, remove_file, copy_file, \
-                  is_valid_filepath
-                from ambari_server.dbConfiguration import DBMSConfigFactory, check_jdbc_drivers, DBMSConfig
-                from ambari_server.dbConfiguration_linux import PGConfig, LinuxDBMSConfig, OracleConfig
-                from ambari_server.properties import Properties
-                from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException
-                from ambari_server.serverConfiguration import configDefaults, check_database_name_property, OS_FAMILY_PROPERTY, \
-                  find_properties_file, get_ambari_properties, get_JAVA_HOME, \
-                  parse_properties_file, read_ambari_user, update_ambari_properties, update_properties_2, write_property, find_jdk, \
-                  get_is_active_instance, \
-                  AMBARI_CONF_VAR, AMBARI_SERVER_LIB, JDBC_DATABASE_PROPERTY, JDBC_RCA_PASSWORD_FILE_PROPERTY, \
-                  PERSISTENCE_TYPE_PROPERTY, JDBC_URL_PROPERTY, get_conf_dir, JDBC_USER_NAME_PROPERTY, JDBC_PASSWORD_PROPERTY, \
-                  JDBC_DATABASE_NAME_PROPERTY, OS_TYPE_PROPERTY, validate_jdk, JDBC_POSTGRES_SCHEMA_PROPERTY, \
-                  RESOURCES_DIR_PROPERTY, JDBC_RCA_PASSWORD_ALIAS, JDBC_RCA_SCHEMA_PROPERTY, \
-                  SSL_API, SSL_API_PORT, CLIENT_API_PORT_PROPERTY,\
-                  JDBC_CONNECTION_POOL_TYPE, LDAP_MGR_PASSWORD_PROPERTY, LDAP_MGR_PASSWORD_ALIAS, JDBC_PASSWORD_FILENAME, NR_USER_PROPERTY, SECURITY_KEY_IS_PERSISTED, \
-                  SECURITY_IS_ENCRYPTION_ENABLED, PID_DIR_PROPERTY, \
-                  SECURITY_MASTER_KEY_LOCATION, SECURITY_KEYS_DIR, store_password_file, \
-                  get_pass_file_path, GET_FQDN_SERVICE_URL, SECURITY_KEY_ENV_VAR_NAME, \
-                  JAVA_HOME_PROPERTY, JDK_NAME_PROPERTY, JCE_NAME_PROPERTY, STACK_LOCATION_KEY, SERVER_VERSION_FILE_PATH, \
-                  COMMON_SERVICES_PATH_PROPERTY, WEBAPP_DIR_PROPERTY, SHARED_RESOURCES_DIR, BOOTSTRAP_SCRIPT, \
-                  CUSTOM_ACTION_DEFINITIONS, BOOTSTRAP_SETUP_AGENT_SCRIPT, STACKADVISOR_SCRIPT, BOOTSTRAP_DIR_PROPERTY, MPACKS_STAGING_PATH_PROPERTY, STACK_JAVA_VERSION
-                from ambari_server.serverUtils import is_server_runing, refresh_stack_hash
-                from ambari_server.serverSetup import check_selinux, check_ambari_user, setup_jdbc, SE_STATUS_DISABLED, SE_MODE_ENFORCING, configure_os_settings, \
-                  download_and_install_jdk, prompt_db_properties, setup, \
-                  AmbariUserChecks, JDKSetup, reset, setup_jce_policy, expand_jce_zip_file, check_ambari_java_version_is_valid
-                from ambari_server.serverUpgrade import upgrade, run_schema_upgrade, move_user_custom_actions, find_and_copy_custom_services
-                from ambari_server.setupHttps import is_valid_https_port, setup_https, import_cert_and_key_action, get_fqdn, \
-                  generate_random_string, get_cert_info, COMMON_NAME_ATTR, is_valid_cert_exp, NOT_AFTER_ATTR, NOT_BEFORE_ATTR, \
-                  SSL_DATE_FORMAT, import_cert_and_key, is_valid_cert_host, setup_truststore, \
-                  SRVR_ONE_WAY_SSL_PORT_PROPERTY, SRVR_TWO_WAY_SSL_PORT_PROPERTY
-                from ambari_server.setupSecurity import adjust_directory_permissions, get_alias_string, get_ldap_event_spec_names, sync_ldap, \
-                  configure_ldap_password, setup_ldap, REGEX_HOSTNAME_PORT, REGEX_TRUE_FALSE, REGEX_ANYTHING,\
-                  setup_ambari_krb5_jaas, LDAP_GENERIC, should_query_ldap_type, LdapPropTemplate, LdapDefault, LdapDefaultMap
-                from ambari_server.userInput import get_YN_input, get_choice_string_input, get_validated_string_input, \
-                  read_password
-                from ambari_server_main import get_ulimit_open_files, ULIMIT_OPEN_FILES_KEY, ULIMIT_OPEN_FILES_DEFAULT
-                from ambari_server.serverClassPath import JDBC_DRIVER_PATH_PROPERTY, ServerClassPath
-                from ambari_server.hostUpdate import update_host_names
-                from ambari_server.checkDatabase import check_database
+            with patch.object(os_utils, "is_service_exist", return_value = True):
+              with patch("glob.glob", return_value = ['/etc/init.d/postgresql-9.3']):
+                _ambari_server_ = __import__('ambari-server')
+                with patch("__builtin__.open"):
+                  from ambari_commons.firewall import Firewall
+                  from ambari_commons.os_check import OSCheck, OSConst
+                  from ambari_commons.os_family_impl import OsFamilyImpl, OsFamilyFuncImpl
+                  from ambari_commons.exceptions import FatalException, NonFatalException
+                  from ambari_commons.logging_utils import get_verbose, set_verbose, get_silent, set_silent, get_debug_mode, \
+                    print_info_msg, print_warning_msg, print_error_msg
+                  from ambari_commons.os_utils import run_os_command, search_file, set_file_permissions, remove_file, copy_file, \
+                    is_valid_filepath
+                  from ambari_server.dbConfiguration import DBMSConfigFactory, check_jdbc_drivers, DBMSConfig
+                  from ambari_server.dbConfiguration_linux import PGConfig, LinuxDBMSConfig, OracleConfig
+                  from ambari_server.properties import Properties
+                  from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException
+                  from ambari_server.serverConfiguration import configDefaults, check_database_name_property, OS_FAMILY_PROPERTY, \
+                    find_properties_file, get_ambari_properties, get_JAVA_HOME, \
+                    parse_properties_file, read_ambari_user, update_ambari_properties, update_properties_2, write_property, find_jdk, \
+                    get_is_active_instance, \
+                    AMBARI_CONF_VAR, AMBARI_SERVER_LIB, JDBC_DATABASE_PROPERTY, JDBC_RCA_PASSWORD_FILE_PROPERTY, \
+                    PERSISTENCE_TYPE_PROPERTY, JDBC_URL_PROPERTY, get_conf_dir, JDBC_USER_NAME_PROPERTY, JDBC_PASSWORD_PROPERTY, \
+                    JDBC_DATABASE_NAME_PROPERTY, OS_TYPE_PROPERTY, validate_jdk, JDBC_POSTGRES_SCHEMA_PROPERTY, \
+                    RESOURCES_DIR_PROPERTY, JDBC_RCA_PASSWORD_ALIAS, JDBC_RCA_SCHEMA_PROPERTY, \
+                    SSL_API, SSL_API_PORT, CLIENT_API_PORT_PROPERTY,\
+                    JDBC_CONNECTION_POOL_TYPE, LDAP_MGR_PASSWORD_PROPERTY, LDAP_MGR_PASSWORD_ALIAS, JDBC_PASSWORD_FILENAME, NR_USER_PROPERTY, SECURITY_KEY_IS_PERSISTED, \
+                    SECURITY_IS_ENCRYPTION_ENABLED, PID_DIR_PROPERTY, \
+                    SECURITY_MASTER_KEY_LOCATION, SECURITY_KEYS_DIR, store_password_file, \
+                    get_pass_file_path, GET_FQDN_SERVICE_URL, SECURITY_KEY_ENV_VAR_NAME, \
+                    JAVA_HOME_PROPERTY, JDK_NAME_PROPERTY, JCE_NAME_PROPERTY, STACK_LOCATION_KEY, SERVER_VERSION_FILE_PATH, \
+                    COMMON_SERVICES_PATH_PROPERTY, WEBAPP_DIR_PROPERTY, SHARED_RESOURCES_DIR, BOOTSTRAP_SCRIPT, \
+                    CUSTOM_ACTION_DEFINITIONS, BOOTSTRAP_SETUP_AGENT_SCRIPT, STACKADVISOR_SCRIPT, BOOTSTRAP_DIR_PROPERTY, MPACKS_STAGING_PATH_PROPERTY, STACK_JAVA_VERSION
+                  from ambari_server.serverUtils import is_server_runing, refresh_stack_hash
+                  from ambari_server.serverSetup import check_selinux, check_ambari_user, setup_jdbc, SE_STATUS_DISABLED, SE_MODE_ENFORCING, configure_os_settings, \
+                    download_and_install_jdk, prompt_db_properties, setup, \
+                    AmbariUserChecks, JDKSetup, reset, setup_jce_policy, expand_jce_zip_file, check_ambari_java_version_is_valid
+                  from ambari_server.serverUpgrade import upgrade, run_schema_upgrade, move_user_custom_actions, find_and_copy_custom_services
+                  from ambari_server.setupHttps import is_valid_https_port, setup_https, import_cert_and_key_action, get_fqdn, \
+                    generate_random_string, get_cert_info, COMMON_NAME_ATTR, is_valid_cert_exp, NOT_AFTER_ATTR, NOT_BEFORE_ATTR, \
+                    SSL_DATE_FORMAT, import_cert_and_key, is_valid_cert_host, setup_truststore, \
+                    SRVR_ONE_WAY_SSL_PORT_PROPERTY, SRVR_TWO_WAY_SSL_PORT_PROPERTY
+                  from ambari_server.setupSecurity import adjust_directory_permissions, get_alias_string, get_ldap_event_spec_names, sync_ldap, \
+                    configure_ldap_password, setup_ldap, REGEX_HOSTNAME_PORT, REGEX_TRUE_FALSE, REGEX_ANYTHING, \
+                    setup_ambari_krb5_jaas, LDAP_GENERIC, should_query_ldap_type, LdapPropTemplate, LdapDefault, LdapDefaultMap
+                  from ambari_server.userInput import get_YN_input, get_choice_string_input, get_validated_string_input, \
+                    read_password
+                  from ambari_server_main import get_ulimit_open_files, ULIMIT_OPEN_FILES_KEY, ULIMIT_OPEN_FILES_DEFAULT
+                  from ambari_server.serverClassPath import JDBC_DRIVER_PATH_PROPERTY, ServerClassPath
+                  from ambari_server.hostUpdate import update_host_names
+                  from ambari_server.checkDatabase import check_database
 
 CURR_AMBARI_VERSION = "2.0.0"
 
diff --git a/ambari-server/src/test/python/TestMpacks.py b/ambari-server/src/test/python/TestMpacks.py
index 1a45038c9b..6001af626c 100644
--- a/ambari-server/src/test/python/TestMpacks.py
+++ b/ambari-server/src/test/python/TestMpacks.py
@@ -39,13 +39,14 @@ with patch.object(platform, "linux_distribution", return_value = MagicMock(retur
       with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}):
         with patch("platform.linux_distribution", return_value = os_distro_value):
           with patch("os.symlink"):
-            with patch("glob.glob", return_value = ['/etc/init.d/postgresql-9.3']):
-              _ambari_server_ = __import__('ambari-server')
-              os_utils.search_file = _search_file
-              with patch("__builtin__.open"):
-                from ambari_commons.exceptions import FatalException, NonFatalException
-                from ambari_server import serverConfiguration
-                serverConfiguration.search_file = _search_file
+            with patch.object(os_utils, "is_service_exist", return_value = True):
+              with patch("glob.glob", return_value = ['/etc/init.d/postgresql-9.3']):
+                _ambari_server_ = __import__('ambari-server')
+                os_utils.search_file = _search_file
+                with patch("__builtin__.open"):
+                  from ambari_commons.exceptions import FatalException, NonFatalException
+                  from ambari_server import serverConfiguration
+                  serverConfiguration.search_file = _search_file
 
 from ambari_server.setupMpacks import install_mpack, upgrade_mpack, replay_mpack_logs, \
   purge_stacks_and_mpacks, validate_purge, read_mpack_metadata, _uninstall_mpack, \
diff --git a/ambari-server/src/test/python/TestOSCheck.py b/ambari-server/src/test/python/TestOSCheck.py
index 9aba78b2ec..e91ad99583 100644
--- a/ambari-server/src/test/python/TestOSCheck.py
+++ b/ambari-server/src/test/python/TestOSCheck.py
@@ -48,11 +48,12 @@ with patch("os.path.isdir", return_value = MagicMock(return_value=True)):
     with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}):
       with patch("platform.linux_distribution", return_value = os_distro_value_linux):
         with patch.object(OSCheck, "os_distribution", return_value = os_distro_value):
-          with patch.object(utils, "get_postgre_hba_dir"):
-            os.environ["ROOT"] = ""
-            ambari_server = __import__('ambari-server')
-      
-            from ambari_server.serverConfiguration import update_ambari_properties, configDefaults
+          with patch.object(os_utils, "is_service_exist", return_value = True):
+            with patch.object(utils, "get_postgre_hba_dir"):
+              os.environ["ROOT"] = ""
+              ambari_server = __import__('ambari-server')
+
+              from ambari_server.serverConfiguration import update_ambari_properties, configDefaults
 
 @patch.object(platform, "linux_distribution", new = MagicMock(return_value=('Redhat', '6.4', 'Final')))
 class TestOSCheck(TestCase):
diff --git a/ambari-server/src/test/python/TestSetupTrustedProxy.py b/ambari-server/src/test/python/TestSetupTrustedProxy.py
index 7c02f49713..2d4205b43c 100644
--- a/ambari-server/src/test/python/TestSetupTrustedProxy.py
+++ b/ambari-server/src/test/python/TestSetupTrustedProxy.py
@@ -65,12 +65,13 @@ with patch.object(platform, "linux_distribution", return_value = MagicMock(retur
       with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}):
         with patch("platform.linux_distribution", return_value = os_distro_value):
           with patch("os.symlink"):
-            with patch("glob.glob", return_value = ['/etc/init.d/postgresql-9.3']):
-              _ambari_server_ = __import__('ambari-server')
-              with patch("__builtin__.open"):
-                from ambari_commons.exceptions import FatalException, NonFatalException
-                from ambari_server.properties import Properties
-                from ambari_server.setupTrustedProxy import setup_trusted_proxy, TPROXY_SUPPORT_ENABLED, PROXYUSER_HOSTS, PROXYUSER_USERS, PROXYUSER_GROUPS
+            with patch.object(os_utils, "is_service_exist", return_value = True):
+              with patch("glob.glob", return_value = ['/etc/init.d/postgresql-9.3']):
+                _ambari_server_ = __import__('ambari-server')
+                with patch("__builtin__.open"):
+                  from ambari_commons.exceptions import FatalException, NonFatalException
+                  from ambari_server.properties import Properties
+                  from ambari_server.setupTrustedProxy import setup_trusted_proxy, TPROXY_SUPPORT_ENABLED, PROXYUSER_HOSTS, PROXYUSER_USERS, PROXYUSER_GROUPS
 
 class TestSetupTrustedProxy(unittest.TestCase):
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ambari.apache.org
For additional commands, e-mail: commits-help@ambari.apache.org