Add proxy IP headers to Telegram notifications
All checks were successful
Tests / Laravel tests (pull_request) Successful in 12m3s

This commit is contained in:
2026-06-04 00:30:44 +02:00
parent 03b06632f9
commit da4bdc6bf4
6 changed files with 96 additions and 19 deletions

View File

@@ -18,13 +18,19 @@ test('telegram service sends a contact message notification', function () {
ip: '127.0.0.1',
userAgent: 'Pest Browser',
email: 'roberto@example.com',
phone: '+31612345678'
phone: '+31612345678',
ipHeaders: [
'CF-Connecting-IP' => '203.0.113.10',
'X-Forwarded-For' => '203.0.113.10, 198.51.100.20',
],
);
Http::assertSent(fn ($request) => $request->url() === 'https://api.telegram.org/bottelegram-token/sendMessage'
&& $request['chat_id'] === 'telegram-chat'
&& str_contains($request['text'], 'Nieuw contactbericht ontvangen')
&& str_contains($request['text'], 'roberto@example.com'));
&& str_contains($request['text'], 'roberto@example.com')
&& str_contains($request['text'], 'CF-Connecting-IP: 203.0.113.10')
&& str_contains($request['text'], 'X-Forwarded-For: 203.0.113.10, 198.51.100.20'));
});
test('telegram service sends a personalia click notification', function () {
@@ -39,10 +45,13 @@ test('telegram service sends a personalia click notification', function () {
'value' => 'roberto@example.com',
]);
app(TelegramNotificationService::class)->notifyPersonaliaClick($personalia, '127.0.0.1', 'Pest Browser');
app(TelegramNotificationService::class)->notifyPersonaliaClick($personalia, '127.0.0.1', 'Pest Browser', [
'CF-Connecting-IP' => '203.0.113.10',
]);
Http::assertSent(fn ($request) => str_contains($request['text'], 'Persoonlijke gegevens bekeken')
&& str_contains($request['text'], 'roberto@example.com'));
&& str_contains($request['text'], 'roberto@example.com')
&& str_contains($request['text'], 'CF-Connecting-IP: 203.0.113.10'));
});
test('telegram service sends a page visit notification', function () {
@@ -69,10 +78,15 @@ test('telegram service sends a page visit notification', function () {
'width' => 1440,
'height' => 900,
],
], '127.0.0.1', 'Pest Browser', 'nl-NL,nl;q=0.9');
], '127.0.0.1', 'Pest Browser', 'nl-NL,nl;q=0.9', [
'CF-Connecting-IP' => '203.0.113.10',
'X-Real-IP' => '198.51.100.30',
]);
Http::assertSent(fn ($request) => str_contains($request['text'], 'Pagina bezocht')
&& str_contains($request['text'], 'Visitor ID: visitor-123')
&& str_contains($request['text'], 'Scherm: 1920x1080')
&& str_contains($request['text'], 'Viewport: 1440x900'));
&& str_contains($request['text'], 'Viewport: 1440x900')
&& str_contains($request['text'], 'CF-Connecting-IP: 203.0.113.10')
&& str_contains($request['text'], 'X-Real-IP: 198.51.100.30'));
});