This is an automated email from the ASF dual-hosted git repository.
jialiang 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 8553ad22d4 AMBARI-26236: The database password character type
requirement is too few (#3883)
8553ad22d4 is described below
commit 8553ad22d48b9ad43e6b4805cfbd9bdf2527e8e8
Author: Peng Lu <[email protected]>
AuthorDate: Mon Nov 25 17:57:53 2024 +0800
AMBARI-26236: The database password character type requirement is too few
(#3883)
* The database password character type requirement is too few
* Add more special characters, and add UT for this case
* Update test case
---
.../python/ambari_server/dbConfiguration_linux.py | 4 +--
ambari-server/src/test/python/TestAmbariServer.py | 30 +++++++++++++++++++++-
2 files changed, 31 insertions(+), 3 deletions(-)
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 912e97df72..5b850c855c 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 @@ class LinuxDBMSConfig(DBMSConfig):
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 c863b211b3..738c4f5d7f 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -83,7 +83,7 @@ with patch.object(distro, "linux_distribution", return_value
= MagicMock(return_
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 @@ class TestAmbariServer(TestCase):
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()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]