GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch master (f137da)
by Dmitri
01:44
created

anonymous//Tests/Security/AbstractAuthenticatorTest.php$0   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
wmc 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Tests\Security;
6
7
use Damax\Bundle\ApiAuthBundle\Extractor\Extractor;
8
use Damax\Bundle\ApiAuthBundle\Security\AbstractAuthenticator;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use PHPUnit\Framework\TestCase;
11
use Symfony\Component\HttpFoundation\JsonResponse;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
14
use Symfony\Component\Security\Core\Exception\AuthenticationException;
15
use Symfony\Component\Security\Core\User\UserInterface;
16
use Symfony\Component\Security\Core\User\UserProviderInterface;
17
18
class AbstractAuthenticatorTest extends TestCase
19
{
20
    /**
21
     * @var Request
22
     */
23
    private $request;
24
25
    /**
26
     * @var Extractor|MockObject
27
     */
28
    private $extractor;
29
30
    /**
31
     * @var AbstractAuthenticator
32
     */
33
    private $authenticator;
34
35
    protected function setUp()
36
    {
37
        $this->request = new Request();
38
        $this->extractor = $extractor = $this->createMock(Extractor::class);
39
        $this->authenticator = new class($extractor) extends AbstractAuthenticator {
40
            public function getUser($credentials, UserProviderInterface $userProvider)
41
            {
42
            }
43
        };
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function it_supports_authentication()
50
    {
51
        $this->extractor
52
            ->expects($this->once())
53
            ->method('extractKey')
54
            ->with($this->identicalTo($this->request))
55
            ->willReturn('ABC')
56
        ;
57
58
        $this->assertTrue($this->authenticator->supports($this->request));
59
    }
60
61
    /**
62
     * @test
63
     */
64
    public function it_does_not_support_authentication()
65
    {
66
        $this->extractor
67
            ->expects($this->once())
68
            ->method('extractKey')
69
            ->with($this->identicalTo($this->request))
70
        ;
71
72
        $this->assertFalse($this->authenticator->supports($this->request));
73
    }
74
75
    /**
76
     * @test
77
     */
78
    public function it_starts_authentication()
79
    {
80
        $response = $this->authenticator->start($this->request);
81
82
        $this->assertInstanceOf(JsonResponse::class, $response);
83
        $this->assertEquals(401, $response->getStatusCode());
84
        $this->assertEquals('{"message":"Unauthorized"}', $response->getContent());
85
    }
86
87
    /**
88
     * @test
89
     */
90
    public function it_retrieves_credentials()
91
    {
92
        $this->extractor
93
            ->expects($this->once())
94
            ->method('extractKey')
95
            ->with($this->identicalTo($this->request))
96
            ->willReturn('ABC')
97
        ;
98
        $this->assertEquals('ABC', $this->authenticator->getCredentials($this->request));
99
    }
100
101
    /**
102
     * @test
103
     */
104
    public function it_always_validates_credentials()
105
    {
106
        /** @var UserInterface $user */
107
        $user = $this->createMock(UserInterface::class);
108
109
        $this->assertTrue($this->authenticator->checkCredentials('password', $user));
110
    }
111
112
    /**
113
     * @test
114
     */
115
    public function it_allows_authentication()
116
    {
117
        /** @var TokenInterface $token */
118
        $token = $this->createMock(TokenInterface::class);
119
120
        $this->assertNull($this->authenticator->onAuthenticationSuccess($this->request, $token, 'main'));
121
    }
122
123
    /**
124
     * @test
125
     */
126
    public function it_denies_authentication()
127
    {
128
        $response = $this->authenticator->onAuthenticationFailure(new Request(), new AuthenticationException('Authentication error.'));
129
130
        $this->assertInstanceOf(JsonResponse::class, $response);
131
        $this->assertEquals(403, $response->getStatusCode());
132
        $this->assertEquals('{"message":"Forbidden"}', $response->getContent());
133
    }
134
135
    /**
136
     * @test
137
     */
138
    public function it_does_not_support_remember_me()
139
    {
140
        $this->assertFalse($this->authenticator->supportsRememberMe());
141
    }
142
}
143