diff --git a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py index 912e97df729..5b850c855c8 100644 --- a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py +++ b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py @@ -224,9 +224,9 @@ def _configure_database_password(showDefault=True, defaultPassword=DEFAULT_PASSW passwordPrompt = 'Enter Database Password (' + passwordDefault + '): ' else: passwordPrompt = 'Enter Database Password: ' - passwordPattern = "^[a-zA-Z0-9_-]*$" + passwordPattern = "^[a-zA-Z0-9!#$%@^&=+\\[\\]\\{\\}\\(\\)<>.*?;:'\"_-]*$" passwordDescr = "Invalid characters in password. Use only alphanumeric or " \ - "_ or - characters" + "some special characters, such as !#$%@^&=+[]{}()<>.*?;:'\"_- " password = read_password(passwordDefault, passwordPattern, passwordPrompt, passwordDescr) diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py index c863b211b3c..738c4f5d7f7 100644 --- a/ambari-server/src/test/python/TestAmbariServer.py +++ b/ambari-server/src/test/python/TestAmbariServer.py @@ -83,7 +83,7 @@ def search_file_proxy(filename, searchpatch, pathsep=os.pathsep): 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 import DBMSConfigFactory, check_jdbc_drivers, DBMSConfig, DEFAULT_PASSWORD from ambari_server.dbConfiguration_linux import PGConfig, LinuxDBMSConfig, OracleConfig from ambari_server.properties import Properties from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException @@ -8066,6 +8066,34 @@ def test_configure_ldap_password(self, read_password_method): sys.stdout = sys.__stdout__ pass + @patch("ambari_server.userInput.get_password") + def test_configure_database_password(self, get_password_method): + ''' Test default password ''' + get_password_method.side_effect = ['', ''] + password = LinuxDBMSConfig._configure_database_password(True) + self.assertEqual(DEFAULT_PASSWORD, password) + + get_password_method.reset_mock() + + ''' Test password string only contains alphanumeric characters ''' + get_password_method.side_effect = ['bigdata123', 'bigdata123'] + password = LinuxDBMSConfig._configure_database_password(True) + self.assertEqual("bigdata123", password) + + get_password_method.reset_mock() + + ''' Test password string contains special characters ''' + get_password_method.side_effect = ['admin@123', 'admin@123'] + password = LinuxDBMSConfig._configure_database_password(True) + self.assertEqual("admin@123", password) + + get_password_method.reset_mock() + + ''' Test password string contains multiple special characters ''' + get_password_method.side_effect = ['admin@_123!#$%@^=+[]{}<>.*?;:"\'-&', 'admin@_123!#$%@^=+[]{}<>.*?;:"\'-&'] + password = LinuxDBMSConfig._configure_database_password(True) + self.assertEqual('admin@_123!#$%@^=+[]{}<>.*?;:"\'-&', password) + @patch("ambari_server.userInput.get_validated_string_input") def test_read_password(self, get_validated_string_input_method): out = io.StringIO()