|
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
|
|
|
|