fix: remove legacy cloud image import restriction

dev
admin 2 months ago
parent 40248c1064
commit 64205cf8f2

@ -3523,9 +3523,15 @@ byId("template-import-form").addEventListener("submit", async (event) => {
showError("template-import-error", "请填写不超过 64 个字符的模板名称。");
return;
}
if (!existingJobId && (!url || url.origin !== "https://repo.almalinux.org" || url.username || url.password || url.search || url.hash
|| !/^\/almalinux\/(9|10)\/cloud\/x86_64\/images\/AlmaLinux-\1-GenericCloud-[A-Za-z0-9._-]+\.x86_64\.qcow2$/.test(url.pathname))) {
showError("template-import-error", "目前仅支持 repo.almalinux.org 上的 AlmaLinux 9 / 10 x86_64 GenericCloud qcow2 HTTPS 地址。");
const officialHosts = new Set([
"repo.almalinux.org",
"cloud.debian.org",
"cloud-images.ubuntu.com",
"cloud.centos.org",
]);
if (!existingJobId && (!url || url.protocol !== "https:" || !officialHosts.has(url.hostname)
|| (url.port && url.port !== "443") || url.username || url.password || url.search || url.hash)) {
showError("template-import-error", "请填写受支持发行版官方镜像站的 HTTPS 文件地址。");
return;
}
if (!existingJobId && sha256 && !/^[a-f0-9]{64}$/.test(sha256)) {

@ -391,10 +391,10 @@
<div class="page-heading"><div><span class="eyebrow">CLOUD IMAGE CATALOG</span><h1>云镜像模板</h1><p>仅管理员可以导入官方云镜像和修改模板名称;用户创建虚拟机时选择已导入的版本。</p></div><button id="template-back-button" class="button button-outline" type="button">返回虚拟机</button></div>
<div class="template-admin-grid">
<section class="host-card" aria-labelledby="template-import-title">
<div class="host-card-heading"><span class="host-card-number">+</span><div><h2 id="template-import-title">导入云镜像</h2><p>从 AlmaLinux 官方仓库下载;可选择使用发布方 SHA-256 校验。</p></div></div>
<div class="host-card-heading"><span class="host-card-number">+</span><div><h2 id="template-import-title">导入云镜像</h2><p>从受支持发行版的官方镜像站下载;可选择使用发布方 SHA-256 校验。</p></div></div>
<form id="template-import-form" class="form-stack" novalidate>
<label for="template-name">模板名称</label><input id="template-name" type="text" maxlength="64" required autocomplete="off" placeholder="例如 AlmaLinux 10 Cloud" />
<label for="template-url">云镜像下载地址</label><input id="template-url" type="url" inputmode="url" maxlength="2048" required autocomplete="off" placeholder="粘贴官方 GenericCloud qcow2 完整 HTTPS 地址" /><small class="template-field-help">支持 repo.almalinux.org 的 AlmaLinux 9 / 10 x86_64 GenericCloud qcow2 镜像。</small>
<label for="template-url">云镜像下载地址</label><input id="template-url" type="url" inputmode="url" maxlength="2048" required autocomplete="off" placeholder="粘贴官方云镜像完整 HTTPS 文件地址" /><small class="template-field-help">支持 AlmaLinux 8/9/10、Debian 11/12/13、CentOS Stream 9/10 和 Ubuntu 20.04/22.04/24.04/25.04/25.10/26.04 官方 x86_64 云镜像;Ubuntu 官方 qcow2 内容的 .img 文件也可导入。</small>
<label for="template-sha256">镜像 SHA-256 校验值(可选)</label><input id="template-sha256" type="text" maxlength="64" spellcheck="false" autocomplete="off" placeholder="可留空;填写时必须为 64 位十六进制" /><small class="template-field-help">留空时面板仍会计算并保存实际 SHA-256;填写后会在导入前核对。</small>
<p id="template-import-status" class="template-import-status" role="status" hidden></p><p id="template-import-error" class="form-error" role="alert" hidden></p><button id="template-import-button" class="button button-primary" type="submit">导入模板</button>
</form>

@ -180,6 +180,34 @@ def test_system_family_metadata_recognizes_debian_centos_and_ubuntu() -> None:
assert "/^[0-9]+(?:\\.[0-9]+)?$/" in system_code
def test_template_import_form_accepts_every_supported_official_host() -> None:
script = (STATIC / "app.js").read_text(encoding="utf-8")
submit_code = script.split(
'byId("template-import-form").addEventListener("submit"', 1
)[1].split('byId("rescue-template-form")', 1)[0]
for hostname in (
"repo.almalinux.org",
"cloud.debian.org",
"cloud-images.ubuntu.com",
"cloud.centos.org",
):
assert f'"{hostname}"' in submit_code
assert 'url.protocol !== "https:"' in submit_code
assert 'url.port !== "443"' in submit_code
assert "url.username" in submit_code and "url.password" in submit_code
assert "url.search" in submit_code and "url.hash" in submit_code
assert "/almalinux\\/(9|10)" not in submit_code
page = (STATIC / "index.html").read_text(encoding="utf-8")
for label in (
"AlmaLinux 8/9/10",
"Debian 11/12/13",
"CentOS Stream 9/10",
"Ubuntu 20.04/22.04/24.04/25.04/25.10/26.04",
):
assert label in page
def test_version_cards_show_only_centered_template_name() -> None:
script = (STATIC / "app.js").read_text(encoding="utf-8")
catalog_code = script.split("function renderTemplateCatalog(inputId) {", 1)[1].split(

Loading…
Cancel
Save