Retry Node downloads with Windows trust
This commit is contained in:
@@ -2,9 +2,11 @@ import hashlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import ssl
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
import urllib.error
|
||||
import zipfile
|
||||
import ctypes
|
||||
from pathlib import Path
|
||||
@@ -195,6 +197,49 @@ class InstallerTests(unittest.TestCase):
|
||||
self.assertTrue(npm.exists())
|
||||
self.assertTrue(any("自动选择 Node.js 20.12.2" in message for message in messages))
|
||||
|
||||
def test_node_download_retries_with_windows_certificate_store(self):
|
||||
version = "20.12.2"
|
||||
directory = f"node-v{version}-win-x64"
|
||||
archive_name = f"{directory}.zip"
|
||||
archive_buffer = io.BytesIO()
|
||||
with zipfile.ZipFile(archive_buffer, "w") as archive:
|
||||
archive.writestr(f"{directory}/node.exe", "node")
|
||||
archive.writestr(f"{directory}/npm.cmd", "npm")
|
||||
archive_bytes = archive_buffer.getvalue()
|
||||
checksum = hashlib.sha256(archive_bytes).hexdigest()
|
||||
index_bytes = json.dumps(
|
||||
[{"version": f"v{version}", "lts": "Iron", "files": ["win-x64-zip"]}]
|
||||
).encode("utf-8")
|
||||
|
||||
def certificate_failure(_url, timeout):
|
||||
raise urllib.error.URLError(ssl.SSLCertVerificationError("self-signed certificate"))
|
||||
|
||||
def windows_download(url, destination, timeout):
|
||||
if url.endswith("index.json"):
|
||||
payload = index_bytes
|
||||
elif url.endswith("SHASUMS256.txt"):
|
||||
payload = f"{checksum} {archive_name}\n".encode("ascii")
|
||||
else:
|
||||
payload = archive_bytes
|
||||
destination.write_bytes(payload)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
with (
|
||||
patch("deploy_tool.installer.urllib.request.urlopen", side_effect=certificate_failure),
|
||||
patch(
|
||||
"deploy_tool.installer._download_with_windows_certificates",
|
||||
side_effect=windows_download,
|
||||
) as fallback,
|
||||
patch("deploy_tool.installer.os.name", "nt"),
|
||||
):
|
||||
messages = []
|
||||
node, npm, installed_version = install_node((">=18 <21",), messages.append, Path(tmp))
|
||||
self.assertEqual(installed_version, version)
|
||||
self.assertTrue(node.exists())
|
||||
self.assertTrue(npm.exists())
|
||||
self.assertEqual(fallback.call_count, 3)
|
||||
self.assertTrue(any("Windows 系统证书存储" in message for message in messages))
|
||||
|
||||
def test_builds_unattended_mysql_msi_install_command(self):
|
||||
command = build_mysql_installer_command(Path("mysql-installer.msi"), Path("mysql-install.log"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user