Enable six character MySQL passwords by default
This commit is contained in:
@@ -4,10 +4,14 @@ import tempfile
|
||||
import unittest
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from subprocess import CompletedProcess
|
||||
from unittest.mock import patch
|
||||
|
||||
from deploy_tool.installer import (
|
||||
MAVEN_ARCHIVE_NAME,
|
||||
MYSQL_VERSION,
|
||||
MYSQL_ROOT_PASSWORD,
|
||||
configure_mysql_weak_password_policy,
|
||||
TOMCAT_VERSION,
|
||||
install_maven,
|
||||
install_tomcat,
|
||||
@@ -106,10 +110,48 @@ class InstallerTests(unittest.TestCase):
|
||||
self.assertEqual(command[0:5], ["winget", "install", "--exact", "--id", "Oracle.MySQL"])
|
||||
self.assertEqual(command[command.index("--version") + 1], MYSQL_VERSION)
|
||||
self.assertEqual(MYSQL_VERSION, "8.0.43")
|
||||
override = command[command.index("--override") + 1]
|
||||
self.assertIn("root_passwd=123456", override)
|
||||
self.assertIn("open_win_firewall=false", override)
|
||||
self.assertIn("--accept-source-agreements", command)
|
||||
self.assertIn("--accept-package-agreements", command)
|
||||
self.assertIn("--disable-interactivity", command)
|
||||
|
||||
def test_persists_six_character_mysql_password_policy(self):
|
||||
query_result = CompletedProcess(
|
||||
[],
|
||||
0,
|
||||
stdout="validate_password.length\t8\nvalidate_password.policy\tMEDIUM\n",
|
||||
stderr="",
|
||||
)
|
||||
success = CompletedProcess([], 0, stdout="1\n", stderr="")
|
||||
|
||||
with patch("deploy_tool.installer.subprocess.run", side_effect=[query_result, success, success]) as run:
|
||||
messages = []
|
||||
configure_mysql_weak_password_policy(Path("mysql.exe"), messages.append, attempts=1)
|
||||
|
||||
configure_call = run.call_args_list[1]
|
||||
sql = configure_call.kwargs["input"]
|
||||
self.assertIn("SET PERSIST validate_password.policy = 'LOW'", sql)
|
||||
self.assertIn("SET PERSIST validate_password.length = 6", sql)
|
||||
self.assertIn("ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'", sql)
|
||||
self.assertEqual(configure_call.kwargs["env"]["MYSQL_PWD"], MYSQL_ROOT_PASSWORD)
|
||||
self.assertNotIn(MYSQL_ROOT_PASSWORD, configure_call.args[0])
|
||||
self.assertTrue(any("永久允许 6 位弱密码" in message for message in messages))
|
||||
|
||||
def test_mysql_without_validation_component_still_sets_and_verifies_password(self):
|
||||
no_component = CompletedProcess([], 0, stdout="", stderr="")
|
||||
success = CompletedProcess([], 0, stdout="1\n", stderr="")
|
||||
|
||||
with patch("deploy_tool.installer.subprocess.run", side_effect=[no_component, success, success]) as run:
|
||||
messages = []
|
||||
configure_mysql_weak_password_policy(Path("mysql.exe"), messages.append, attempts=1)
|
||||
|
||||
sql = run.call_args_list[1].kwargs["input"]
|
||||
self.assertNotIn("SET PERSIST", sql)
|
||||
self.assertIn("ALTER USER", sql)
|
||||
self.assertTrue(any("未启用 validate_password" in message for message in messages))
|
||||
|
||||
def test_maven_is_not_offered_as_an_invalid_winget_package(self):
|
||||
with self.assertRaises(ValueError):
|
||||
build_install_command("Maven")
|
||||
|
||||
Reference in New Issue
Block a user