You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.6 KiB
PHP
29 lines
1.6 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__) . '/app/Services/Config.php';
|
|
require dirname(__DIR__) . '/app/Services/TicketTelegramNotifier.php';
|
|
|
|
use App\Services\TicketTelegramNotifier as Notifications;
|
|
|
|
function check($value, string $label): void
|
|
{
|
|
if (!$value) {
|
|
throw new RuntimeException($label);
|
|
}
|
|
}
|
|
|
|
$System_Config = ['enable_telegram' => 'true', 'telegram_token' => 'test-not-a-real-token', 'telegram_request_token' => ''];
|
|
check(!Notifications::authorizeWebhook(''), 'Empty webhook secret must fail closed');
|
|
$System_Config['telegram_request_token'] = str_repeat('a', 32);
|
|
check(!Notifications::authorizeWebhook(str_repeat('b', 32)), 'Wrong secret accepted');
|
|
check(Notifications::authorizeWebhook(str_repeat('a', 32)), 'Valid configured secret rejected');
|
|
$System_Config['enable_telegram'] = 'false';
|
|
check(!Notifications::authorizeWebhook(str_repeat('a', 32)), 'Disabled integration accepted');
|
|
|
|
$message = ['chat' => ['type' => 'private', 'id' => 123], 'from' => ['id' => 123], 'text' => '/start ' . str_repeat('a', 48)];
|
|
check(Notifications::bindingCommand(['message' => $message]) !== null, 'Private one-time code command rejected');
|
|
foreach ([['text' => '/reply 1 hello'], ['chat' => ['type' => 'group', 'id' => 123]], ['from' => ['id' => 124]], ['forward_origin' => ['type' => 'user']], ['from' => ['id' => 123, 'is_bot' => true]], ['text' => '/start bad']] as $change) {
|
|
check(Notifications::bindingCommand(['message' => array_replace($message, $change)]) === null, 'Unexpected bot capability accepted');
|
|
}
|
|
echo "Administrator-only Telegram boundaries passed.\n";
|