This commit is contained in:
Jeremy Benoist
2015-05-30 13:52:26 +02:00
parent 399bd777d7
commit 4346a86068
31 changed files with 204 additions and 163 deletions

View File

@ -47,6 +47,7 @@ class WallabagRestController extends Controller
* {"name"="username", "dataType"="string", "required"=true, "description"="username"}
* }
* )
*
* @return array
*/
public function getSaltAction($username)
@ -77,6 +78,7 @@ class WallabagRestController extends Controller
* {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."},
* }
* )
*
* @return Entry
*/
public function getEntriesAction(Request $request)
@ -109,13 +111,14 @@ class WallabagRestController extends Controller
}
/**
* Retrieve a single entry
* Retrieve a single entry.
*
* @ApiDoc(
* requirements={
* {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
* }
* )
*
* @return Entry
*/
public function getEntryAction(Entry $entry)
@ -128,7 +131,7 @@ class WallabagRestController extends Controller
}
/**
* Create an entry
* Create an entry.
*
* @ApiDoc(
* parameters={
@ -137,6 +140,7 @@ class WallabagRestController extends Controller
* {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
* }
* )
*
* @return Entry
*/
public function postEntriesAction(Request $request)
@ -164,7 +168,7 @@ class WallabagRestController extends Controller
}
/**
* Change several properties of an entry
* Change several properties of an entry.
*
* @ApiDoc(
* requirements={
@ -177,15 +181,16 @@ class WallabagRestController extends Controller
* {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."},
* }
* )
*
* @return Entry
*/
public function patchEntriesAction(Entry $entry, Request $request)
{
$this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId());
$title = $request->request->get("title");
$isArchived = $request->request->get("archive");
$isStarred = $request->request->get("star");
$title = $request->request->get('title');
$isArchived = $request->request->get('archive');
$isStarred = $request->request->get('star');
if (!is_null($title)) {
$entry->setTitle($title);
@ -213,13 +218,14 @@ class WallabagRestController extends Controller
}
/**
* Delete **permanently** an entry
* Delete **permanently** an entry.
*
* @ApiDoc(
* requirements={
* {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
* }
* )
*
* @return Entry
*/
public function deleteEntriesAction(Entry $entry)
@ -236,7 +242,7 @@ class WallabagRestController extends Controller
}
/**
* Retrieve all tags for an entry
* Retrieve all tags for an entry.
*
* @ApiDoc(
* requirements={
@ -254,7 +260,7 @@ class WallabagRestController extends Controller
}
/**
* Add one or more tags to an entry
* Add one or more tags to an entry.
*
* @ApiDoc(
* requirements={
@ -284,7 +290,7 @@ class WallabagRestController extends Controller
}
/**
* Permanently remove one tag for an entry
* Permanently remove one tag for an entry.
*
* @ApiDoc(
* requirements={
@ -308,7 +314,7 @@ class WallabagRestController extends Controller
}
/**
* Retrieve all tags
* Retrieve all tags.
*
* @ApiDoc()
*/
@ -320,7 +326,7 @@ class WallabagRestController extends Controller
}
/**
* Permanently remove one tag from **every** entry
* Permanently remove one tag from **every** entry.
*
* @ApiDoc(
* requirements={
@ -343,10 +349,10 @@ class WallabagRestController extends Controller
/**
* Validate that the first id is equal to the second one.
* If not, throw exception. It means a user try to access information from an other user
* If not, throw exception. It means a user try to access information from an other user.
*
* @param integer $requestUserId User id from the requested source
* @param integer $currentUserId User id from the retrieved source
* @param int $requestUserId User id from the requested source
* @param int $currentUserId User id from the retrieved source
*/
private function validateUserAccess($requestUserId, $currentUserId)
{
@ -357,7 +363,7 @@ class WallabagRestController extends Controller
/**
* Send a JSON Response.
* We don't use the Symfony JsonRespone, because it takes an array as parameter instead of a JSON string
* We don't use the Symfony JsonRespone, because it takes an array as parameter instead of a JSON string.
*
* @param string $json
*

View File

@ -6,7 +6,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/

View File

@ -1,4 +1,5 @@
<?php
namespace Wallabag\ApiBundle\Security\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
@ -29,7 +30,7 @@ class WsseProvider implements AuthenticationProviderInterface
$user = $this->userProvider->loadUserByUsername($token->getUsername());
if (!$user) {
throw new AuthenticationException("Bad credentials. Did you forgot your username?");
throw new AuthenticationException('Bad credentials. Did you forgot your username?');
}
if ($user && $this->validateDigest($token->digest, $token->nonce, $token->created, $user->getPassword())) {
@ -46,12 +47,12 @@ class WsseProvider implements AuthenticationProviderInterface
{
// Check created time is not in the future
if (strtotime($created) > time()) {
throw new AuthenticationException("Back to the future...");
throw new AuthenticationException('Back to the future...');
}
// Expire timestamp after 5 minutes
if (time() - strtotime($created) > 300) {
throw new AuthenticationException("Too late for this timestamp... Watch your watch.");
throw new AuthenticationException('Too late for this timestamp... Watch your watch.');
}
// Validate nonce is unique within 5 minutes
@ -65,7 +66,7 @@ class WsseProvider implements AuthenticationProviderInterface
$expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true));
if ($digest !== $expected) {
throw new AuthenticationException("Bad credentials ! Digest is not as expected.");
throw new AuthenticationException('Bad credentials ! Digest is not as expected.');
}
return $digest === $expected;

View File

@ -1,4 +1,5 @@
<?php
namespace Wallabag\ApiBundle\Security\Authentication\Token;
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;

View File

@ -9,7 +9,7 @@ class WallabagRestControllerTest extends WebTestCase
protected static $salt;
/**
* Grab the salt once and store it to be available for all tests
* Grab the salt once and store it to be available for all tests.
*/
public static function setUpBeforeClass()
{
@ -24,7 +24,7 @@ class WallabagRestControllerTest extends WebTestCase
}
/**
* Generate HTTP headers for authenticate user on API
* Generate HTTP headers for authenticate user on API.
*
* @param string $username
* @param string $password
@ -327,7 +327,7 @@ class WallabagRestControllerTest extends WebTestCase
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('tags', $content);
$this->assertEquals($nbTags+3, count($content['tags']));
$this->assertEquals($nbTags + 3, count($content['tags']));
$entryDB = $client->getContainer()
->get('doctrine.orm.entity_manager')
@ -369,7 +369,7 @@ class WallabagRestControllerTest extends WebTestCase
$content = json_decode($client->getResponse()->getContent(), true);
$this->assertArrayHasKey('tags', $content);
$this->assertEquals($nbTags-1, count($content['tags']));
$this->assertEquals($nbTags - 1, count($content['tags']));
}
public function testGetUserTags()