Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMBARI-26236: The database password character type requirement is too few #3883

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 29 additions & 1 deletion ambari-server/src/test/python/TestAmbariServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down