Harden notification release regressions

This commit is contained in:
Eric Peters
2026-04-24 18:44:25 +02:00
parent 4908064f6d
commit c052aeaa03
4 changed files with 286 additions and 20 deletions
@@ -287,6 +287,78 @@ class DeliverNotificationActionTest extends TestCase
$this->assertSame('Connection timed out while contacting the remote endpoint.', $deliveryLog->error_excerpt);
}
/**
* Ensure retryable delivery logs redact stored secret URLs from response excerpts.
*/
public function test_retryable_response_excerpts_redact_delivery_urls(): void
{
Http::preventStrayRequests();
$deliveryUrl = 'https://hooks.example.test/kanbangit/secret-token';
Http::fake([
$deliveryUrl => Http::response([
'message' => "Remote service could not deliver to {$deliveryUrl}.",
], 503),
]);
$notificationAction = NotificationAction::factory()->webhook()->create([
'delivery_url' => $deliveryUrl,
]);
$deliveryLog = $this->createPendingDeliveryLog($notificationAction);
$job = (new DeliverNotificationAction(
notificationActionId: $notificationAction->id,
payload: $this->payload(),
notificationDeliveryLogId: $deliveryLog->id,
))->withFakeQueueInteractions();
$job->handle();
$job->assertReleased($job->backoff()[0]);
$deliveryLog = $deliveryLog->fresh();
$this->assertSame(NotificationDeliveryStatus::Retryable, $deliveryLog->delivery_status);
$this->assertStringContainsString('[redacted]', (string) $deliveryLog->response_excerpt);
$this->assertStringNotContainsString($deliveryUrl, (string) $deliveryLog->response_excerpt);
}
/**
* Ensure connection failure logs redact stored secret URLs from error excerpts.
*/
public function test_connection_failure_excerpts_redact_delivery_urls(): void
{
Http::preventStrayRequests();
$deliveryUrl = 'https://hooks.example.test/kanbangit/secret-token';
Http::fake([
$deliveryUrl => Http::failedConnection(
"Connection timed out while contacting {$deliveryUrl}.",
),
]);
$notificationAction = NotificationAction::factory()->webhook()->create([
'delivery_url' => $deliveryUrl,
]);
$deliveryLog = $this->createPendingDeliveryLog($notificationAction);
$job = (new DeliverNotificationAction(
notificationActionId: $notificationAction->id,
payload: $this->payload(),
notificationDeliveryLogId: $deliveryLog->id,
))->withFakeQueueInteractions();
$job->handle();
$job->assertReleased($job->backoff()[0]);
$deliveryLog = $deliveryLog->fresh();
$this->assertSame(NotificationDeliveryStatus::Retryable, $deliveryLog->delivery_status);
$this->assertStringContainsString('[redacted]', (string) $deliveryLog->error_excerpt);
$this->assertStringNotContainsString($deliveryUrl, (string) $deliveryLog->error_excerpt);
}
/**
* Ensure Discord deliveries reject empty rendered messages before sending the request.
*/