Skip to content

Commit 0533c0c

Browse files
committed
Checks for empty email before sending notification
1 parent 27e418b commit 0533c0c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Listeners/SendSecurityNotification.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public function handle(SecureFieldsUpdated $event): void
1515
{
1616
$notificationClass = config('security-notifications.notifications.secure_fields');
1717

18-
Notification::route('mail', $event->original_email)
19-
->notify(new $notificationClass($event->fields, $event->updated_at));
18+
if (! empty($event->original_email)) {
19+
Notification::route('mail', $event->original_email)
20+
->notify(new $notificationClass($event->fields, $event->updated_at));
21+
}
2022
}
2123
}

tests/Unit/Listeners/SendSecurityNotificationTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,21 @@
3030
&& Arr::has($notification->fields, 'username')
3131
&& Arr::has($notification->fields, 'password');
3232
});
33+
});
34+
35+
it('does not send the notification if the email is an empty string', function () {
36+
Notification::fake();
37+
38+
$user = User::factory()->create();
39+
40+
$event = (new SecureFieldsUpdated(
41+
model: $user,
42+
fields: [],
43+
original_email: '',
44+
updated_at: now(),
45+
));
46+
47+
(new SendSecurityNotification)->handle($event);
48+
49+
Notification::assertNothingSent();
3350
});

0 commit comments

Comments
 (0)