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 ( d962fa...c70e52 )
by François
02:00
created

VootProviderTest::testVootCallInvalidToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 1
f 1
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\Acl\Provider;
20
21
use GuzzleHttp\Client;
22
use GuzzleHttp\Message\Response;
23
use GuzzleHttp\Subscriber\Mock;
24
use PDO;
25
use PHPUnit_Framework_TestCase;
26
use SURFnet\VPN\Common\Config;
27
use SURFnet\VPN\Server\Storage;
28
29
class VootProviderTest extends PHPUnit_Framework_TestCase
30
{
31
    /** @var VootProvider */
32
    private $vootProvider;
33
34
    public function setUp()
35
    {
36
        $client = new Client();
37
        $mock = new Mock(
38
            [
39
                file_get_contents(sprintf('%s/data/response.json', __DIR__)),
40
                file_get_contents(sprintf('%s/data/response_invalid_token.json', __DIR__)),
41
            ]
42
        );
43
        $client->getEmitter()->attach($mock);
44
45
        $random = $this->getMockBuilder('SURFnet\VPN\Common\RandomInterface')->getMock();
46
        $random->method('get')->will($this->onConsecutiveCalls('random_1', 'random_2'));
47
48
        $storage = new Storage(
49
            new PDO('sqlite::memory:'),
50
            $random
51
        );
52
        $storage->init();
53
        $storage->setVootToken('foo', 'abcdef');
54
55
        $this->vootProvider = new VootProvider(
56
            new Config(['apiUrl' => 'https://voot.surfconext.nl/me/groups']),
57
            $storage,
58
            $client
59
        );
60
    }
61
62
    public function testVootCall()
63
    {
64
        $this->assertSame(
65
            [
66
                [
67
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:eduvpn',
68
                    'displayName' => 'EduVPN',
69
                ],
70
                [
71
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:eduvpn-test',
72
                    'displayName' => 'eduVPN-test',
73
                ],
74
                [
75
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:enabling_dynamic_services_2015',
76
                    'displayName' => 'Enabling Dynamic Services 2015',
77
                ],
78
                [
79
                    'id' => 'urn:collab:group:surfteams.nl:nl:surfnet:diensten:surfcloud_utrecht_users',
80
                    'displayName' => 'SURFcloud Utrecht users',
81
                ],
82
            ],
83
            $this->vootProvider->getGroups('foo')
84
        );
85
    }
86
87
    public function testVootCallNoToken()
88
    {
89
        $this->assertSame(
90
            [
91
            ],
92
            $this->vootProvider->getGroups('bar')
93
        );
94
    }
95
96
    public function testVootCallInvalidToken()
97
    {
98
        // first call succeeds, second call is invalid token response
99
        $this->vootProvider->getGroups('foo');
100
        $this->assertSame(
101
            [
102
            ],
103
            $this->vootProvider->getGroups('foo')
104
        );
105
    }
106
}
107