test: add test for NameCom provider

This commit is contained in:
Maël Gangloff
2025-10-17 23:08:28 +02:00
parent 28fdcd2575
commit 7d0642eb6a
6 changed files with 108 additions and 63 deletions

View File

@@ -12,3 +12,6 @@ LIMIT_MAX_WATCHLIST_WEBHOOKS=10
# TEST
GANDI_PAT_TOKEN=
NAMECOM_USERNAME=
NAMECOM_PASSWORD=

View File

@@ -106,6 +106,8 @@ jobs:
needs: [ php-setup, cs-fixer, phpstan ]
env:
GANDI_PAT_TOKEN: ${{ secrets.GANDI_PAT_TOKEN }}
NAMECOM_USERNAME: ${{ secrets.NAMECOM_USERNAME }}
NAMECOM_PASSWORD: ${{ secrets.NAMECOM_PASSWORD }}
services:
postgres:
image: postgres

View File

@@ -50,3 +50,5 @@ services:
when@test:
parameters:
gandi_pat_token: '%env(string:GANDI_PAT_TOKEN)%'
namecom_username: '%env(string:NAMECOM_USERNAME)%'
namecom_password: '%env(string:NAMECOM_PASSWORD)%'

View File

@@ -57,20 +57,17 @@ class NameComProvider extends AbstractProvider
$this->client->request(
'POST',
'/v4/domains',
'/core/v1/domains',
(new HttpOptions())
->setHeader('Accept', 'application/json')
->setAuthBasic($this->authData->username, $this->authData->token)
->setBaseUri($dryRun ? self::DEV_BASE_URL : self::BASE_URL)
->setJson([
'domain' => [
[
'domainName' => $domain->getLdhName(),
'locked' => false,
'autorenewEnabled' => false,
],
'domainName' => $domain->getLdhName(),
'locked' => false,
'autorenewEnabled' => false,
'purchaseType' => 'registration',
'years' => 1,
// 'tldRequirements' => []
],
])
@@ -104,7 +101,7 @@ class NameComProvider extends AbstractProvider
{
$response = $this->client->request(
'GET',
'/v4/hello',
'/core/v1/hello',
(new HttpOptions())
->setHeader('Accept', 'application/json')
->setAuthBasic($this->authData->username, $this->authData->token)

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Tests\Service\Provider;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use App\Config\ConnectorProvider;
use App\Entity\Domain;
use App\Entity\Tld;
use App\Entity\WatchList;
use App\Factory\UserFactory;
use App\Message\OrderDomain;
use App\MessageHandler\OrderDomainHandler;
use App\Tests\Controller\ConnectorControllerTest;
use App\Tests\Service\RDAPServiceTest;
use App\Tests\State\WatchListUpdateProcessorTest;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\DependsExternal;
use Symfony\Component\Uid\UuidV4;
class AbstractProviderTest extends ApiTestCase
{
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
public function testGandi()
{
$gandiToken = static::getContainer()->getParameter('gandi_pat_token');
if (!$gandiToken) {
$this->markTestSkipped('Missing Gandi PAT token');
}
$this->testGenericProvider(ConnectorProvider::GANDI, [
'waiveRetractationPeriod' => true,
'acceptConditions' => true,
'ownerLegalAge' => true,
'token' => $gandiToken,
]);
}
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
public function testNameCom()
{
$namecomUsername = static::getContainer()->getParameter('namecom_username');
$namecomPassword = static::getContainer()->getParameter('namecom_password');
if (!$namecomUsername || !$namecomPassword) {
$this->markTestSkipped('Missing Name.com username or password');
}
$this->testGenericProvider(ConnectorProvider::NAMECOM, [
'waiveRetractationPeriod' => true,
'acceptConditions' => true,
'ownerLegalAge' => true,
'username' => $namecomUsername,
'token' => $namecomPassword,
]);
}
private function testGenericProvider(ConnectorProvider $connectorProvider, array $authData): void
{
// Create a Connector
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
$response = $client->request('POST', '/api/connectors', ['json' => [
'authData' => $authData,
'provider' => $connectorProvider->value,
]]);
$this->assertResponseStatusCodeSame(201);
/** @var EntityManagerInterface $entityManager */
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
// Create a Watchlist with the domain name
WatchListUpdateProcessorTest::createUserAndWatchlist($client,
['/api/domains/example.com'],
'/api/connectors/'.$response->toArray()['id']);
$response = $client->request('GET', '/api/watchlists');
$watchlist = $entityManager->getRepository(WatchList::class)->findOneBy(['token' => $response->toArray()['hydra:member'][0]['token']]);
$domain = (new Domain())
->setLdhName((new UuidV4()).'.com')
->setDeleted(true)
->setTld($entityManager->getReference(Tld::class, 'fr'))
->setDelegationSigned(false);
$entityManager->persist($domain);
$watchlist->addDomain($domain);
$entityManager->flush();
// Trigger the Order Domain message
$orderDomainHandler = self::getContainer()->get(OrderDomainHandler::class);
$message = new OrderDomain($watchlist->getToken(), $domain->getLdhName());
$orderDomainHandler($message);
$this->assertResponseStatusCodeSame(200);
}
}

View File

@@ -1,55 +0,0 @@
<?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);
}
}