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.

VootProviderTest::testVootCallInvalidToken()   A
last analyzed

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
/**
4
 * eduVPN - End-user friendly VPN.
5
 *
6
 * Copyright: 2016-2017, The Commons Conservancy eduVPN Programme
7
 * SPDX-License-Identifier: AGPL-3.0+
8
 */
9
10
namespace SURFnet\VPN\Server\Tests\Acl\Provider;
11
12
use DateTime;
13
use fkooman\OAuth\Client\AccessToken;
14
use fkooman\OAuth\Client\Http\Response;
15
use fkooman\OAuth\Client\OAuthClient;
16
use fkooman\OAuth\Client\Provider;
17
use PDO;
18
use PHPUnit_Framework_TestCase;
19
use SURFnet\VPN\Server\Acl\Provider\VootProvider;
20
use SURFnet\VPN\Server\Storage;
21
use SURFnet\VPN\Server\Tests\TestOAuthClientRandom;
22
use SURFnet\VPN\Server\Tests\TestOAuthClientSession;
23
24
class VootProviderTest extends PHPUnit_Framework_TestCase
25
{
26
    /** @var VootProvider */
27
    private $vootProvider;
28
29
    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...
30
    {
31
        $vootClient = $this->getMockBuilder('\fkooman\OAuth\Client\Http\HttpClientInterface')->getMock();
32
        $vootClient->method('send')->will(
33
            $this->onConsecutiveCalls(
34
                new Response(200, file_get_contents(sprintf('%s/data/response.json', __DIR__)), ['Content-Type' => 'application/json']),
35
                new Response(401, file_get_contents(sprintf('%s/data/response_invalid_token.json', __DIR__)), ['Content-Type' => 'application/json'])
36
            )
37
        );
38
39
        $storage = new Storage(
40
            new PDO(
41
                $GLOBALS['DB_DSN'],
42
                $GLOBALS['DB_USER'],
43
                $GLOBALS['DB_PASSWD']
44
            ),
45
            new DateTime()
46
        );
47
        $storage->init();
48
//        $storage->setAccessToken('foo', 'voot', new AccessToken('AT', 'bearer', 'groups', 'RT', new DateTime('2016-01-02')));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
49
        $storage->storeAccessToken(
50
            'foo',
51
            AccessToken::fromJson(
52
                json_encode([
53
                    'provider_id' => 'c|a',
54
                    'user_id' => 'foo',
55
                    'access_token' => 'AT',
56
                    'token_type' => 'bearer',
57
                    'scope' => 'groups',
58
                    'refresh_token' => 'RT',
59
                    'expires_in' => 3600,
60
                    'issued_at' => '2016-01-02 00:00:00',
61
                ])
62
            )
63
        );
64
65
        $oauthClient = new OAuthClient(
66
            $storage,
67
            $vootClient,
68
            new TestOAuthClientSession(),
69
            new TestOAuthClientRandom(),
70
            new DateTime('2016-01-01')
71
        );
72
        $oauthClient->setProvider(new Provider('a', 'b', 'c', 'd'));
73
        $this->vootProvider = new VootProvider(
74
            $oauthClient,
75
            'https://voot.surfconext.nl/me/groups'
76
        );
77
    }
78
79
    public function testVootCall()
80
    {
81
        $this->assertSame(
82
            [
83
                [
84
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:eduvpn',
85
                    'displayName' => 'EduVPN',
86
                ],
87
                [
88
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:eduvpn-test',
89
                    'displayName' => 'eduVPN-test',
90
                ],
91
                [
92
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:enabling_dynamic_services_2015',
93
                    'displayName' => 'Enabling Dynamic Services 2015',
94
                ],
95
                [
96
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:surfcloud_utrecht_users',
97
                    'displayName' => 'SURFcloud Utrecht users',
98
                ],
99
            ],
100
            $this->vootProvider->getGroups('foo')
101
        );
102
    }
103
104
    public function testVootCallNoToken()
105
    {
106
        $this->assertSame(
107
            [
108
            ],
109
            $this->vootProvider->getGroups('bar')
110
        );
111
    }
112
113
    public function testVootCallInvalidToken()
114
    {
115
        // first call succeeds, second call is invalid token response
116
        $this->vootProvider->getGroups('foo');
117
        $this->assertSame(
118
            [
119
            ],
120
            $this->vootProvider->getGroups('foo')
121
        );
122
    }
123
}
124