fix(fileserver): admin reconcile의 @RequestBody에 @Valid를 더한다

web-fileserver admin 평면에서 orphans:reconcile만 @RequestBody에 @Valid가 없었다.
다른 다섯 핸들러(relocate·force-delete·submit-notification 등)는 모두 @Valid다.
지금은 OrphanReconcileHttpRequest에 Bean Validation 제약이 없어 드러나지 않지만,
나중에 limit에 @Min, reason에 @NotBlank를 더하면 @Valid가 없어 조용히 무시된다 —
이 템플릿이 평소 막는 검증 우회 부류다.

reconcileOrphans 파라미터에 @Valid를 더하고, 이 컨트롤러의 모든 @RequestBody가
@Valid를 갖는지 반사로 확인하는 막는 시험을 더해 admin 평면 전체에 규약을 고정한다.

검증: RED→GREEN — @Valid를 빼면 FileserverAdminControllerRequestBodyValidationTest
가 실패(rc=1, 그 파일 41행 AssertionError: offenders 비지 않음), 넣으면
:adapter:inbound:web-fileserver:test rc=0.
This commit is contained in:
DongHyeonka
2026-11-12 01:15:07 +09:00
parent 9fb5a61fc7
commit bb8bb31b9c
2 changed files with 45 additions and 1 deletions
@@ -113,7 +113,8 @@ public class FileserverAdminController {
path = "/internal/fileserver/orphans:reconcile",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public OrphanReconcileReport reconcileOrphans(@RequestBody OrphanReconcileHttpRequest request) {
public OrphanReconcileReport reconcileOrphans(
@Valid @RequestBody OrphanReconcileHttpRequest request) {
return reconcileOrphans.handle(toCommand(request, contextFactory.current()));
}
@@ -0,0 +1,43 @@
package dev.caskeleton.adapter.inbound.web.fileserver.admin;
import static org.assertj.core.api.Assertions.assertThat;
import jakarta.validation.Valid;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.web.bind.annotation.RequestBody;
/**
* W4 red team BE-INPUT-002 — every {@code @RequestBody} on the admin controller must also carry
* {@code @Valid}.
*
* <p>{@code reconcileOrphans} shipped a {@code @RequestBody} without {@code @Valid}, unlike every
* sibling handler (relocate/force-delete/…). Harmless today because {@code OrphanReconcileHttpRequest}
* declares no Bean Validation constraints — but the moment one is added (a {@code @Min} on the limit,
* a {@code @NotBlank} on the reason), it would be silently ignored, exactly the validation-bypass
* class this template otherwise guards against. This pins the convention for the whole admin plane so
* the gap cannot reopen.
*/
class FileserverAdminControllerRequestBodyValidationTest {
@Test
void everyRequestBodyParameterAlsoCarriesValid() {
List<String> offenders = new ArrayList<>();
for (Method method : FileserverAdminController.class.getDeclaredMethods()) {
for (Parameter parameter : method.getParameters()) {
if (parameter.isAnnotationPresent(RequestBody.class)
&& !parameter.isAnnotationPresent(Valid.class)) {
offenders.add(method.getName() + "(" + parameter.getType().getSimpleName() + ")");
}
}
}
assertThat(offenders)
.as(
"admin @RequestBody handlers without @Valid would silently drop any Bean Validation "
+ "constraint added to their DTO later (BE-INPUT-002)")
.isEmpty();
}
}