diff options
-rw-r--r-- | app/config/security.yml | 4 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 20 | ||||
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | 17 |
3 files changed, 38 insertions, 3 deletions
diff --git a/app/config/security.yml b/app/config/security.yml index 0318fce1..96489e26 100644 --- a/app/config/security.yml +++ b/app/config/security.yml | |||
@@ -57,9 +57,7 @@ security: | |||
57 | target: / | 57 | target: / |
58 | 58 | ||
59 | access_control: | 59 | access_control: |
60 | - { path: ^/api/doc, roles: IS_AUTHENTICATED_ANONYMOUSLY } | 60 | - { path: ^/api/(doc|version|info|user), roles: IS_AUTHENTICATED_ANONYMOUSLY } |
61 | - { path: ^/api/version, roles: IS_AUTHENTICATED_ANONYMOUSLY } | ||
62 | - { path: ^/api/user, roles: IS_AUTHENTICATED_ANONYMOUSLY } | ||
63 | - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } | 61 | - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } |
64 | - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } | 62 | - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } |
65 | - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } | 63 | - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } |
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 7d8cfbba..3c7ad0cf 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -14,6 +14,8 @@ class WallabagRestController extends FOSRestController | |||
14 | * | 14 | * |
15 | * @ApiDoc() | 15 | * @ApiDoc() |
16 | * | 16 | * |
17 | * @deprecated Should use info endpoint instead | ||
18 | * | ||
17 | * @return JsonResponse | 19 | * @return JsonResponse |
18 | */ | 20 | */ |
19 | public function getVersionAction() | 21 | public function getVersionAction() |
@@ -24,6 +26,24 @@ class WallabagRestController extends FOSRestController | |||
24 | return (new JsonResponse())->setJson($json); | 26 | return (new JsonResponse())->setJson($json); |
25 | } | 27 | } |
26 | 28 | ||
29 | /** | ||
30 | * Retrieve information about the wallabag instance. | ||
31 | * | ||
32 | * @ApiDoc() | ||
33 | * | ||
34 | * @return JsonResponse | ||
35 | */ | ||
36 | public function getInfoAction() | ||
37 | { | ||
38 | $info = [ | ||
39 | 'appname' => 'wallabag', | ||
40 | 'version' => $this->container->getParameter('wallabag_core.version'), | ||
41 | 'allowed_registration' => $this->container->getParameter('wallabag_user.registration_enabled'), | ||
42 | ]; | ||
43 | |||
44 | return (new JsonResponse())->setJson($this->get('jms_serializer')->serialize($info, 'json')); | ||
45 | } | ||
46 | |||
27 | protected function validateAuthentication() | 47 | protected function validateAuthentication() |
28 | { | 48 | { |
29 | if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { | 49 | if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { |
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index ac4d6cdc..8b49c0ae 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | |||
@@ -18,4 +18,21 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
18 | 18 | ||
19 | $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content); | 19 | $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content); |
20 | } | 20 | } |
21 | |||
22 | public function testGetInfo() | ||
23 | { | ||
24 | // create a new client instead of using $this->client to be sure client isn't authenticated | ||
25 | $client = static::createClient(); | ||
26 | $client->request('GET', '/api/info'); | ||
27 | |||
28 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
29 | |||
30 | $content = json_decode($client->getResponse()->getContent(), true); | ||
31 | |||
32 | $this->assertArrayHasKey('appname', $content); | ||
33 | $this->assertArrayHasKey('version', $content); | ||
34 | $this->assertArrayHasKey('allowed_registration', $content); | ||
35 | |||
36 | $this->assertSame('wallabag', $content['appname']); | ||
37 | } | ||
21 | } | 38 | } |