From 0c25bbfe350d49598b232e47ac5b734594ac611c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Thu, 3 Oct 2024 11:23:01 +0200 Subject: [PATCH] fix: update verifyAuthData in NamecheapProvider --- src/Service/Connector/NamecheapProvider.php | 25 +++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Service/Connector/NamecheapProvider.php b/src/Service/Connector/NamecheapProvider.php index e85fa44..17e9c74 100644 --- a/src/Service/Connector/NamecheapProvider.php +++ b/src/Service/Connector/NamecheapProvider.php @@ -3,11 +3,12 @@ namespace App\Service\Connector; use App\Entity\Domain; -use Exception; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\InvalidArgumentException; use Symfony\Component\DependencyInjection\Attribute\Autoconfigure; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; @@ -92,7 +93,7 @@ class NamecheapProvider extends AbstractProvider $data = new \SimpleXMLElement($response->getContent()); if ($data->Errors->Error) { - throw new \Exception($data->Errors->Error); // FIXME better exception type + throw new BadRequestHttpException($data->Errors->Error); } return $data->CommandResponse; @@ -100,11 +101,31 @@ class NamecheapProvider extends AbstractProvider public function verifyAuthData(array $authData): array { + $apiUser = $authData['ApiUser']; + $apiKey = $authData['ApiKey']; + + $acceptConditions = $authData['acceptConditions']; + $ownerLegalAge = $authData['ownerLegalAge']; + $waiveRetractationPeriod = $authData['waiveRetractationPeriod']; + + if (!is_string($apiUser) || empty($apiUser) + || !is_string($apiKey) || empty($apiKey) + ) { + throw new BadRequestHttpException('Bad authData schema'); + } + + if (true !== $acceptConditions + || true !== $ownerLegalAge + || true !== $waiveRetractationPeriod) { + throw new HttpException(451, 'The user has not given explicit consent'); + } + return [ 'ApiUser' => $authData['ApiUser'], 'ApiKey' => $authData['ApiKey'], 'acceptConditions' => $authData['acceptConditions'], 'ownerLegalAge' => $authData['ownerLegalAge'], + 'waiveRetractationPeriod' => $authData['waiveRetractationPeriod'], ]; }