test(dispatch): verify multi-photo evidence and synchronize PDF storage assertions

This commit is contained in:
2026-10-26 19:47:18 +08:00
parent a5befc9bad
commit 3e0d8d6c88
3 changed files with 94 additions and 5 deletions
@@ -45,8 +45,9 @@ class OwnedBusinessPhotoFileTest {
verifyNoInteractions(files, storage);
}
/** 装车驾驶证允许 PDF;油耗仍限图片,两类都拒绝空文件、伪造内容和超限文件。 */
@ParameterizedTest @ValueSource(strings = {LOADING, FUEL})
void storesRealImagesButRejectsPdfSpoofedEmptyAndOversizedFiles(String type) throws Exception {
void enforcesLoadingAndFuelFormatPoliciesAndRejectsInvalidFiles(String type) throws Exception {
var storage = new BusinessFileStorage();
ReflectionTestUtils.setField(storage, "configuredRoot", root);
storage.initializeRoot();
@@ -60,8 +61,14 @@ class OwnedBusinessPhotoFileTest {
for (var upload : new MockMultipartFile[]{
new MockMultipartFile("file", "empty.png", "image/png", new byte[0]),
new MockMultipartFile("file", "spoof.png", "image/png", "not-image".getBytes()),
new MockMultipartFile("file", "receipt.pdf", "application/pdf", "%PDF-1.7\nreceipt".getBytes())})
new MockMultipartFile("file", "spoof.pdf", "application/pdf", "not-pdf".getBytes())})
assertThatThrownBy(() -> storage.store(0, "71", upload, category)).isInstanceOf(BizException.class);
var pdf = new MockMultipartFile("file", "license.pdf", "application/pdf", "%PDF-1.7\nTEST license".getBytes());
if (LOADING.equals(type)) {
var saved = storage.store(0, "71", pdf, category);
assertThat(saved.contentType()).isEqualTo("application/pdf");
assertThat(storage.read(saved.objectKey())).isEqualTo(pdf.getBytes());
} else assertThatThrownBy(() -> storage.store(0, "71", pdf, category)).isInstanceOf(BizException.class);
MultipartFile oversized = mock(MultipartFile.class);
when(oversized.isEmpty()).thenReturn(false);
when(oversized.getSize()).thenReturn(10L * 1024 * 1024 + 1);