feat: check malformed domain names

This commit is contained in:
Maël Gangloff
2025-10-16 14:16:58 +02:00
parent a20344816c
commit a143039925
8 changed files with 77 additions and 32 deletions

View File

@@ -7,6 +7,7 @@ namespace App\Tests\Entity;
use App\Entity\Domain;
use App\Entity\DomainEvent;
use App\Entity\DomainStatus;
use App\Exception\MalformedDomainException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
@@ -159,7 +160,7 @@ final class DomainTest extends TestCase
);
}
public function testSetLdhName(): void
public function testIdnDomainName(): void
{
/*
* @see https://en.wikipedia.org/wiki/IDN_Test_TLDs
@@ -180,6 +181,12 @@ final class DomainTest extends TestCase
);
}
public function testInvalidDomainName()
{
$this->expectException(MalformedDomainException::class);
(new Domain())->setLdhName('*');
}
public static function isToBeUpdatedProvider(): array
{
$now = new \DateTimeImmutable();

View File

@@ -5,6 +5,8 @@ namespace App\Tests\State;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use App\Entity\Domain;
use App\Factory\UserFactory;
use App\Repository\DomainRepository;
use App\Service\RDAPService;
use App\Tests\AuthenticatedUserTrait;
use App\Tests\Service\RDAPServiceTest;
use PHPUnit\Framework\Attributes\DependsExternal;
@@ -18,11 +20,31 @@ final class AutoRegisterDomainProviderTest extends ApiTestCase
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
public function testRegisterDomain(): void
{
$testUser = UserFactory::createOne();
$client = AutoRegisterDomainProviderTest::createClientWithCredentials(AutoRegisterDomainProviderTest::getToken($testUser));
$client = AutoRegisterDomainProviderTest::createClientWithCredentials(AutoRegisterDomainProviderTest::getToken(UserFactory::createOne()));
$client->request('GET', '/api/domains/example.com');
$this->assertResponseIsSuccessful();
$this->assertMatchesResourceItemJsonSchema(Domain::class);
}
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
public function testRegisterDomainAlreadyUpdated(): void
{
$client = AutoRegisterDomainProviderTest::createClientWithCredentials(AutoRegisterDomainProviderTest::getToken(UserFactory::createOne()));
$mockedDomain = $this->getMockBuilder(Domain::class)->getMock();
$mockedDomain->method('isToBeUpdated')->willReturn(false);
$mockedDomainRepository = $this->createMock(DomainRepository::class);
$mockedDomainRepository->method('findOneBy')->willReturn($mockedDomain);
$rdapServiceMocked = $this->createMock(RDAPService::class);
$rdapServiceMocked->expects(self::never())->method('registerDomain');
$container = static::getContainer();
$container->set(DomainRepository::class, $mockedDomainRepository);
$container->set(RDAPService::class, $rdapServiceMocked);
$client->request('GET', '/api/domains/example.com');
}
}