Skip to content

Commit

Permalink
Securing edpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Aug 9, 2020
1 parent 999ebd6 commit 4115fb0
Show file tree
Hide file tree
Showing 26 changed files with 378 additions and 32 deletions.
12 changes: 12 additions & 0 deletions src/Controllers/ActionsV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
* @subpackage Controllers
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*
* @Secured
* @Secured\User(loggedIn)
*/
final class ActionsV1Controller extends BaseV1Controller
{
Expand Down Expand Up @@ -128,6 +131,9 @@ public function read(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function create(
Message\ServerRequestInterface $request,
Expand Down Expand Up @@ -252,6 +258,9 @@ public function create(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function update(
Message\ServerRequestInterface $request,
Expand Down Expand Up @@ -334,6 +343,9 @@ public function update(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function delete(
Message\ServerRequestInterface $request,
Expand Down
12 changes: 12 additions & 0 deletions src/Controllers/ConditionsV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
* @subpackage Controllers
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*
* @Secured
* @Secured\User(loggedIn)
*/
final class ConditionsV1Controller extends BaseV1Controller
{
Expand Down Expand Up @@ -154,6 +157,9 @@ public function read(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function create(
Message\ServerRequestInterface $request,
Expand Down Expand Up @@ -292,6 +298,9 @@ public function create(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function update(
Message\ServerRequestInterface $request,
Expand Down Expand Up @@ -386,6 +395,9 @@ public function update(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function delete(
Message\ServerRequestInterface $request,
Expand Down
12 changes: 12 additions & 0 deletions src/Controllers/NotificationsV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
* @subpackage Controllers
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*
* @Secured
* @Secured\User(loggedIn)
*/
final class NotificationsV1Controller extends BaseV1Controller
{
Expand Down Expand Up @@ -133,6 +136,9 @@ public function read(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function create(
Message\ServerRequestInterface $request,
Expand Down Expand Up @@ -273,6 +279,9 @@ public function create(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function update(
Message\ServerRequestInterface $request,
Expand Down Expand Up @@ -361,6 +370,9 @@ public function update(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function delete(
Message\ServerRequestInterface $request,
Expand Down
12 changes: 12 additions & 0 deletions src/Controllers/TriggersV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
* @subpackage Controllers
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*
* @Secured
* @Secured\User(loggedIn)
*/
final class TriggersV1Controller extends BaseV1Controller
{
Expand Down Expand Up @@ -121,6 +124,9 @@ public function read(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function create(
Message\ServerRequestInterface $request,
Expand Down Expand Up @@ -235,6 +241,9 @@ public function create(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function update(
Message\ServerRequestInterface $request,
Expand Down Expand Up @@ -326,6 +335,9 @@ public function update(
*
* @throws NodeJsonApiExceptions\IJsonApiException
* @throws Doctrine\DBAL\ConnectionException
*
* @Secured
* @Secured\Role(manager,administrator)
*/
public function delete(
Message\ServerRequestInterface $request,
Expand Down
46 changes: 38 additions & 8 deletions tests/cases/Unit/Controllers/ActionsV1ControllerTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,27 @@ final class ActionsV1ControllerTest extends DbTestCase

/**
* @param string $url
* @param string|null $token
* @param int $statusCode
* @param string $fixture
*
* @dataProvider ./../../../fixtures/Controllers/actionsRead.php
*/
public function testRead(string $url, int $statusCode, string $fixture): void
public function testRead(string $url, ?string $token, int $statusCode, string $fixture): void
{
/** @var Router\Router $router */
$router = $this->getContainer()->getByType(Router\Router::class);

$headers = [];

if ($token !== null) {
$headers['authorization'] = $token;
}

$request = new ServerRequest(
RequestMethodInterface::METHOD_GET,
$url
$url,
$headers
);

$response = $router->handle($request);
Expand All @@ -47,21 +55,28 @@ final class ActionsV1ControllerTest extends DbTestCase

/**
* @param string $url
* @param string|null $token
* @param string $body
* @param int $statusCode
* @param string $fixture
*
* @dataProvider ./../../../fixtures/Controllers/actionsCreate.php
*/
public function testCreate(string $url, string $body, int $statusCode, string $fixture): void
public function testCreate(string $url, ?string $token, string $body, int $statusCode, string $fixture): void
{
/** @var Router\Router $router */
$router = $this->getContainer()->getByType(Router\Router::class);

$headers = [];

if ($token !== null) {
$headers['authorization'] = $token;
}

$request = new ServerRequest(
RequestMethodInterface::METHOD_POST,
$url,
[],
$headers,
$body
);

Expand All @@ -77,21 +92,28 @@ final class ActionsV1ControllerTest extends DbTestCase

/**
* @param string $url
* @param string|null $token
* @param string $body
* @param int $statusCode
* @param string $fixture
*
* @dataProvider ./../../../fixtures/Controllers/actionsUpdate.php
*/
public function testUpdate(string $url, string $body, int $statusCode, string $fixture): void
public function testUpdate(string $url, ?string $token, string $body, int $statusCode, string $fixture): void
{
/** @var Router\Router $router */
$router = $this->getContainer()->getByType(Router\Router::class);

$headers = [];

if ($token !== null) {
$headers['authorization'] = $token;
}

$request = new ServerRequest(
RequestMethodInterface::METHOD_PATCH,
$url,
[],
$headers,
$body
);

Expand All @@ -107,19 +129,27 @@ final class ActionsV1ControllerTest extends DbTestCase

/**
* @param string $url
* @param string|null $token
* @param int $statusCode
* @param string $fixture
*
* @dataProvider ./../../../fixtures/Controllers/actionsDelete.php
*/
public function testDelete(string $url, int $statusCode, string $fixture): void
public function testDelete(string $url, ?string $token, int $statusCode, string $fixture): void
{
/** @var Router\Router $router */
$router = $this->getContainer()->getByType(Router\Router::class);

$headers = [];

if ($token !== null) {
$headers['authorization'] = $token;
}

$request = new ServerRequest(
RequestMethodInterface::METHOD_DELETE,
$url
$url,
$headers
);

$response = $router->handle($request);
Expand Down

0 comments on commit 4115fb0

Please sign in to comment.