mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-20 19:25:40 +00:00
test: update test suite
This commit is contained in:
parent
cd454750cf
commit
afd736882e
@ -5,15 +5,19 @@ namespace App\Controller;
|
|||||||
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Component\Routing\RouterInterface;
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
|
|
||||||
class HomeController extends AbstractController
|
class HomeController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(private readonly RouterInterface $router)
|
public function __construct(
|
||||||
{
|
private readonly RouterInterface $router,
|
||||||
|
private readonly ParameterBagInterface $parameterBag,
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route(path: '/', name: 'index')]
|
#[Route(path: '/', name: 'index')]
|
||||||
@ -25,8 +29,11 @@ class HomeController extends AbstractController
|
|||||||
#[Route(path: '/login/oauth', name: 'oauth_connect')]
|
#[Route(path: '/login/oauth', name: 'oauth_connect')]
|
||||||
public function connectAction(ClientRegistry $clientRegistry): Response
|
public function connectAction(ClientRegistry $clientRegistry): Response
|
||||||
{
|
{
|
||||||
|
if ($this->parameterBag->get('oauth_enabled')) {
|
||||||
return $clientRegistry->getClient('oauth')->redirect([], []);
|
return $clientRegistry->getClient('oauth')->redirect([], []);
|
||||||
}
|
}
|
||||||
|
throw new NotFoundHttpException();
|
||||||
|
}
|
||||||
|
|
||||||
#[Route(path: '/logout', name: 'logout')]
|
#[Route(path: '/logout', name: 'logout')]
|
||||||
public function logout(Security $security): ?RedirectResponse
|
public function logout(Security $security): ?RedirectResponse
|
||||||
|
|||||||
@ -7,18 +7,15 @@ use App\Entity\Connector;
|
|||||||
use App\Factory\UserFactory;
|
use App\Factory\UserFactory;
|
||||||
use App\Tests\AuthenticatedUserTrait;
|
use App\Tests\AuthenticatedUserTrait;
|
||||||
use Zenstruck\Foundry\Test\Factories;
|
use Zenstruck\Foundry\Test\Factories;
|
||||||
use Zenstruck\Foundry\Test\ResetDatabase;
|
|
||||||
|
|
||||||
final class ConnectorControllerTest extends ApiTestCase
|
final class ConnectorControllerTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
use ResetDatabase;
|
|
||||||
use Factories;
|
use Factories;
|
||||||
use AuthenticatedUserTrait;
|
use AuthenticatedUserTrait;
|
||||||
|
|
||||||
public function testGetConnectorCollection(): void
|
public function testGetConnectorCollection(): void
|
||||||
{
|
{
|
||||||
$testUser = UserFactory::createOne();
|
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
|
||||||
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken($testUser));
|
|
||||||
|
|
||||||
$response = $client->request('GET', '/api/connectors');
|
$response = $client->request('GET', '/api/connectors');
|
||||||
|
|
||||||
@ -26,4 +23,50 @@ final class ConnectorControllerTest extends ApiTestCase
|
|||||||
$this->assertMatchesResourceCollectionJsonSchema(Connector::class);
|
$this->assertMatchesResourceCollectionJsonSchema(Connector::class);
|
||||||
$this->assertCount(0, $response->toArray()['hydra:member']);
|
$this->assertCount(0, $response->toArray()['hydra:member']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreateConnectorInvalidAuthData(): void
|
||||||
|
{
|
||||||
|
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
|
||||||
|
$client->request('POST', '/api/connectors', ['json' => [
|
||||||
|
'authData' => [
|
||||||
|
'waiveRetractationPeriod' => true,
|
||||||
|
'acceptConditions' => true,
|
||||||
|
'ownerLegalAge' => true,
|
||||||
|
'token' => '',
|
||||||
|
],
|
||||||
|
'provider' => 'gandi',
|
||||||
|
]]);
|
||||||
|
$this->assertResponseStatusCodeSame(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateConnectorInvalidConsent(): void
|
||||||
|
{
|
||||||
|
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
|
||||||
|
$client->request('POST', '/api/connectors', ['json' => [
|
||||||
|
'authData' => [
|
||||||
|
'waiveRetractationPeriod' => true,
|
||||||
|
'acceptConditions' => true,
|
||||||
|
'ownerLegalAge' => false,
|
||||||
|
'token' => '',
|
||||||
|
],
|
||||||
|
'provider' => 'gandi',
|
||||||
|
]]);
|
||||||
|
$this->assertResponseStatusCodeSame(451);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateConnectorInvalidAuthDataAdditionalKey(): void
|
||||||
|
{
|
||||||
|
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
|
||||||
|
$client->request('POST', '/api/connectors', ['json' => [
|
||||||
|
'authData' => [
|
||||||
|
'waiveRetractationPeriod' => true,
|
||||||
|
'acceptConditions' => true,
|
||||||
|
'ownerLegalAge' => true,
|
||||||
|
'token' => '',
|
||||||
|
'unknownKey' => 'hello',
|
||||||
|
],
|
||||||
|
'provider' => 'gandi',
|
||||||
|
]]);
|
||||||
|
$this->assertResponseStatusCodeSame(400);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
tests/Controller/HomeControllerTest.php
Normal file
24
tests/Controller/HomeControllerTest.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tests\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
|
class HomeControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
public function testIndex(): void
|
||||||
|
{
|
||||||
|
$client = static::createClient();
|
||||||
|
$client->request('GET', '/');
|
||||||
|
|
||||||
|
$this->assertResponseIsSuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConnectSsoReturnNotFound(): void
|
||||||
|
{
|
||||||
|
$client = static::createClient();
|
||||||
|
$client->request('GET', '/login/oauth');
|
||||||
|
|
||||||
|
$this->assertResponseStatusCodeSame(404);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user