Add SSM deployment and reliable Maven setup

This commit is contained in:
王鹏
2026-10-08 17:58:09 +08:00
parent 2d7b6216ba
commit d1695eba74
13 changed files with 626 additions and 46 deletions

View File

@@ -1,8 +1,20 @@
import hashlib
import io
import tempfile
import unittest
import zipfile
from pathlib import Path
from deploy_tool.installer import build_install_command, explain_install_failure, format_install_output, recommend_jdk_version
from deploy_tool.installer import (
MAVEN_ARCHIVE_NAME,
TOMCAT_VERSION,
install_maven,
install_tomcat,
build_install_command,
explain_install_failure,
format_install_output,
recommend_jdk_version,
)
from deploy_tool.scanner import scan_project
@@ -73,6 +85,54 @@ class InstallerTests(unittest.TestCase):
self.assertEqual(command, ["winget", "install", "-e", "--id", "OpenJS.NodeJS.LTS"])
def test_maven_is_not_offered_as_an_invalid_winget_package(self):
with self.assertRaises(ValueError):
build_install_command("Maven")
def test_installs_maven_from_verified_apache_archive(self):
archive_buffer = io.BytesIO()
with zipfile.ZipFile(archive_buffer, "w") as archive:
archive.writestr("apache-maven-3.10.0/bin/mvn.cmd", "@echo off")
archive_bytes = archive_buffer.getvalue()
checksum = hashlib.sha512(archive_bytes).hexdigest().encode("ascii")
def opener(url, timeout):
return io.BytesIO(checksum if url.endswith(".sha512") else archive_bytes)
with tempfile.TemporaryDirectory() as tmp:
messages = []
executable = install_maven(messages.append, Path(tmp), opener)
self.assertTrue(executable.exists())
self.assertEqual(executable.read_text(), "@echo off")
self.assertTrue(any("校验通过" in message for message in messages))
def test_rejects_maven_archive_with_wrong_checksum(self):
def opener(url, timeout):
payload = ("0" * 128).encode("ascii") if url.endswith(".sha512") else b"not-a-zip"
return io.BytesIO(payload)
with tempfile.TemporaryDirectory() as tmp:
with self.assertRaisesRegex(RuntimeError, "SHA-512"):
install_maven(lambda _message: None, Path(tmp), opener)
self.assertFalse((Path(tmp) / MAVEN_ARCHIVE_NAME.removesuffix("-bin.zip")).exists())
def test_installs_tomcat_from_verified_apache_archive(self):
archive_buffer = io.BytesIO()
with zipfile.ZipFile(archive_buffer, "w") as archive:
archive.writestr(f"apache-tomcat-{TOMCAT_VERSION}/bin/catalina.bat", "@echo off")
archive_bytes = archive_buffer.getvalue()
checksum = hashlib.sha512(archive_bytes).hexdigest().encode("ascii")
def opener(url, timeout):
return io.BytesIO(checksum if url.endswith(".sha512") else archive_bytes)
with tempfile.TemporaryDirectory() as tmp:
executable = install_tomcat(lambda _message: None, Path(tmp), opener)
self.assertTrue(executable.exists())
self.assertEqual(executable.name, "catalina.bat")
def test_formats_winget_progress_without_garbled_bar(self):
raw = "████████████▒▒▒▒▒▒ 63%\r".encode("utf-8")