mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 09:45:29 +00:00
test: add gandi provider test
This commit is contained in:
parent
64fe0c895b
commit
a7d07be1be
@ -9,3 +9,6 @@ LIMITED_FEATURES=true
|
||||
LIMIT_MAX_WATCHLIST=10
|
||||
LIMIT_MAX_WATCHLIST_DOMAINS=10
|
||||
LIMIT_MAX_WATCHLIST_WEBHOOKS=10
|
||||
|
||||
# TEST
|
||||
GANDI_PAT_TOKEN=
|
||||
|
||||
2
.github/workflows/lint-and-tests.yml
vendored
2
.github/workflows/lint-and-tests.yml
vendored
@ -102,6 +102,8 @@ jobs:
|
||||
name: Tests
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ php-setup, cs-fixer, phpstan ]
|
||||
env:
|
||||
GANDI_PAT_TOKEN: ${{ secrets.GANDI_PAT_TOKEN }}
|
||||
services:
|
||||
postgres:
|
||||
image: postgres
|
||||
|
||||
@ -46,3 +46,7 @@ services:
|
||||
|
||||
# add more service definitions when explicit configuration is needed
|
||||
# please note that last definitions always *replace* previous ones
|
||||
|
||||
when@test:
|
||||
parameters:
|
||||
gandi_pat_token: '%env(string:GANDI_PAT_TOKEN)%'
|
||||
|
||||
@ -93,6 +93,7 @@ final readonly class OrderDomainHandler
|
||||
* The user is authenticated to ensure that the credentials are still valid.
|
||||
* If no errors occur, the purchase is attempted.
|
||||
*/
|
||||
$connectorProvider->authenticate($connector->getAuthData());
|
||||
|
||||
$connectorProvider->orderDomain($domain, $this->kernel->isDebug());
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
|
||||
use Symfony\Component\HttpClient\HttpOptions;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
@ -31,12 +32,14 @@ class GandiProvider extends AbstractProvider
|
||||
protected DefaultProviderDto $authData;
|
||||
|
||||
private const BASE_URL = 'https://api.gandi.net';
|
||||
private const SANDBOX_BASE_URL = 'https://api.sandbox.gandi.net';
|
||||
|
||||
public function __construct(
|
||||
CacheItemPoolInterface $cacheItemPool,
|
||||
private readonly HttpClientInterface $client,
|
||||
DenormalizerInterface&NormalizerInterface $serializer,
|
||||
ValidatorInterface $validator,
|
||||
private readonly KernelInterface $kernel,
|
||||
) {
|
||||
parent::__construct($cacheItemPool, $serializer, $validator);
|
||||
}
|
||||
@ -58,14 +61,14 @@ class GandiProvider extends AbstractProvider
|
||||
$user = $this->client->request('GET', '/v5/organization/user-info', (new HttpOptions())
|
||||
->setAuthBearer($this->authData->token)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->setBaseUri($this->kernel->isDebug() ? self::SANDBOX_BASE_URL : self::BASE_URL)
|
||||
->toArray()
|
||||
)->toArray();
|
||||
|
||||
$httpOptions = (new HttpOptions())
|
||||
->setAuthBearer($this->authData->token)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->setBaseUri($this->kernel->isDebug() ? self::SANDBOX_BASE_URL : self::BASE_URL)
|
||||
->setHeader('Dry-Run', $dryRun ? '1' : '0')
|
||||
->setJson([
|
||||
'fqdn' => $ldhName,
|
||||
@ -90,7 +93,7 @@ class GandiProvider extends AbstractProvider
|
||||
]);
|
||||
}
|
||||
|
||||
$res = $this->client->request('POST', '/domain/domains', $httpOptions->toArray());
|
||||
$res = $this->client->request('POST', '/v5/domain/domains', $httpOptions->toArray());
|
||||
|
||||
if ((!$dryRun && Response::HTTP_ACCEPTED !== $res->getStatusCode())
|
||||
|| ($dryRun && Response::HTTP_OK !== $res->getStatusCode())) {
|
||||
@ -107,7 +110,7 @@ class GandiProvider extends AbstractProvider
|
||||
$response = $this->client->request('GET', '/v5/organization/user-info', (new HttpOptions())
|
||||
->setAuthBearer($this->authData->token)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->setBaseUri($this->kernel->isDebug() ? self::SANDBOX_BASE_URL : self::BASE_URL)
|
||||
->toArray()
|
||||
);
|
||||
|
||||
@ -128,7 +131,7 @@ class GandiProvider extends AbstractProvider
|
||||
$response = $this->client->request('GET', '/v5/domain/tlds', (new HttpOptions())
|
||||
->setAuthBearer($this->authData->token)
|
||||
->setHeader('Accept', 'application/json')
|
||||
->setBaseUri(self::BASE_URL)
|
||||
->setBaseUri($this->kernel->isDebug() ? self::SANDBOX_BASE_URL : self::BASE_URL)
|
||||
->toArray())->toArray();
|
||||
|
||||
return array_map(fn ($tld) => $tld['name'], $response);
|
||||
|
||||
@ -28,8 +28,8 @@ class NamecheapProvider extends AbstractProvider
|
||||
/** @var NamecheapProviderDto */
|
||||
protected DefaultProviderDto $authData;
|
||||
|
||||
public const BASE_URL = 'https://api.namecheap.com/xml.response';
|
||||
public const SANDBOX_BASE_URL = 'https://api.sandbox.namecheap.com/xml.response';
|
||||
private const BASE_URL = 'https://api.namecheap.com/xml.response';
|
||||
private const SANDBOX_BASE_URL = 'https://api.sandbox.namecheap.com/xml.response';
|
||||
|
||||
public function __construct(
|
||||
CacheItemPoolInterface $cacheItemPool,
|
||||
|
||||
@ -32,7 +32,7 @@ final class ConnectorControllerTest extends ApiTestCase
|
||||
'waiveRetractationPeriod' => true,
|
||||
'acceptConditions' => true,
|
||||
'ownerLegalAge' => true,
|
||||
'token' => '',
|
||||
'token' => 'test',
|
||||
],
|
||||
'provider' => 'gandi',
|
||||
]]);
|
||||
@ -69,4 +69,23 @@ final class ConnectorControllerTest extends ApiTestCase
|
||||
]]);
|
||||
$this->assertResponseStatusCodeSame(400);
|
||||
}
|
||||
|
||||
public function testCreateConnectorValidAuthData(): void
|
||||
{
|
||||
$gandiToken = static::getContainer()->getParameter('gandi_pat_token');
|
||||
if (!$gandiToken) {
|
||||
$this->markTestSkipped('Missing Gandi PAT token');
|
||||
}
|
||||
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
|
||||
$client->request('POST', '/api/connectors', ['json' => [
|
||||
'authData' => [
|
||||
'waiveRetractationPeriod' => true,
|
||||
'acceptConditions' => true,
|
||||
'ownerLegalAge' => true,
|
||||
'token' => $gandiToken,
|
||||
],
|
||||
'provider' => 'gandi',
|
||||
]]);
|
||||
$this->assertResponseStatusCodeSame(201);
|
||||
}
|
||||
}
|
||||
|
||||
55
tests/Service/Provider/GandiProviderTest.php
Normal file
55
tests/Service/Provider/GandiProviderTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Service\Provider;
|
||||
|
||||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
||||
use App\Factory\UserFactory;
|
||||
use App\Message\OrderDomain;
|
||||
use App\MessageHandler\OrderDomainHandler;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Tests\Controller\ConnectorControllerTest;
|
||||
use App\Tests\Service\RDAPServiceTest;
|
||||
use App\Tests\State\WatchListUpdateProcessorTest;
|
||||
use PHPUnit\Framework\Attributes\DependsExternal;
|
||||
|
||||
class GandiProviderTest extends ApiTestCase
|
||||
{
|
||||
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
||||
public function testOrderDomain()
|
||||
{
|
||||
$gandiToken = static::getContainer()->getParameter('gandi_pat_token');
|
||||
if (!$gandiToken) {
|
||||
$this->markTestSkipped('Missing Gandi PAT token');
|
||||
}
|
||||
|
||||
// Create a GANDI Connector
|
||||
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
|
||||
$response = $client->request('POST', '/api/connectors', ['json' => [
|
||||
'authData' => [
|
||||
'waiveRetractationPeriod' => true,
|
||||
'acceptConditions' => true,
|
||||
'ownerLegalAge' => true,
|
||||
'token' => $gandiToken,
|
||||
],
|
||||
'provider' => 'gandi',
|
||||
]]);
|
||||
$this->assertResponseStatusCodeSame(201);
|
||||
|
||||
// Create a Watchlist with a single domain name
|
||||
WatchListUpdateProcessorTest::createUserAndWatchlist($client, ['/api/domains/example.com'], '/api/connectors/'.$response->toArray()['id']);
|
||||
|
||||
$response = $client->request('GET', '/api/watchlists');
|
||||
$watchlistId = $response->toArray()['hydra:member'][0]['token'];
|
||||
|
||||
// Set the domain as deleted
|
||||
$domain = self::getContainer()->get(DomainRepository::class)->findOneBy(['ldhName' => 'example.com']);
|
||||
$domain->setDeleted(true);
|
||||
|
||||
// Trigger the Order Domain message
|
||||
$orderDomainHandler = self::getContainer()->get(OrderDomainHandler::class);
|
||||
$message = new OrderDomain($watchlistId, 'example.com');
|
||||
$orderDomainHandler($message);
|
||||
|
||||
$this->assertResponseStatusCodeSame(200);
|
||||
}
|
||||
}
|
||||
@ -53,13 +53,15 @@ final class WatchListUpdateProcessorTest extends ApiTestCase
|
||||
$this->assertCount(1, $data['trackedEvents']);
|
||||
}
|
||||
|
||||
public static function createUserAndWatchlist(?Client $client = null, array $domains = ['/api/domains/example.com']): Client
|
||||
public static function createUserAndWatchlist(?Client $client = null, array $domains = ['/api/domains/example.com'], ?string $connectorId = null): Client
|
||||
{
|
||||
$client = $client ?? self::createClientWithCredentials(self::getToken(UserFactory::createOne()));
|
||||
|
||||
$client->request('POST', '/api/watchlists', ['json' => [
|
||||
'domains' => $domains,
|
||||
'name' => 'My Watchlist',
|
||||
'trackedEvents' => ['last changed', 'transfer', 'expiration', 'deletion'],
|
||||
'connector' => $connectorId,
|
||||
]]);
|
||||
|
||||
return $client;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user