|
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
|
|
|
namespace SURFnet\VPN\Server; |
|
19
|
|
|
|
|
20
|
|
|
use PHPUnit_Framework_TestCase; |
|
21
|
|
|
|
|
22
|
|
|
class ConnectionTest extends PHPUnit_Framework_TestCase |
|
23
|
|
|
{ |
|
24
|
|
View Code Duplication |
public function testConnect() |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
$c = new Connection(__DIR__); |
|
27
|
|
|
$c->connect( |
|
28
|
|
|
[ |
|
29
|
|
|
'INSTANCE_ID' => 'vpn.example', |
|
30
|
|
|
'POOL_ID' => 'internet', |
|
31
|
|
|
'common_name' => 'foo_xyz', |
|
32
|
|
|
'time_unix' => 1234567890, |
|
33
|
|
|
'ifconfig_pool_remote_ip' => '10.10.10.25', |
|
34
|
|
|
'ifconfig_pool_remote_ip6' => 'fd00:1234::25', |
|
35
|
|
|
] |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @expectedException \SURFnet\VPN\Server\Exception\ConnectionException |
|
41
|
|
|
* @expectedExceptionMessage client not allowed, user is disabled |
|
42
|
|
|
*/ |
|
43
|
|
View Code Duplication |
public function testDisabledUser() |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$c = new Connection(__DIR__); |
|
46
|
|
|
$c->connect( |
|
47
|
|
|
[ |
|
48
|
|
|
'INSTANCE_ID' => 'vpn.example', |
|
49
|
|
|
'POOL_ID' => 'internet', |
|
50
|
|
|
'common_name' => 'bar_xyz', |
|
51
|
|
|
'time_unix' => 1234567890, |
|
52
|
|
|
'ifconfig_pool_remote_ip' => '10.10.10.25', |
|
53
|
|
|
'ifconfig_pool_remote_ip6' => 'fd00:1234::25', |
|
54
|
|
|
] |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @expectedException \SURFnet\VPN\Server\Exception\ConnectionException |
|
60
|
|
|
* @expectedExceptionMessage client not allowed, CN is disabled |
|
61
|
|
|
*/ |
|
62
|
|
View Code Duplication |
public function testDisabledCommonName() |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
$c = new Connection(__DIR__); |
|
65
|
|
|
$c->connect( |
|
66
|
|
|
[ |
|
67
|
|
|
'INSTANCE_ID' => 'vpn.example', |
|
68
|
|
|
'POOL_ID' => 'internet', |
|
69
|
|
|
'common_name' => 'foo_disabled', |
|
70
|
|
|
'time_unix' => 1234567890, |
|
71
|
|
|
'ifconfig_pool_remote_ip' => '10.10.10.25', |
|
72
|
|
|
'ifconfig_pool_remote_ip6' => 'fd00:1234::25', |
|
73
|
|
|
] |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
public function testAclIsMember() |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
$c = new Connection(__DIR__); |
|
80
|
|
|
$c->connect( |
|
81
|
|
|
[ |
|
82
|
|
|
'INSTANCE_ID' => 'vpn.example', |
|
83
|
|
|
'POOL_ID' => 'bar', |
|
84
|
|
|
'common_name' => 'foo_xyz', |
|
85
|
|
|
'time_unix' => 1234567890, |
|
86
|
|
|
'ifconfig_pool_remote_ip' => '10.10.10.25', |
|
87
|
|
|
'ifconfig_pool_remote_ip6' => 'fd00:1234::25', |
|
88
|
|
|
] |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @expectedException \SURFnet\VPN\Server\Exception\ConnectionException |
|
94
|
|
|
* @expectedExceptionMessage client not allowed, not a member of "all" |
|
95
|
|
|
*/ |
|
96
|
|
View Code Duplication |
public function testAclIsNoMember() |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
$c = new Connection(__DIR__); |
|
99
|
|
|
$c->connect( |
|
100
|
|
|
[ |
|
101
|
|
|
'INSTANCE_ID' => 'vpn.example', |
|
102
|
|
|
'POOL_ID' => 'bar', |
|
103
|
|
|
'common_name' => 'xyz_abc', |
|
104
|
|
|
'time_unix' => 1234567890, |
|
105
|
|
|
'ifconfig_pool_remote_ip' => '10.10.10.25', |
|
106
|
|
|
'ifconfig_pool_remote_ip6' => 'fd00:1234::25', |
|
107
|
|
|
] |
|
108
|
|
|
); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
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.