Skip to content

Commit f12673f

Browse files
committed
Merge branch '4.3' into main
2 parents a509a75 + dad45bf commit f12673f

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
},
1818
"autoload-dev": {
1919
"psr-4": {
20-
"EzSystems\\EzPlatformRestBundle\\Tests\\": "tests/bundle/",
21-
"EzSystems\\EzPlatformRest\\Tests\\": "tests/lib/",
2220
"Ibexa\\Tests\\Rest\\": "tests/lib/",
23-
"Ibexa\\Tests\\Bundle\\Rest\\": "tests/bundle/"
21+
"Ibexa\\Tests\\Bundle\\Rest\\": "tests/bundle/",
22+
"Ibexa\\Tests\\Contracts\\Rest\\": "tests/contracts/",
23+
"Ibexa\\Tests\\Integration\\Rest\\": "tests/integration/"
2424
}
2525
},
2626
"require": {

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</testsuite>
1616
<testsuite name="Ibexa REST">
1717
<directory>tests/lib/</directory>
18+
<directory>tests/contracts/</directory>
1819
<exclude>tests/lib/Server</exclude>
1920
</testsuite>
2021
<testsuite name="Ibexa REST Server Tests">

src/bundle/Resources/config/security.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ services:
1212
- "@?logger"
1313
abstract: true
1414

15+
Ibexa\Contracts\Rest\Security\AuthorizationHeaderRESTRequestMatcher: ~
16+
1517
Ibexa\Rest\Server\Security\RestLogoutHandler:
1618
arguments:
1719
- '@ibexa.config.resolver'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Contracts\Rest\Security;
10+
11+
use Symfony\Component\HttpFoundation\Request;
12+
use Symfony\Component\HttpFoundation\RequestMatcher;
13+
14+
final class AuthorizationHeaderRESTRequestMatcher extends RequestMatcher
15+
{
16+
public function matches(Request $request): bool
17+
{
18+
if ($request->attributes->get('is_rest_request', false) !== true) {
19+
return false;
20+
}
21+
22+
if (
23+
$request->attributes->get('_route') === 'ibexa.rest.create_token'
24+
|| !empty($request->headers->get('Authorization'))
25+
) {
26+
return parent::matches($request);
27+
}
28+
29+
return false;
30+
}
31+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Tests\Contracts\Rest\Security;
10+
11+
use Ibexa\Contracts\Rest\Security\AuthorizationHeaderRESTRequestMatcher;
12+
use PHPUnit\Framework\TestCase;
13+
use Symfony\Component\HttpFoundation\Request;
14+
15+
final class AuthorizationHeaderRESTRequestMatcherTest extends TestCase
16+
{
17+
public function testDoesNotMatchNonRestRequests(): void
18+
{
19+
$matcher = new AuthorizationHeaderRESTRequestMatcher();
20+
21+
self::assertFalse($matcher->matches(new Request()));
22+
}
23+
24+
public function testDoesNotMatchRestRequestsWithoutHeader(): void
25+
{
26+
$matcher = new AuthorizationHeaderRESTRequestMatcher();
27+
28+
$request = new Request([], [], [
29+
'is_rest_request' => true,
30+
]);
31+
32+
self::assertFalse($matcher->matches($request));
33+
}
34+
35+
public function testMatchesRestRequestsWithHeader(): void
36+
{
37+
$matcher = new AuthorizationHeaderRESTRequestMatcher();
38+
39+
$request = new Request([], [], [
40+
'is_rest_request' => true,
41+
], [], [], [
42+
'HTTP_AUTHORIZATION' => 'Bearer foo',
43+
]);
44+
45+
self::assertTrue($matcher->matches($request));
46+
}
47+
48+
public function testMatchesRestJwtCreationEndpoint(): void
49+
{
50+
$matcher = new AuthorizationHeaderRESTRequestMatcher();
51+
52+
$request = new Request([], [], [
53+
'is_rest_request' => true,
54+
'_route' => 'ibexa.rest.create_token',
55+
]);
56+
57+
self::assertTrue($matcher->matches($request));
58+
}
59+
}

0 commit comments

Comments
 (0)