From 8e81232075e848df5c081853b8e0a312ace004ab Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sat, 21 Nov 2026 14:52:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?test(notification):=20=EC=9A=B4=EC=98=81?= =?UTF-8?q?=EC=9E=90=20=EC=9C=A0=EC=8A=A4=EC=BC=80=EC=9D=B4=EC=8A=A4?= =?UTF-8?q?=EC=9D=98=20=EA=B6=8C=ED=95=9C=C2=B7tenant=C2=B7=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EB=B0=9C=EC=86=A1=20=EC=8A=B9=EC=9D=B8=20=EA=B1=B0?= =?UTF-8?q?=EC=A0=88=EC=9D=84=20=EC=8B=9C=ED=97=98=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 운영자 유스케이스 넷(suppression 변경, redrive, reconcile, provider 상태)은 command의 AdminActor로 authority와 tenant를 한 번 더 보고, redrive는 결과가 불명확한 시도를 승인 없이 다시 보내지 않는다. 그런데 NotificationAdminUseCasesTest의 거절 시험 둘은 authority를 가진 actor가 tenant 검사에서 거절되는 경우뿐이고, redrive 시험은 모두 승인을 켰다. 그래서 require·requireTenant·duplicateRiskGuard.verify 줄을 지워도 모든 시험이 통과한다(허브 변이 확인). 같은 시험 클래스에 넷을 더한다. - 유스케이스 넷을 표로 돌려, 그 유스케이스의 authority만 빠지고 나머지 운영자 authority는 다 가진 전역 actor가 AdminAccessDeniedException (required = 그 authority)으로 거절되고 claim이 없음을 본다. 빈 Set 대신 나머지 전부를 쥐여, 다른 authority로는 통과하지 못함까지 본다. - tenant-b actor가 tenant-a의 suppression을 바꾸거나 tenant-a 시도를 redrive하면 거절되고, suppression·recipient 상태·claim이 그대로다. - AMBIGUOUS 시도를 승인 없이 redrive하면 DuplicateRiskApprovalRequiredException(AMBIGUOUS_SUBMISSION)이고 recipient 상태가 FAILED 그대로이며 claim이 없다. guard를 annotation·AOP로 옮겨 ArchUnit으로 강제하는 안은 버렸다. 규칙이 actor·tenant 값에 기대서 정적 검사로 증명되지 않는다. 위험·한계: main 코드와 guard는 바꾸지 않았다. 거절 뒤 "그대로"는 guard가 쓰기 앞에 있는 지금 순서를 고정한다. 순서를 바꾸면 이 시험이 먼저 깨진다. 검증: desktop RED·GREEN은 PR 본문에 둔다. Refs: REV-BE-0033 --- .../admin/NotificationAdminUseCasesTest.java | 215 ++++++++++++++++++ 1 file changed, 215 insertions(+) diff --git a/src/application/notification/src/test/java/dev/caskeleton/application/notification/platform/admin/NotificationAdminUseCasesTest.java b/src/application/notification/src/test/java/dev/caskeleton/application/notification/platform/admin/NotificationAdminUseCasesTest.java index 23681873..14fddc5f 100644 --- a/src/application/notification/src/test/java/dev/caskeleton/application/notification/platform/admin/NotificationAdminUseCasesTest.java +++ b/src/application/notification/src/test/java/dev/caskeleton/application/notification/platform/admin/NotificationAdminUseCasesTest.java @@ -15,6 +15,7 @@ import dev.caskeleton.application.notification.platform.api.delivery.DeliveryOut import dev.caskeleton.application.notification.platform.api.delivery.EvidenceLevel; import dev.caskeleton.application.notification.platform.api.delivery.RecipientDeliveryState; import dev.caskeleton.application.notification.platform.api.delivery.SubmissionOutcome; +import dev.caskeleton.application.notification.platform.api.error.FailureCategory; import dev.caskeleton.application.notification.platform.api.routing.Channel; import dev.caskeleton.application.notification.platform.callback.DeliveryAttemptSnapshot; import dev.caskeleton.application.notification.platform.dispatch.AttemptSnapshots; @@ -37,12 +38,17 @@ import java.time.Clock; import java.time.Instant; import java.time.ZoneOffset; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiFunction; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * The four operator-plane use cases, each its own entrypoint with its own permission (round9 review @@ -347,6 +353,215 @@ class NotificationAdminUseCasesTest { .containsExactly(1, 1, List.of(true)); } + /** + * The actor holds every operator authority but the one the use case exercises, and is global, so + * the tenant checks pass and the use case's own {@code require} is the only thing that refuses. + */ + @ParameterizedTest(name = "{0}") + @MethodSource("operatorUseCases") + void eachOperatorUseCaseRefusesAnActorMissingItsOwnAuthority(OperatorCall call) { + // given + Fixture fixture = new Fixture(); + AttemptSnapshots.store( + fixture.requests, + fixture.attempts, + attemptOf(new TenantId("tenant-a")), + RecipientDeliveryState.FAILED); + AdminActor everyOtherAuthority = + new AdminActor( + "operator-1", EnumSet.complementOf(EnumSet.of(call.authority())), Optional.empty()); + + // when + Throwable failure = catchThrowable(() -> call.invoke(fixture, everyOtherAuthority)); + + // then + assertThat(failure) + .as("refused with AdminAccessDeniedException(%s)", call.authority()) + .isInstanceOfSatisfying( + AdminAccessDeniedException.class, + denied -> + assertThat(List.of(denied.required(), fixture.operations.claims)) + .containsExactly(call.authority(), 0)); + } + + @Test + void aTenantScopedOperatorCannotSuppressAnotherTenantsContactPoint() { + // given + Fixture fixture = new Fixture(); + TenantId tenantA = new TenantId("tenant-a"); + AdminActor tenantB = + new AdminActor( + "operator-b", + Set.of(NotificationAdminAuthority.SUPPRESS), + Optional.of(new TenantId("tenant-b"))); + + // when + Throwable failure = + catchThrowable( + () -> + fixture.suppression.handle( + new ChangeSuppressionCommand(suppressionOf(tenantA), tenantB))); + + // then + assertThat(failure) + .as("refused with AdminAccessDeniedException(SUPPRESS)") + .isInstanceOfSatisfying( + AdminAccessDeniedException.class, + denied -> + assertThat( + List.of( + denied.required(), + fixture + .suppressions + .activeFor(tenantA, "c".repeat(64), CLOCK.instant()) + .size(), + fixture.operations.claims)) + .containsExactly(NotificationAdminAuthority.SUPPRESS, 0, 0)); + } + + @Test + void aTenantScopedOperatorCannotRedriveAnotherTenantsAttempt() { + // given + Fixture fixture = new Fixture(); + DeliveryAttemptSnapshot foreign = attemptOf(new TenantId("tenant-a")); + AttemptSnapshots.store( + fixture.requests, fixture.attempts, foreign, RecipientDeliveryState.FAILED); + AdminActor tenantB = + new AdminActor( + "operator-b", + Set.of(NotificationAdminAuthority.REDRIVE), + Optional.of(new TenantId("tenant-b"))); + RedriveRequest approved = + new RedriveRequest("op-rd-b", foreign.attemptId(), "provider outage", true, false); + + // when + Throwable failure = + catchThrowable(() -> fixture.redrive.handle(new RedriveDeliveryCommand(approved, tenantB))); + + // then + assertThat(failure) + .as("refused with AdminAccessDeniedException(REDRIVE)") + .isInstanceOfSatisfying( + AdminAccessDeniedException.class, + denied -> + assertThat( + List.of( + denied.required(), + fixture + .recipients + .find(foreign.recipientDeliveryId()) + .orElseThrow() + .state(), + fixture.operations.claims)) + .containsExactly( + NotificationAdminAuthority.REDRIVE, RecipientDeliveryState.FAILED, 0)); + } + + @Test + void anAmbiguousAttemptIsNotRedrivenWithoutTheDuplicateRiskApproval() { + // given + Fixture fixture = new Fixture(); + DeliveryAttemptSnapshot ambiguous = attemptOf(new TenantId("tenant-a")); + AttemptSnapshots.store( + fixture.requests, fixture.attempts, ambiguous, RecipientDeliveryState.FAILED); + AdminActor operator = + new AdminActor("operator-1", Set.of(NotificationAdminAuthority.REDRIVE), Optional.empty()); + RedriveRequest unapproved = + new RedriveRequest("op-rd-risk", ambiguous.attemptId(), "provider outage", false, false); + + // when + Throwable failure = + catchThrowable( + () -> fixture.redrive.handle(new RedriveDeliveryCommand(unapproved, operator))); + + // then + assertThat(failure) + .as("refused with DuplicateRiskApprovalRequiredException(AMBIGUOUS_SUBMISSION)") + .isInstanceOfSatisfying( + DuplicateRiskApprovalRequiredException.class, + refused -> + assertThat( + List.of( + refused.descriptor().category(), + fixture + .recipients + .find(ambiguous.recipientDeliveryId()) + .orElseThrow() + .state(), + fixture.operations.claims)) + .containsExactly( + FailureCategory.AMBIGUOUS_SUBMISSION, RecipientDeliveryState.FAILED, 0)); + } + + private static Stream operatorUseCases() { + DeliveryAttemptId attempt = attemptOf(new TenantId("tenant-a")).attemptId(); + return Stream.of( + new OperatorCall( + "ChangeSuppressionUseCase", + NotificationAdminAuthority.SUPPRESS, + (fixture, actor) -> + fixture.suppression.handle( + new ChangeSuppressionCommand(suppressionOf(new TenantId("tenant-a")), actor))), + new OperatorCall( + "RedriveDeliveryUseCase", + NotificationAdminAuthority.REDRIVE, + (fixture, actor) -> + fixture.redrive.handle( + new RedriveDeliveryCommand( + new RedriveRequest("op-rd", attempt, "provider outage", true, false), + actor))), + new OperatorCall( + "ReconcileDeliveriesUseCase", + NotificationAdminAuthority.RECONCILE, + (fixture, actor) -> + fixture.reconcile.handle( + new ReconcileDeliveriesCommand( + new ReconcileRequest("op-r", List.of(attempt), "stuck attempt", false), + actor))), + new OperatorCall( + "ChangeProviderStateUseCase", + NotificationAdminAuthority.PROVIDER_CONTROL, + (fixture, actor) -> + fixture.providerState.handle( + new ChangeProviderStateCommand( + new ProviderStateRequest( + "op-p", + new ProviderProfileId("ses-primary"), + ProviderRuntimeState.DISABLED, + "provider maintenance", + false), + actor)))); + } + + private static SuppressionRequest suppressionOf(TenantId tenantId) { + return new SuppressionRequest( + "op-s", + tenantId, + SuppressionScope.CONTACT_POINT, + SuppressionReason.ADMIN_BLOCK, + "c".repeat(64), + Optional.empty(), + false, + "reported abuse", + false); + } + + /** One operator use case, the authority it exercises, and how to call it as an actor. */ + private record OperatorCall( + String useCase, + NotificationAdminAuthority authority, + BiFunction call) { + + AdminOperationResult invoke(Fixture fixture, AdminActor actor) { + return call.apply(fixture, actor); + } + + @Override + public String toString() { + return useCase + " requires " + authority; + } + } + private static DeliveryAttemptSnapshot attemptOf(TenantId tenantId) { return new DeliveryAttemptSnapshot( new DeliveryAttemptId(UUID.fromString("00000000-0000-7000-8000-000000000011")), -- 2.54.0 From 83caba40a43f263242884497126f8c2036612735 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sat, 21 Nov 2026 14:52:35 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test(notification):=20=EC=B7=A8=EC=86=8C?= =?UTF-8?q?=EC=9D=98=20CONFIRMED=5FACCEPTED=C2=B7=ED=9B=84=EC=86=8D=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=20=EB=B6=84=EA=B8=B0=EB=A5=BC=20=ED=91=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=8B=9C=ED=97=98=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 알림 취소는 provider가 이미 받았거나(CONFIRMED_ACCEPTED) 결과가 불명확한(ambiguous) 시도가 있는 job을 멈췄다고 세지 않고 EXTERNAL_SIDE_EFFECT_UNCERTAIN으로 보고한다. 시험은 ambiguous job에 cancelAmbiguousFollowUps=false 한 경우뿐이라, CONFIRMED_ACCEPTED 조건을 지우거나 후속 취소 분기를 if (true)로 바꿔도 통과한다(허브 변이 확인). cancellationReportsExternalUncertaintyRatherThanClaimingTheMessageWasStopped를 2x2 표(@ParameterizedTest, @CsvSource)로 바꾼다. 행은 근거(ambiguous 시도 + AMBIGUOUS / 비terminal + CONFIRMED_ACCEPTED)와 cancelAmbiguousFollowUps (false/true)다. 행마다 uncertain=true, canceled 수(0 또는 1), reason code 목록, 취소 뒤 recipient 상태(그대로 또는 CANCELED)를 한 번에 단언한다. 원래 행(ambiguous + false)도 표의 첫 행으로 남는다. job 상태는 실제로 그 근거가 붙는 비terminal 상태(RECONCILIATION_REQUIRED· DISPATCHING)로 둔다. 위험·한계: main 코드는 바꾸지 않았다. 후속 취소를 하지 않은 job이 alreadyTerminalRecipients로 세어지는 지금 동작은 항목 밖이라 단언하지 않았다. 검증: desktop RED·GREEN은 PR 본문에 둔다. Refs: REV-BE-0037 --- .../NotificationSubmissionServiceTest.java | 62 +++++++++++++++---- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/src/application/notification/src/test/java/dev/caskeleton/application/notification/platform/dispatch/NotificationSubmissionServiceTest.java b/src/application/notification/src/test/java/dev/caskeleton/application/notification/platform/dispatch/NotificationSubmissionServiceTest.java index 25040bf2..86b58924 100644 --- a/src/application/notification/src/test/java/dev/caskeleton/application/notification/platform/dispatch/NotificationSubmissionServiceTest.java +++ b/src/application/notification/src/test/java/dev/caskeleton/application/notification/platform/dispatch/NotificationSubmissionServiceTest.java @@ -11,6 +11,7 @@ import dev.caskeleton.application.notification.platform.api.NotificationReceipt; import dev.caskeleton.application.notification.platform.api.RequestStatus; import dev.caskeleton.application.notification.platform.api.TenantId; import dev.caskeleton.application.notification.platform.api.delivery.RecipientDeliveryState; +import dev.caskeleton.application.notification.platform.api.delivery.SubmissionOutcome; import dev.caskeleton.application.notification.platform.api.error.IdempotencyConflictException; import dev.caskeleton.application.notification.platform.api.error.NotificationValidationException; import dev.caskeleton.application.notification.platform.api.routing.Channel; @@ -29,6 +30,7 @@ import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; /** @@ -242,19 +244,49 @@ class NotificationSubmissionServiceTest { assertThat(transactions.committed()).isEmpty(); } - @Test - void cancellationReportsExternalUncertaintyRatherThanClaimingTheMessageWasStopped() { + /** + * A job whose provider may already hold the message — an ambiguous attempt, or a submission the + * provider confirmed while the job is still open — is never reported as stopped. Without the + * follow-up flag the job is left as it is; with it the follow-up is canceled, and the result + * still says the external side effect is uncertain. + */ + @ParameterizedTest(name = "[{index}] ambiguousAttempt={0}, submission={1}, cancelFollowUps={3}") + @CsvSource( + textBlock = + """ + # ambiguousAttempt, submission, state before, cancelFollowUps, canceled, state after + true, AMBIGUOUS, RECONCILIATION_REQUIRED, false, 0, RECONCILIATION_REQUIRED + false, CONFIRMED_ACCEPTED, DISPATCHING, false, 0, DISPATCHING + true, AMBIGUOUS, RECONCILIATION_REQUIRED, true, 1, CANCELED + false, CONFIRMED_ACCEPTED, DISPATCHING, true, 1, CANCELED + """) + void cancellationReportsExternalUncertaintyRatherThanClaimingTheMessageWasStopped( + boolean ambiguousAttempt, + SubmissionOutcome submission, + RecipientDeliveryState before, + boolean cancelFollowUps, + int canceled, + RecipientDeliveryState after) { + // given + TenantId tenant = new TenantId("tenant-a"); var receipt = submit(PlatformFakes.plan("idem-6", Map.of())); - var job = requests.recipientsOf(new TenantId("tenant-a"), receipt.notificationId()).get(0); - requests.replace(withAmbiguousAttempt(job)); + var job = requests.recipientsOf(tenant, receipt.notificationId()).get(0); + requests.replace(withEvidence(job, before, submission, ambiguousAttempt)); + // when var result = - service.cancel(receipt.notificationId(), new CancelCommand("OPERATOR_REQUEST", false)); + service.cancel( + receipt.notificationId(), new CancelCommand("OPERATOR_REQUEST", cancelFollowUps)); - assertThat(result.externalSideEffectUncertain()).isTrue(); - assertThat(result.reasonCodes()).contains("EXTERNAL_SIDE_EFFECT_UNCERTAIN"); - // The provider will not un-send what it already accepted, and the result says so. - assertThat(result.canceledRecipients()).isZero(); + // then + assertThat( + List.of( + result.externalSideEffectUncertain(), + result.canceledRecipients(), + result.reasonCodes(), + requests.recipientsOf(tenant, receipt.notificationId()).get(0).state())) + .containsExactly( + true, canceled, List.of("EXTERNAL_SIDE_EFFECT_UNCERTAIN", "OPERATOR_REQUEST"), after); } @Test @@ -294,7 +326,11 @@ class NotificationSubmissionServiceTest { assertThat(NotificationRequestStatusPolicy.rollUp(List.of())).isEqualTo(RequestStatus.CREATED); } - private static RecipientDeliveryRecord withAmbiguousAttempt(RecipientDeliveryRecord job) { + private static RecipientDeliveryRecord withEvidence( + RecipientDeliveryRecord job, + RecipientDeliveryState state, + SubmissionOutcome submission, + boolean ambiguousAttempt) { return new RecipientDeliveryRecord( job.id(), job.notificationId(), @@ -304,11 +340,11 @@ class NotificationSubmissionServiceTest { job.timeZone(), job.routingPlan(), job.routeCursor(), - job.state(), - job.submissionOutcome(), + state, + submission, job.deliveryOutcome(), job.evidenceLevel(), - true, + ambiguousAttempt, job.duplicateRisk(), job.nextDispatchAt(), job.expiresAt(), -- 2.54.0