Hide MySQL password setup console windows

This commit is contained in:
王鹏
2026-10-09 10:31:41 +08:00
parent 46ad9270c7
commit ef5869985a
2 changed files with 33 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
import hashlib
import io
import json
import os
import subprocess
import tempfile
import unittest
import zipfile
@@ -350,9 +352,30 @@ class InstallerTests(unittest.TestCase):
self.assertIn("ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'", sql)
self.assertEqual(configure_call.kwargs["env"]["MYSQL_PWD"], MYSQL_INITIAL_ROOT_PASSWORD)
self.assertEqual(run.call_args_list[2].kwargs["env"]["MYSQL_PWD"], MYSQL_ROOT_PASSWORD)
expected_creation_flags = getattr(subprocess, "CREATE_NO_WINDOW", 0) if os.name == "nt" else 0
self.assertTrue(all(call.kwargs["creationflags"] == expected_creation_flags for call in run.call_args_list))
self.assertNotIn(MYSQL_ROOT_PASSWORD, configure_call.args[0])
self.assertTrue(any("永久允许 6 位弱密码" in message for message in messages))
def test_mysql_password_configuration_stops_retrying_on_access_denied(self):
denied = CompletedProcess(
[],
1,
stdout="",
stderr="ERROR 1045 (28000): Access denied for user 'root'@'localhost'",
)
with patch("deploy_tool.installer.subprocess.run", return_value=denied) as run:
with self.assertRaisesRegex(RuntimeError, "Access denied"):
configure_mysql_weak_password_policy(
Path("mysql.exe"),
lambda _message: None,
attempts=30,
retry_delay=0,
)
self.assertEqual(run.call_count, 1)
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="")