mirror of
https://github.com/shlinkio/shlink.git
synced 2026-08-11 05:24:46 -05:00
Ensured default domain redirects cannot be edited through regular approach
This commit is contained in:
@@ -15,6 +15,7 @@ use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
|
||||
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\Entity\Domain;
|
||||
use Shlinkio\Shlink\Core\Exception\DomainNotFoundException;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidDomainException;
|
||||
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition;
|
||||
@@ -213,4 +214,15 @@ class DomainServiceTest extends TestCase
|
||||
yield 'domain not found and author API key' => [null, $authorApiKey];
|
||||
yield 'domain found and author API key' => [$domain, $authorApiKey];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function anExceptionIsThrowsWhenTryingToEditRedirectsForDefaultDomain(): void
|
||||
{
|
||||
$this->expectException(InvalidDomainException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'You cannot configure default domain\'s redirects this way. Use the configuration or env vars.',
|
||||
);
|
||||
|
||||
$this->domainService->configureNotFoundRedirects('default.com', NotFoundRedirects::withoutRedirects());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Exception;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidDomainException;
|
||||
|
||||
class InvalidDomainExceptionTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function configuresTheExceptionAsExpected(): void
|
||||
{
|
||||
$e = InvalidDomainException::forDefaultDomainRedirects();
|
||||
$expected = 'You cannot configure default domain\'s redirects this way. Use the configuration or env vars.';
|
||||
|
||||
self::assertEquals($expected, $e->getMessage());
|
||||
self::assertEquals($expected, $e->getDetail());
|
||||
self::assertEquals('Invalid domain', $e->getTitle());
|
||||
self::assertEquals('INVALID_DOMAIN', $e->getType());
|
||||
self::assertEquals(400, $e->getStatus());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user