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.
Completed
Push — master ( 932629...d7a7a8 )
by François
03:12
created

VootProviderTest::testVootCallInvalidToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 *  Copyright (C) 2016 SURFnet.
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as
7
 *  published by the Free Software Foundation, either version 3 of the
8
 *  License, or (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace SURFnet\VPN\Server\Tests\Acl\Provider;
20
21
use DateTime;
22
use fkooman\OAuth\Client\AccessToken;
23
use fkooman\OAuth\Client\Http\Response;
24
use fkooman\OAuth\Client\OAuthClient;
25
use fkooman\OAuth\Client\Provider;
26
use PDO;
27
use PHPUnit_Framework_TestCase;
28
use Psr\Log\NullLogger;
29
use SURFnet\VPN\Server\Acl\Provider\VootProvider;
30
use SURFnet\VPN\Server\Storage;
31
32
class VootProviderTest extends PHPUnit_Framework_TestCase
33
{
34
    /** @var VootProvider */
35
    private $vootProvider;
36
37
    public function setUp()
0 ignored issues
show
Coding Style introduced by
setUp uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
38
    {
39
        $vootClient = $this->getMockBuilder('\fkooman\OAuth\Client\Http\HttpClientInterface')->getMock();
40
        $vootClient->method('get')->will(
41
            $this->onConsecutiveCalls(
42
                new Response(200, file_get_contents(sprintf('%s/data/response.json', __DIR__))),
43
                new Response(401, file_get_contents(sprintf('%s/data/response_invalid_token.json', __DIR__)))
44
            )
45
        );
46
47
        $storage = new Storage(
48
            new PDO(
49
                $GLOBALS['DB_DSN'],
50
                $GLOBALS['DB_USER'],
51
                $GLOBALS['DB_PASSWD']
52
            ),
53
            new DateTime()
54
        );
55
        $storage->init();
56
        $storage->setAccessToken('foo', new AccessToken('AT', 'bearer', 'foo_bar', 'RT', new DateTime('2016-01-02')));
57
58
        $random = $this->getMockBuilder('fkooman\OAuth\Client\RandomInterface')->getMock();
59
        $random->method('get')->will($this->onConsecutiveCalls('random_1', 'random_2'));
60
61
        $oauthClient = new OAuthClient(
62
            new Provider('a', 'b', 'c', 'd'),
63
            $storage,
64
            $vootClient,
65
            $random,
66
            new NullLogger(),
67
            new DateTime('2016-01-01')
68
        );
69
70
        $this->vootProvider = new VootProvider(
71
            $oauthClient,
72
            'https://voot.surfconext.nl/me/groups'
73
        );
74
    }
75
76
    public function testVootCall()
77
    {
78
        $this->assertSame(
79
            [
80
                [
81
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:eduvpn',
82
                    'displayName' => 'EduVPN',
83
                ],
84
                [
85
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:eduvpn-test',
86
                    'displayName' => 'eduVPN-test',
87
                ],
88
                [
89
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:enabling_dynamic_services_2015',
90
                    'displayName' => 'Enabling Dynamic Services 2015',
91
                ],
92
                [
93
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:surfcloud_utrecht_users',
94
                    'displayName' => 'SURFcloud Utrecht users',
95
                ],
96
            ],
97
            $this->vootProvider->getGroups('foo')
98
        );
99
    }
100
101
    public function testVootCallNoToken()
102
    {
103
        $this->assertSame(
104
            [
105
            ],
106
            $this->vootProvider->getGroups('bar')
107
        );
108
    }
109
110
    public function testVootCallInvalidToken()
111
    {
112
        // first call succeeds, second call is invalid token response
113
        $this->vootProvider->getGroups('foo');
114
        $this->assertSame(
115
            [
116
            ],
117
            $this->vootProvider->getGroups('foo')
118
        );
119
    }
120
}
121