Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
phpunit.xml
Tests/autoload.php
var/
vendor/
Propel/om/
Propel/map/
Expand Down
6 changes: 3 additions & 3 deletions Controller/AuthorizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
1 change: 1 addition & 0 deletions Form/Type/AuthorizeFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'FOS\OAuthServerBundle\Form\Model\Authorize',
'validation_groups' => [],
]);
}

Expand Down
2 changes: 0 additions & 2 deletions Resources/doc/configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
85 changes: 85 additions & 0 deletions Tests/Controller/AuthorizeControllerFunctionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* 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, '<form name="fos_oauth_server_authorize_form" method="post" action="/oauth/v2/auth">');
}

public function testAuthorizeActionWillFinishClientAuthorization(): void
{
// TODO: refactor unit AuthorizeControllerTest as functional test here
$this->assertTrue(true);
}

public function testAuthorizeActionWillEnsureLogout(): void
{
// TODO: refactor unit AuthorizeControllerTest as functional test here
$this->assertTrue(true);
}

public function testAuthorizeActionWillProcessAuthorizationForm(): void
{
// TODO: refactor unit AuthorizeControllerTest as functional test here
$this->assertTrue(true);
}
}
108 changes: 4 additions & 104 deletions Tests/Controller/AuthorizeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,106 +221,6 @@ public function setUp(): void
parent::setUp();
}

public function testAuthorizeActionWillThrowAccessDeniedException(): void
{
$token = $this->getMockBuilder(TokenInterface::class)
->disableOriginalConstructor()
->getMock()
;

$this->tokenStorage
->expects($this->at(0))
->method('getToken')
->willReturn($token)
;

$token
->expects($this->at(0))
->method('getUser')
->willReturn(null)
;

$this->expectException(AccessDeniedException::class);
$this->expectExceptionMessage('This user does not have access to this section.');

$this->instance->authorizeAction($this->request);
}

public function testAuthorizeActionWillRenderTemplate(): void
{
$token = $this->getMockBuilder(TokenInterface::class)
->disableOriginalConstructor()
->getMock()
;

$this->tokenStorage
->expects($this->at(0))
->method('getToken')
->willReturn($token)
;

$token
->expects($this->at(0))
->method('getUser')
->willReturn($this->user)
;

$this->session
->expects($this->at(0))
->method('get')
->with('_fos_oauth_server.ensure_logout')
->willReturn(false)
;

$propertyReflection = new ReflectionProperty(AuthorizeController::class, 'client');
$propertyReflection->setAccessible(true);
$propertyReflection->setValue($this->instance, $this->client);

$this->eventDispatcher
->expects($this->at(0))
->method('dispatch')
->with(new OAuthEvent($this->user, $this->client), OAuthEvent::PRE_AUTHORIZATION_PROCESS)
->willReturn($this->event)
;

$this->event
->expects($this->at(0))
->method('isAuthorizedClient')
->with()
->willReturn(false)
;

$this->authorizeFormHandler
->expects($this->at(0))
->method('process')
->with()
->willReturn(false)
;

$this->form
->expects($this->at(0))
->method('createView')
->willReturn($this->formView)
;

$response = '';

$this->twig
->expects($this->at(0))
->method('render')
->with(
'@FOSOAuthServer/Authorize/authorize.html.twig',
[
'form' => $this->formView,
'client' => $this->client,
]
)
->willReturn($response)
;

self::assertSame($response, $this->instance->authorizeAction($this->request));
}

public function testAuthorizeActionWillFinishClientAuthorization(): void
{
$token = $this->getMockBuilder(TokenInterface::class)
Expand Down Expand Up @@ -462,8 +362,6 @@ public function testAuthorizeActionWillEnsureLogout(): void
->willReturn($this->formView)
;

$response = '';

$this->twig
->expects($this->at(0))
->method('render')
Expand All @@ -474,10 +372,12 @@ public function testAuthorizeActionWillEnsureLogout(): void
'client' => $this->client,
]
)
->willReturn($response)
->willReturn('')
;

self::assertSame($response, $this->instance->authorizeAction($this->request));
$response = $this->instance->authorizeAction($this->request);
self::assertInstanceOf(Response::class, $response);
self::assertSame('', $response->getContent());
}

public function testAuthorizeActionWillProcessAuthorizationForm(): void
Expand Down
27 changes: 13 additions & 14 deletions Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;

/**
Expand All @@ -46,7 +47,7 @@ class OAuthFactoryTest extends TestCase

public function setUp(): void
{
$this->definitionDecoratorClass = 'Symfony\Component\DependencyInjection\DefinitionDecorator';
$this->definitionDecoratorClass = DefinitionDecorator::class;
$this->childDefinitionClass = ChildDefinition::class;

$this->instance = new OAuthFactory();
Expand All @@ -64,19 +65,6 @@ public function testGetKey(): void
self::assertSame('fos_oauth', $this->instance->getKey());
}

public function testCreate(): void
{
if (class_exists($this->childDefinitionClass)) {
return $this->useChildDefinition();
}

if (class_exists($this->definitionDecoratorClass)) {
return $this->useDefinitionDecorator();
}

throw new Exception('Neither DefinitionDecorator nor ChildDefinition exist');
}

public function testAddConfigurationDoesNothing(): void
{
$nodeDefinition = $this->getMockBuilder(NodeDefinition::class)
Expand All @@ -86,6 +74,17 @@ public function testAddConfigurationDoesNothing(): void
self::assertNull($this->instance->addConfiguration($nodeDefinition));
}

public function testCreate(): void
{
if (class_exists($this->childDefinitionClass)) {
$this->useChildDefinition();
} elseif (class_exists($this->definitionDecoratorClass)) {
$this->useDefinitionDecorator();
} else {
throw new Exception('Neither DefinitionDecorator nor ChildDefinition exist');
}
}

protected function useDefinitionDecorator(): void
{
$container = $this->getMockBuilder(ContainerBuilder::class)
Expand Down
1 change: 1 addition & 0 deletions Tests/Form/Type/AuthorizeFormTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function testConfigureOptionsWillSetDefaultsOnTheOptionsResolver(): void
->method('setDefaults')
->with([
'data_class' => Authorize::class,
'validation_groups' => [],
])
->willReturn($resolver)
;
Expand Down
6 changes: 3 additions & 3 deletions Tests/Functional/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class AppKernel extends Kernel
public function registerBundles()
{
$bundles = [
new \FOS\OAuthServerBundle\FOSOAuthServerBundle(),
new \FOS\OAuthServerBundle\Tests\Functional\TestBundle\TestBundle(),
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\MonologBundle\MonologBundle(),
new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
new \Symfony\Bundle\TwigBundle\TwigBundle(),
new \FOS\OAuthServerBundle\FOSOAuthServerBundle(),

new \FOS\OAuthServerBundle\Tests\Functional\TestBundle\TestBundle(),
];

if ('orm' === $this->getEnvironment()) {
Expand Down
Loading