AuthenticatorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testProtectedRouteWithBearerToken() 0 6 1
A testProtectedRouteWithInvalidJWTToken() 0 7 1
A testProtectedRouteWithQueryToken() 0 6 1
A testProtectedRouteWithoutAuthentication() 0 8 1
A testProtectedRouteInDevEnvironment() 0 6 1
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