fix: Invalid discoveryHandlerId can persist broken discovery upstream rows - #6530
Conversation
Aias00
left a comment
There was a problem hiding this comment.
Reviewed #6530. The fix correctly closes the reported path in #6466 (POST /discovery-upstream with a non-existent discoveryHandlerId → orphan row + NPE in fetchAll). It reuses the existing @Existed/DiscoveryHandlerMapper.existed validator the repo already uses for the id and namespaceId fields and for the PUT path variable, so it's consistent and correct for the HTTP create/update paths. No blocker from me.
Two non-blocking items:
-
No regression test (should_fix). Issue #6466 ships a 4-step repro and the PR adds no test. The H2
discovery_handlertable (schema.sql:1249),AbstractSpringIntegrationTest(@ActiveProfiles("h2")), andDiscoveryUpstreamMapperTest.existed()already provide the harness. Please add a controller/validation test that POSTs aDiscoveryUpstreamDTOwith a non-existentdiscoveryHandlerIdand asserts a 400 (plus a happy-path 200 with an existing handler) — otherwise a future revert/refactor of this annotation regresses silently. The PR checklist also leaves "submit test cases" unchecked. -
Update endpoint behavior (nit).
PUT /discovery-upstream/{discoveryHandlerId}now@Existed-validates thediscoveryHandlerIdinside each body element, butDiscoveryUpstreamServiceImpl.updateBatch(:115) overwrites it with the path id and ignores the body value. If the admin frontend sends a placeholder/mismatched id in the PUT body, this becomes a new 400. Please confirm the frontend sends the matching path id in each body element; if so, no action needed.
Out of scope (follow-up, not for this PR): the import/programmatic paths (DiscoveryUpstreamServiceImpl.importData at :255/:293, nativeCreateOrUpdate at :123, fed by Gson in ConfigsServiceImpl:440 and DiscoveryUpstreamDataConfigsExportImportHandler:59) bypass @Valid and can still insert orphan rows. They don't call fetchAll, so they dodge the NPE in #6466 — hence not blocking here — but a service-level existence check would fully match the issue title's intent.
…_broken_discovery_upstream_rows
|
Clean defensive fix — adding Is the validation actually exercised on every write path that can persist a No test (the body's "submit test cases" checkbox is unchecked). A test passing a non-existent |
…_broken_discovery_upstream_rows
Invalid discoveryHandlerId can persist broken discovery upstream rows
Fixes: #6466
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.