diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-08 00:02:22 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-08 00:05:41 +0200 |
commit | ee32248f43baef7e995c9e420cd00a137e626cf0 (patch) | |
tree | e8119e417887b3132bc7c448a7591943c90dcab2 | |
parent | b0da721a5238ece3056ae7af760e9455f7af3e11 (diff) | |
download | wallabag-ee32248f43baef7e995c9e420cd00a137e626cf0.tar.gz wallabag-ee32248f43baef7e995c9e420cd00a137e626cf0.tar.zst wallabag-ee32248f43baef7e995c9e420cd00a137e626cf0.zip |
Ensure access_token are removed
When we remove the client, we should ensure that access_token are also removed.
To ensure that, I created a test that generated an access_token. So when we remove the client, this association should be cascaded and shouldn’t generate an error.
Also I moved some Api related stuff to the ApiBundle (like the developer controler and ClientType form)
-rw-r--r-- | app/config/routing.yml | 5 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/DeveloperController.php (renamed from src/Wallabag/CoreBundle/Controller/DeveloperController.php) | 4 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Entity/Client.php | 5 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Form/Type/ClientType.php (renamed from src/Wallabag/CoreBundle/Form/Type/ClientType.php) | 2 | ||||
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php (renamed from tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php) | 28 |
5 files changed, 40 insertions, 4 deletions
diff --git a/app/config/routing.yml b/app/config/routing.yml index 2be74d7f..750ed435 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml | |||
@@ -13,6 +13,11 @@ wallabag_user: | |||
13 | prefix: /users | 13 | prefix: /users |
14 | 14 | ||
15 | wallabag_api: | 15 | wallabag_api: |
16 | resource: "@WallabagApiBundle/Controller/" | ||
17 | type: annotation | ||
18 | prefix: / | ||
19 | |||
20 | wallabag_api: | ||
16 | resource: "@WallabagApiBundle/Resources/config/routing.yml" | 21 | resource: "@WallabagApiBundle/Resources/config/routing.yml" |
17 | prefix: / | 22 | prefix: / |
18 | 23 | ||
diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/ApiBundle/Controller/DeveloperController.php index f3492b74..5a36a260 100644 --- a/src/Wallabag/CoreBundle/Controller/DeveloperController.php +++ b/src/Wallabag/ApiBundle/Controller/DeveloperController.php | |||
@@ -1,12 +1,12 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\ApiBundle\Controller; |
4 | 4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
6 | use Symfony\Component\HttpFoundation\Request; | 6 | use Symfony\Component\HttpFoundation\Request; |
7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
8 | use Wallabag\ApiBundle\Entity\Client; | 8 | use Wallabag\ApiBundle\Entity\Client; |
9 | use Wallabag\CoreBundle\Form\Type\ClientType; | 9 | use Wallabag\ApiBundle\Form\Type\ClientType; |
10 | 10 | ||
11 | class DeveloperController extends Controller | 11 | class DeveloperController extends Controller |
12 | { | 12 | { |
diff --git a/src/Wallabag/ApiBundle/Entity/Client.php b/src/Wallabag/ApiBundle/Entity/Client.php index 92b2f762..f7898ac8 100644 --- a/src/Wallabag/ApiBundle/Entity/Client.php +++ b/src/Wallabag/ApiBundle/Entity/Client.php | |||
@@ -30,6 +30,11 @@ class Client extends BaseClient | |||
30 | */ | 30 | */ |
31 | protected $refreshTokens; | 31 | protected $refreshTokens; |
32 | 32 | ||
33 | /** | ||
34 | * @ORM\OneToMany(targetEntity="AccessToken", mappedBy="client", cascade={"remove"}) | ||
35 | */ | ||
36 | protected $accessTokens; | ||
37 | |||
33 | public function __construct() | 38 | public function __construct() |
34 | { | 39 | { |
35 | parent::__construct(); | 40 | parent::__construct(); |
diff --git a/src/Wallabag/CoreBundle/Form/Type/ClientType.php b/src/Wallabag/ApiBundle/Form/Type/ClientType.php index d1fa94e6..0ea1a9c5 100644 --- a/src/Wallabag/CoreBundle/Form/Type/ClientType.php +++ b/src/Wallabag/ApiBundle/Form/Type/ClientType.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Form\Type; | 3 | namespace Wallabag\ApiBundle\Form\Type; |
4 | 4 | ||
5 | use Symfony\Component\Form\AbstractType; | 5 | use Symfony\Component\Form\AbstractType; |
6 | use Symfony\Component\Form\CallbackTransformer; | 6 | use Symfony\Component\Form\CallbackTransformer; |
diff --git a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index 97ed0d58..95befa9c 100644 --- a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\ApiBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | 6 | ||
@@ -33,6 +33,32 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
33 | $this->assertContains('My app', $alert[0]); | 33 | $this->assertContains('My app', $alert[0]); |
34 | } | 34 | } |
35 | 35 | ||
36 | /** | ||
37 | * @depends testCreateClient | ||
38 | */ | ||
39 | public function testCreateToken() | ||
40 | { | ||
41 | $client = $this->getClient(); | ||
42 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
43 | $apiClient = $em->getRepository('WallabagApiBundle:Client')->findOneByName('My app'); | ||
44 | |||
45 | $client->request('POST', '/oauth/v2/token', [ | ||
46 | 'grant_type' => 'password', | ||
47 | 'client_id' => $apiClient->getPublicId(), | ||
48 | 'client_secret' => $apiClient->getSecret(), | ||
49 | 'username' => 'admin', | ||
50 | 'password' => 'mypassword', | ||
51 | ]); | ||
52 | |||
53 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
54 | |||
55 | $data = json_decode($client->getResponse()->getContent(), true); | ||
56 | $this->assertArrayHasKey('access_token', $data); | ||
57 | $this->assertArrayHasKey('expires_in', $data); | ||
58 | $this->assertArrayHasKey('token_type', $data); | ||
59 | $this->assertArrayHasKey('refresh_token', $data); | ||
60 | } | ||
61 | |||
36 | public function testListingClient() | 62 | public function testListingClient() |
37 | { | 63 | { |
38 | $this->logInAs('admin'); | 64 | $this->logInAs('admin'); |