From ee32248f43baef7e995c9e420cd00a137e626cf0 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 8 Oct 2016 00:02:22 +0200 Subject: [PATCH] Ensure access_token are removed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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) --- app/config/routing.yml | 5 ++++ .../Controller/DeveloperController.php | 4 +-- src/Wallabag/ApiBundle/Entity/Client.php | 5 ++++ .../Form/Type/ClientType.php | 2 +- .../Controller/DeveloperControllerTest.php | 28 ++++++++++++++++++- 5 files changed, 40 insertions(+), 4 deletions(-) rename src/Wallabag/{CoreBundle => ApiBundle}/Controller/DeveloperController.php (97%) rename src/Wallabag/{CoreBundle => ApiBundle}/Form/Type/ClientType.php (97%) rename tests/Wallabag/{CoreBundle => ApiBundle}/Controller/DeveloperControllerTest.php (72%) 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 @@ -12,6 +12,11 @@ wallabag_user: type: annotation prefix: /users +wallabag_api: + resource: "@WallabagApiBundle/Controller/" + type: annotation + prefix: / + wallabag_api: resource: "@WallabagApiBundle/Resources/config/routing.yml" prefix: / diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/ApiBundle/Controller/DeveloperController.php similarity index 97% rename from src/Wallabag/CoreBundle/Controller/DeveloperController.php rename to 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 @@ assertContains('My app', $alert[0]); } + /** + * @depends testCreateClient + */ + public function testCreateToken() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $apiClient = $em->getRepository('WallabagApiBundle:Client')->findOneByName('My app'); + + $client->request('POST', '/oauth/v2/token', [ + 'grant_type' => 'password', + 'client_id' => $apiClient->getPublicId(), + 'client_secret' => $apiClient->getSecret(), + 'username' => 'admin', + 'password' => 'mypassword', + ]); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $data = json_decode($client->getResponse()->getContent(), true); + $this->assertArrayHasKey('access_token', $data); + $this->assertArrayHasKey('expires_in', $data); + $this->assertArrayHasKey('token_type', $data); + $this->assertArrayHasKey('refresh_token', $data); + } + public function testListingClient() { $this->logInAs('admin'); -- 2.41.0