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.

InfoModuleTest::testProfileList()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 32
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\Api;
11
12
use PHPUnit_Framework_TestCase;
13
use SURFnet\VPN\Common\Config;
14
use SURFnet\VPN\Common\Http\BasicAuthenticationHook;
15
use SURFnet\VPN\Common\Http\Request;
16
use SURFnet\VPN\Common\Http\Service;
17
use SURFnet\VPN\Server\Api\InfoModule;
18
19
class InfoModuleTest extends PHPUnit_Framework_TestCase
20
{
21
    /** @var \SURFnet\VPN\Common\Http\Service */
22
    private $service;
23
24
    public function setUp()
25
    {
26
        $config = Config::fromFile(sprintf('%s/data/info_module_config.php', __DIR__));
27
28
        $this->service = new Service();
29
        $this->service->addModule(
30
            new InfoModule(
31
                $config
32
            )
33
        );
34
35
        $bearerAuthentication = new BasicAuthenticationHook(
36
            [
37
                'vpn-user-portal' => 'aabbcc',
38
            ]
39
        );
40
41
        $this->service->addBeforeHook('auth', $bearerAuthentication);
42
    }
43
44
    public function testProfileList()
45
    {
46
        $this->assertSame(
47
            [
48
                'internet' => [
49
                    'defaultGateway' => false,
50
                    'routes' => [],
51
                    'dns' => [],
52
                    'useNat' => false,
53
                    'twoFactor' => false,
54
                    'clientToClient' => false,
55
                    'listen' => '::',
56
                    'enableLog' => false,
57
                    'enableAcl' => false,
58
                    'aclGroupList' => [],
59
                    'managementIp' => '127.0.0.1',
60
                    'blockSmb' => false,
61
                    'reject4' => false,
62
                    'reject6' => false,
63
                    'vpnProtoPorts' => [
64
                        'udp/1194',
65
                        'tcp/1194',
66
                    ],
67
                    'hideProfile' => false,
68
                    'tlsCrypt' => false,
69
                    'profileNumber' => 1,
70
                    'displayName' => 'Internet Access',
71
                    'extIf' => 'eth0',
72
                    'range' => '10.0.0.0/24',
73
                    'range6' => 'fd00:4242:4242::/48',
74
                    'hostName' => 'vpn.example',
75
                ],
76
            ],
77
            $this->makeRequest(
78
                ['vpn-user-portal', 'aabbcc'],
79
                'GET',
80
                'profile_list',
81
                [],
82
                []
83
            )
84
        );
85
    }
86
87 View Code Duplication
    private function makeRequest(array $basicAuth, $requestMethod, $pathInfo, array $getData = [], array $postData = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        $response = $this->service->run(
90
            new Request(
91
                [
92
                    'SERVER_PORT' => 80,
93
                    'SERVER_NAME' => 'vpn.example',
94
                    'REQUEST_METHOD' => $requestMethod,
95
                    'SCRIPT_NAME' => '/index.php',
96
                    'REQUEST_URI' => sprintf('/%s', $pathInfo),
97
                    'PHP_AUTH_USER' => $basicAuth[0],
98
                    'PHP_AUTH_PW' => $basicAuth[1],
99
                ],
100
                $getData,
101
                $postData
102
            )
103
        );
104
105
        $responseArray = json_decode($response->getBody(), true)[$pathInfo];
106
        if ($responseArray['ok']) {
107
            if (array_key_exists('data', $responseArray)) {
108
                return $responseArray['data'];
109
            }
110
111
            return true;
112
        }
113
114
        // in case of errors...
115
        return $responseArray;
116
    }
117
}
118