mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-11-25 21:24:22 +00:00
Add WebAppDataValidator for mini app init data
Checks window.WebApp.initData by the bot token as dev.max.ru/docs/webapps/validation describes, then its age, and returns the data parsed. A repeated field is refused. Bound in the Laravel service provider with the configured token.
This commit is contained in:
@@ -16,6 +16,7 @@ use BushlanovDev\MaxMessengerBot\Laravel\MaxBotServiceProvider;
|
||||
use BushlanovDev\MaxMessengerBot\LongPollingHandler;
|
||||
use BushlanovDev\MaxMessengerBot\ModelFactory;
|
||||
use BushlanovDev\MaxMessengerBot\UpdateDispatcher;
|
||||
use BushlanovDev\MaxMessengerBot\WebAppDataValidator;
|
||||
use BushlanovDev\MaxMessengerBot\WebhookHandler;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use InvalidArgumentException;
|
||||
@@ -40,6 +41,7 @@ use ReflectionClass;
|
||||
#[UsesClass(UpdateDispatcher::class)]
|
||||
#[UsesClass(MaxBotManager::class)]
|
||||
#[UsesClass(WebhookHandler::class)]
|
||||
#[UsesClass(WebAppDataValidator::class)]
|
||||
#[UsesClass(ModelFactory::class)]
|
||||
final class MaxBotServiceProviderTest extends TestCase
|
||||
{
|
||||
@@ -90,6 +92,19 @@ final class MaxBotServiceProviderTest extends TestCase
|
||||
$this->app->make(Api::class);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itThrowsExceptionWhenAccessTokenIsMissingForWebAppDataValidator(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'Max Bot access token is not configured. Please set MAXBOT_ACCESS_TOKEN in your .env file.'
|
||||
);
|
||||
|
||||
$this->app['config']->set('maxbot.access_token', null);
|
||||
|
||||
$this->app->make(WebAppDataValidator::class);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[RunInSeparateProcess]
|
||||
#[PreserveGlobalState(false)]
|
||||
@@ -128,6 +143,8 @@ final class MaxBotServiceProviderTest extends TestCase
|
||||
'maxbot.webhook alias' => ['maxbot.webhook', WebhookHandler::class],
|
||||
'LongPollingHandler::class' => [LongPollingHandler::class, LongPollingHandler::class],
|
||||
'maxbot.polling alias' => ['maxbot.polling', LongPollingHandler::class],
|
||||
'WebAppDataValidator::class' => [WebAppDataValidator::class, WebAppDataValidator::class],
|
||||
'maxbot.webapp alias' => ['maxbot.webapp', WebAppDataValidator::class],
|
||||
'MaxBotManager::class' => [MaxBotManager::class, MaxBotManager::class],
|
||||
'maxbot.manager alias' => ['maxbot.manager', MaxBotManager::class],
|
||||
];
|
||||
@@ -420,6 +437,7 @@ final class MaxBotServiceProviderTest extends TestCase
|
||||
UpdateDispatcher::class,
|
||||
WebhookHandler::class,
|
||||
LongPollingHandler::class,
|
||||
WebAppDataValidator::class,
|
||||
MaxBotManager::class,
|
||||
'maxbot',
|
||||
'maxbot.api',
|
||||
@@ -427,6 +445,7 @@ final class MaxBotServiceProviderTest extends TestCase
|
||||
'maxbot.dispatcher',
|
||||
'maxbot.webhook',
|
||||
'maxbot.polling',
|
||||
'maxbot.webapp',
|
||||
'maxbot.manager',
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user