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 ( 6c4153...d181b6 )
by François
03:10
created

ConnectionsModuleTest::testConnect()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 14
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\Api;
20
21
use PDO;
22
use PHPUnit_Framework_TestCase;
23
use SURFnet\VPN\Server\Storage;
24
use SURFnet\VPN\Common\Http\BasicAuthenticationHook;
25
use SURFnet\VPN\Common\Http\Request;
26
use SURFnet\VPN\Common\Http\Service;
27
use SURFnet\VPN\Common\Config;
28
use SURFnet\VPN\Server\Acl\Provider\StaticProvider;
29
30
class ConnectionsModuleTest extends PHPUnit_Framework_TestCase
31
{
32
    /** @var \SURFnet\VPN\Common\Http\Service */
33
    private $service;
34
35
    public function setUp()
36
    {
37
        $random = $this->getMockBuilder('SURFnet\VPN\Common\RandomInterface')->getMock();
38
        $random->method('get')->will($this->onConsecutiveCalls('random_1', 'random_2'));
39
40
        $storage = new Storage(
41
            new PDO('sqlite::memory:'),
42
            $random
43
        );
44
        $storage->init();
45
        $storage->addCertificate('foo', 'abcd1234', 'ABCD1234', 12345678, 23456789);
46
        $storage->clientConnect('internet', 'abcd1234', '10.10.10.10', 'fd00:4242:4242:4242::', 12345678);
47
48
        $config = Config::fromFile(sprintf('%s/data/config.yaml', __DIR__));
49
50
        $groupProviders = [
51
            new StaticProvider(
52
                new Config(
53
                    $config->v('groupProviders', 'StaticProvider')
54
                )
55
            ),
56
        ];
57
58
        $this->service = new Service();
59
        $this->service->addModule(
60
            new ConnectionsModule(
61
                $config,
62
                $storage,
63
                $groupProviders
64
            )
65
        );
66
67
        $bearerAuthentication = new BasicAuthenticationHook(
68
            [
69
                'vpn-server-node' => 'aabbcc',
70
            ]
71
        );
72
73
        $this->service->addBeforeHook('auth', $bearerAuthentication);
74
    }
75
76
    public function testConnect()
77
    {
78
        $this->assertSame(
79
            [
80
                'data' => [
81
                    'connect' => [
82
                        'ok' => true,
83
                    ],
84
                ],
85
            ],
86
            $this->makeRequest(
87
                ['vpn-server-node', 'aabbcc'],
88
                'POST',
89
                '/connect',
90
                [],
91
                [
92
                    'profile_id' => 'internet',
93
                    'common_name' => 'abcd1234',
94
                    'ip4' => '10.10.10.10',
95
                    'ip6' => 'fd00:4242:4242:4242::',
96
                    'connected_at' => 12345678,
97
                ]
98
            )
99
        );
100
    }
101
102
    public function testConnectInAcl()
103
    {
104
        $this->assertSame(
105
            [
106
                'data' => [
107
                    'connect' => [
108
                        'ok' => true,
109
                    ],
110
                ],
111
            ],
112
            $this->makeRequest(
113
                ['vpn-server-node', 'aabbcc'],
114
                'POST',
115
                '/connect',
116
                [],
117
                [
118
                    'profile_id' => 'acl',
119
                    'common_name' => 'abcd1234',
120
                    'ip4' => '10.10.10.10',
121
                    'ip6' => 'fd00:4242:4242:4242::',
122
                    'connected_at' => 12345678,
123
                ]
124
            )
125
        );
126
    }
127
128 View Code Duplication
    public function testConnectNotInAcl()
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...
129
    {
130
        $this->assertSame(
131
            [
132
                'data' => [
133
                    'connect' => [
134
                        'ok' => false,
135
                        'error' => 'user not in ACL',
136
                    ],
137
                ],
138
            ],
139
            $this->makeRequest(
140
                ['vpn-server-node', 'aabbcc'],
141
                'POST',
142
                '/connect',
143
                [],
144
                [
145
                    'profile_id' => 'acl2',
146
                    'common_name' => 'abcd1234',
147
                    'ip4' => '10.10.10.10',
148
                    'ip6' => 'fd00:4242:4242:4242::',
149
                    'connected_at' => 12345678,
150
                ]
151
            )
152
        );
153
    }
154
155 View Code Duplication
    public function testDisconnect()
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...
156
    {
157
        $this->assertSame(
158
            [
159
                'data' => [
160
                    'disconnect' => [
161
                        'ok' => true,
162
                    ],
163
                ],
164
            ],
165
            $this->makeRequest(
166
                ['vpn-server-node', 'aabbcc'],
167
                'POST',
168
                '/disconnect',
169
                [],
170
                [
171
                    'profile_id' => 'internet',
172
                    'common_name' => 'abcd1234',
173
                    'ip4' => '10.10.10.10',
174
                    'ip6' => 'fd00:4242:4242:4242::',
175
                    'connected_at' => 12345678,
176
                    'disconnected_at' => 23456789,
177
                    'bytes_transferred' => 2222222,
178
                ]
179
            )
180
        );
181
    }
182
183 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...
184
    {
185
        $response = $this->service->run(
186
            new Request(
187
                [
188
                    'SERVER_PORT' => 80,
189
                    'SERVER_NAME' => 'vpn.example',
190
                    'REQUEST_METHOD' => $requestMethod,
191
                    'PATH_INFO' => $pathInfo,
192
                    'REQUEST_URI' => $pathInfo,
193
                    'PHP_AUTH_USER' => $basicAuth[0],
194
                    'PHP_AUTH_PW' => $basicAuth[1],
195
                ],
196
                $getData,
197
                $postData
198
            )
199
        );
200
201
        return json_decode($response->getBody(), true);
202
    }
203
}
204