fix(phase-5.2): 消项 CR 第二轮 P1/P2/P3(通道/证据链/交付时序/后管证据页)

This commit is contained in:
2026-10-31 21:12:18 +08:00
parent a4e4456b50
commit 91d36327f9
61 changed files with 2833 additions and 311 deletions
@@ -0,0 +1,68 @@
package com.nanri.aiimage.common.security;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** P2-4:版本包/教程包发布前的压缩包凭据件扫描。 */
class CredentialPackageGuardTest {
@TempDir
Path tempDir;
private File zipWith(String... entries) throws IOException {
File zip = tempDir.resolve("pkg-" + System.nanoTime() + ".zip").toFile();
try (ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(zip.toPath()))) {
for (String entry : entries) {
out.putNextEntry(new ZipEntry(entry));
out.write("x".getBytes(StandardCharsets.UTF_8));
out.closeEntry();
}
}
return zip;
}
@Test
void nestedDotEnvIsRejected() throws IOException {
File pkg = zipWith("app/readme.txt", "app/conf/.env");
assertEquals("app/conf/.env", CredentialPackageGuard.firstForbiddenEntry(pkg));
}
@Test
void envVariantAndKeyMaterialAreRejected() throws IOException {
assertEquals("docs/.env.production",
CredentialPackageGuard.firstForbiddenEntry(zipWith("docs/.env.production")));
assertEquals("certs/server.PEM",
CredentialPackageGuard.firstForbiddenEntry(zipWith("certs/server.PEM")));
assertEquals("tools/kw_share_cfg.json",
CredentialPackageGuard.firstForbiddenEntry(zipWith("tools/kw_share_cfg.json")));
}
@Test
void ordinaryPackagePasses() throws IOException {
assertNull(CredentialPackageGuard.firstForbiddenEntry(
zipWith("app/readme.txt", "app/config/app.yml", "app/update/update.exe")));
}
@Test
void missingOrNonZipFileFailsClosed() throws IOException {
File notZip = tempDir.resolve("not-a-zip.zip").toFile();
Files.writeString(notZip.toPath(), "plain text");
IOException missing = assertThrows(IOException.class,
() -> CredentialPackageGuard.firstForbiddenEntry(tempDir.resolve("absent.zip").toFile()));
assertTrue(missing.getMessage().contains("missing"));
assertThrows(IOException.class, () -> CredentialPackageGuard.firstForbiddenEntry(notZip));
}
}