diff --git a/.gitignore b/.gitignore index b1a9bef1..42e746dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ phpunit.xml Tests/autoload.php +var/ vendor/ Propel/om/ Propel/map/ diff --git a/Controller/AuthorizeController.php b/Controller/AuthorizeController.php index 07febaa3..f973597e 100644 --- a/Controller/AuthorizeController.php +++ b/Controller/AuthorizeController.php @@ -167,9 +167,9 @@ public function authorizeAction(Request $request) 'client' => $this->getClient(), ]; - return $this->twig->render( - '@FOSOAuthServer/Authorize/authorize.html.twig', - $data + return new Response( + $this->twig->render('@FOSOAuthServer/Authorize/authorize.html.twig', $data), + Response::HTTP_OK ); } diff --git a/Form/Type/AuthorizeFormType.php b/Form/Type/AuthorizeFormType.php index 08aec45f..cfecf2a1 100644 --- a/Form/Type/AuthorizeFormType.php +++ b/Form/Type/AuthorizeFormType.php @@ -41,6 +41,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'data_class' => 'FOS\OAuthServerBundle\Form\Model\Authorize', + 'validation_groups' => [], ]); } diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md index 9529fa32..deade0e9 100644 --- a/Resources/doc/configuration_reference.md +++ b/Resources/doc/configuration_reference.md @@ -50,8 +50,6 @@ fos_oauth_server: # Enforce state to be passed in authorization (see RFC 6749, section 10.12) #enforce_state: true or false - template: - engine: twig ``` [Back to index](index.md) diff --git a/Tests/Controller/AuthorizeControllerFunctionalTest.php b/Tests/Controller/AuthorizeControllerFunctionalTest.php new file mode 100644 index 00000000..40c76c31 --- /dev/null +++ b/Tests/Controller/AuthorizeControllerFunctionalTest.php @@ -0,0 +1,85 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\Tests\Controller; + +use FOS\OAuthServerBundle\Tests\Functional\TestCase; +use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; +use Symfony\Component\Security\Core\User\UserInterface; +use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken; + +class AuthorizeControllerFunctionalTest extends TestCase +{ + public function setUp(): void + { + parent::setUp(); + + $this->client = $this->createClient(); + } + + public function tearDown(): void + { + unset($this->client); + + parent::tearDown(); + } + + public function testAuthorizeActionWillThrowAccessDeniedException(): void + { + self::$kernel->getContainer()->get('security.token_storage')->setToken(new AnonymousToken('test-secret', 'anon')); + + $this->expectException(AccessDeniedException::class); + $this->expectExceptionMessage('This user does not have access to this section.'); + + $this->client->catchExceptions(false); + $this->client->request('GET', '/oauth/v2/auth'); + } + + public function testAuthorizeActionWillRenderTemplate(): void + { + $user = $this->getMockBuilder(UserInterface::class) + ->disableOriginalConstructor() + ->getMock() + ; + + self::$kernel->getContainer()->get('security.token_storage')->setToken( + new PostAuthenticationGuardToken($user, 'member_area', ['ROLE_USER']) + ); + + $this->client->catchExceptions(false); + $this->client->request('GET', '/oauth/v2/auth', [ + 'client_id' => '123_test-client-id', + ]); + + $this->assertResponse(200, '