mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
test: add test for NameCom provider
This commit is contained in:
@@ -12,3 +12,6 @@ LIMIT_MAX_WATCHLIST_WEBHOOKS=10
|
|||||||
|
|
||||||
# TEST
|
# TEST
|
||||||
GANDI_PAT_TOKEN=
|
GANDI_PAT_TOKEN=
|
||||||
|
|
||||||
|
NAMECOM_USERNAME=
|
||||||
|
NAMECOM_PASSWORD=
|
||||||
|
|||||||
2
.github/workflows/lint-and-tests.yml
vendored
2
.github/workflows/lint-and-tests.yml
vendored
@@ -106,6 +106,8 @@ jobs:
|
|||||||
needs: [ php-setup, cs-fixer, phpstan ]
|
needs: [ php-setup, cs-fixer, phpstan ]
|
||||||
env:
|
env:
|
||||||
GANDI_PAT_TOKEN: ${{ secrets.GANDI_PAT_TOKEN }}
|
GANDI_PAT_TOKEN: ${{ secrets.GANDI_PAT_TOKEN }}
|
||||||
|
NAMECOM_USERNAME: ${{ secrets.NAMECOM_USERNAME }}
|
||||||
|
NAMECOM_PASSWORD: ${{ secrets.NAMECOM_PASSWORD }}
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres
|
image: postgres
|
||||||
|
|||||||
@@ -50,3 +50,5 @@ services:
|
|||||||
when@test:
|
when@test:
|
||||||
parameters:
|
parameters:
|
||||||
gandi_pat_token: '%env(string:GANDI_PAT_TOKEN)%'
|
gandi_pat_token: '%env(string:GANDI_PAT_TOKEN)%'
|
||||||
|
namecom_username: '%env(string:NAMECOM_USERNAME)%'
|
||||||
|
namecom_password: '%env(string:NAMECOM_PASSWORD)%'
|
||||||
|
|||||||
@@ -57,20 +57,17 @@ class NameComProvider extends AbstractProvider
|
|||||||
|
|
||||||
$this->client->request(
|
$this->client->request(
|
||||||
'POST',
|
'POST',
|
||||||
'/v4/domains',
|
'/core/v1/domains',
|
||||||
(new HttpOptions())
|
(new HttpOptions())
|
||||||
->setHeader('Accept', 'application/json')
|
->setHeader('Accept', 'application/json')
|
||||||
->setAuthBasic($this->authData->username, $this->authData->token)
|
->setAuthBasic($this->authData->username, $this->authData->token)
|
||||||
->setBaseUri($dryRun ? self::DEV_BASE_URL : self::BASE_URL)
|
->setBaseUri($dryRun ? self::DEV_BASE_URL : self::BASE_URL)
|
||||||
->setJson([
|
->setJson([
|
||||||
'domain' => [
|
'domain' => [
|
||||||
[
|
'domainName' => $domain->getLdhName(),
|
||||||
'domainName' => $domain->getLdhName(),
|
'locked' => false,
|
||||||
'locked' => false,
|
'autorenewEnabled' => false,
|
||||||
'autorenewEnabled' => false,
|
|
||||||
],
|
|
||||||
'purchaseType' => 'registration',
|
'purchaseType' => 'registration',
|
||||||
'years' => 1,
|
|
||||||
// 'tldRequirements' => []
|
// 'tldRequirements' => []
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
@@ -104,7 +101,7 @@ class NameComProvider extends AbstractProvider
|
|||||||
{
|
{
|
||||||
$response = $this->client->request(
|
$response = $this->client->request(
|
||||||
'GET',
|
'GET',
|
||||||
'/v4/hello',
|
'/core/v1/hello',
|
||||||
(new HttpOptions())
|
(new HttpOptions())
|
||||||
->setHeader('Accept', 'application/json')
|
->setHeader('Accept', 'application/json')
|
||||||
->setAuthBasic($this->authData->username, $this->authData->token)
|
->setAuthBasic($this->authData->username, $this->authData->token)
|
||||||
|
|||||||
96
tests/Service/Provider/AbstractProviderTest.php
Normal file
96
tests/Service/Provider/AbstractProviderTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user