1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AtlassianConnectBundle\Tests\Functional; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Tests JWTAuthenticator and LegacyJWTAuthenticator. |
9
|
|
|
*/ |
10
|
|
|
final class AuthenticatorTest extends AbstractWebTestCase |
11
|
|
|
{ |
12
|
|
|
public function testProtectedRouteWithoutAuthentication(): void |
13
|
|
|
{ |
14
|
|
|
$client = self::createClient(); |
15
|
|
|
|
16
|
|
|
$client->request('GET', '/protected/route'); |
17
|
|
|
|
18
|
|
|
$this->assertResponseStatusCodeSame(401); |
19
|
|
|
$this->assertSame('Authentication header required', $client->getResponse()->getContent()); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testProtectedRouteWithBearerToken(): void |
23
|
|
|
{ |
24
|
|
|
$client = self::createClient([], ['HTTP_AUTHORIZATION' => 'Bearer '.$this->getTenantJWTCode()]); |
25
|
|
|
|
26
|
|
|
$client->request('GET', '/protected/route'); |
27
|
|
|
$this->assertResponseIsSuccessful(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testProtectedRouteWithQueryToken(): void |
31
|
|
|
{ |
32
|
|
|
$client = self::createClient(); |
33
|
|
|
|
34
|
|
|
$client->request('GET', '/protected/route?jwt='.$this->getTenantJWTCode()); |
35
|
|
|
$this->assertResponseIsSuccessful(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testProtectedRouteInDevEnvironment(): void |
39
|
|
|
{ |
40
|
|
|
$client = self::createClient(['environment' => 'dev']); |
41
|
|
|
|
42
|
|
|
$client->request('GET', '/protected/route'); |
43
|
|
|
$this->assertResponseIsSuccessful(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testProtectedRouteWithInvalidJWTToken(): void |
47
|
|
|
{ |
48
|
|
|
$client = self::createClient(); |
49
|
|
|
|
50
|
|
|
$client->request('GET', '/protected/route?jwt=invalid'); |
51
|
|
|
$this->assertResponseStatusCodeSame(403); |
52
|
|
|
$this->assertEquals('Authentication Failed: Failed to parse token', $client->getResponse()->getContent()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|