|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\Test\Module\discopower; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use ReflectionClass; |
|
9
|
|
|
use SAML2\Constants; |
|
10
|
|
|
use SimpleSAML\Configuration; |
|
11
|
|
|
use SimpleSAML\Metadata\MetaDataStorageHandler; |
|
12
|
|
|
use SimpleSAML\Module\discopower\PowerIdPDisco; |
|
13
|
|
|
|
|
14
|
|
|
class PowerIdPDiscoTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var \SimpleSAML\Module\discopower\PowerIdPDisco */ |
|
17
|
|
|
private static PowerIdPDisco $discoHandler; |
|
18
|
|
|
|
|
19
|
|
|
/** @var array */ |
|
20
|
|
|
private static array $idpList; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function setUpBeforeClass(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$config = Configuration::loadFromArray([ |
|
28
|
|
|
'module.enable' => ['discopower' => true], |
|
29
|
|
|
'metadata.sources' => [ |
|
30
|
|
|
['type' => 'flatfile', 'directory' => __DIR__ . '/test-metadata'], |
|
31
|
|
|
], |
|
32
|
|
|
], '[ARRAY]', 'simplesaml'); |
|
33
|
|
|
Configuration::setPreLoadedConfig($config, 'config.php'); |
|
34
|
|
|
|
|
35
|
|
|
$discoConfig = Configuration::loadFromArray([ |
|
36
|
|
|
'defaulttab' => 0, |
|
37
|
|
|
'taborder' => ['B', 'A'], |
|
38
|
|
|
], '[ARRAY]', 'module_discopower'); |
|
39
|
|
|
Configuration::setPreLoadedConfig($discoConfig, 'module_discopower.php'); |
|
40
|
|
|
|
|
41
|
|
|
/* spoof the request*/ |
|
42
|
|
|
$_GET['entityID'] = 'https://sp01.example.net/sp'; |
|
43
|
|
|
$_GET['return'] = 'https://sp01.example.net/simplesaml/module.php/saml/sp/discoresp.php'; |
|
44
|
|
|
$_GET['returnIDParam'] = 'idpentityid'; |
|
45
|
|
|
$_SERVER['SERVER_NAME'] = 'sp01.example.net'; |
|
46
|
|
|
$_SERVER['REQUEST_URI'] = '/simplesaml/module.php/discopower/disco.php'; |
|
47
|
|
|
|
|
48
|
|
|
self::$discoHandler = new PowerIdPDisco( |
|
49
|
|
|
['saml20-idp-remote'], |
|
50
|
|
|
'poweridpdisco' |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
self::$idpList = MetaDataStorageHandler::getMetadataHandler()->getList('saml20-idp-remote'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @covers \SimpleSAML\Module\discopower\PowerIdPDisco |
|
58
|
|
|
* @covers \SimpleSAML\Module\discopower\PowerIdPDisco::__construct |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testPowerIdPDisco(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->assertInstanceOf(PowerIdPDisco::class, self::$discoHandler); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @covers \SimpleSAML\Module\discopower\PowerIdPDisco::getIdPList |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testGetIdPList(): void |
|
69
|
|
|
{ |
|
70
|
|
|
$refl = new ReflectionClass(self::$discoHandler); |
|
71
|
|
|
$getIdPList = $refl->getMethod('getIdPList'); |
|
72
|
|
|
$getIdPList->setAccessible(true); |
|
73
|
|
|
$idpList = $getIdPList->invoke(self::$discoHandler); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals(self::$idpList, $idpList); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @covers \SimpleSAML\Module\discopower\PowerIdPDisco::idplistStructured |
|
80
|
|
|
* @covers \SimpleSAML\Module\discopower\PowerIdPDisco::getIdPList |
|
81
|
|
|
* @covers \SimpleSAML\Module\discopower\PowerIdPDisco::mcmp |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testIdplistStructured(): void |
|
84
|
|
|
{ |
|
85
|
|
|
$refl = new ReflectionClass(self::$discoHandler); |
|
86
|
|
|
$idplistStructured = $refl->getMethod('idplistStructured'); |
|
87
|
|
|
$idplistStructured->setAccessible(true); |
|
88
|
|
|
$idpList = $idplistStructured->invokeArgs(self::$discoHandler, [self::$idpList]); |
|
89
|
|
|
|
|
90
|
|
|
$expected = [ |
|
91
|
|
|
'B' => [ |
|
92
|
|
|
'https://idp04.example.org' => [ |
|
93
|
|
|
'name' => ['en' => 'IdP 04'], |
|
94
|
|
|
'tags' => ['A', 'B'], |
|
95
|
|
|
'entityid' => 'https://idp04.example.org', |
|
96
|
|
|
'UIInfo' => ['Keywords' => ['en' => ['aap','noot','mies']]], |
|
97
|
|
|
], |
|
98
|
|
|
'https://idp06.example.org' => [ |
|
99
|
|
|
'name' => ['en' => 'IdP 06'], |
|
100
|
|
|
'tags' => ['B'], |
|
101
|
|
|
'entityid' => 'https://idp06.example.org', |
|
102
|
|
|
'UIInfo' => ['Keywords' => ['fr' => ['singue','noix','mies'], 'de' => ['Affe', 'Nuss', 'mies']]], |
|
103
|
|
|
], |
|
104
|
|
|
'https://idp05.example.org' => [ |
|
105
|
|
|
'tags' => ['B'], |
|
106
|
|
|
'entityid' => 'https://idp05.example.org' |
|
107
|
|
|
], |
|
108
|
|
|
], |
|
109
|
|
|
'A' => [ |
|
110
|
|
|
'https://idp03.example.org' => [ |
|
111
|
|
|
'name' => ['en' => 'IdP 03'], |
|
112
|
|
|
'discopower.weight' => 100, |
|
113
|
|
|
'tags' => ['A'], |
|
114
|
|
|
'entityid' => 'https://idp03.example.org' |
|
115
|
|
|
], |
|
116
|
|
|
'https://idp02.example.org' => [ |
|
117
|
|
|
'name' => ['en' => 'IdP 02'], |
|
118
|
|
|
'tags' => ['A'], |
|
119
|
|
|
'entityid' => 'https://idp02.example.org' |
|
120
|
|
|
], |
|
121
|
|
|
'https://idp04.example.org' => [ |
|
122
|
|
|
'name' => ['en' => 'IdP 04'], |
|
123
|
|
|
'tags' => ['A','B',], |
|
124
|
|
|
'entityid' => 'https://idp04.example.org', |
|
125
|
|
|
'UIInfo' => ['Keywords' => ['en' => ['aap','noot','mies']]], |
|
126
|
|
|
], |
|
127
|
|
|
'https://idp01.example.org' => [ |
|
128
|
|
|
'name' => ['en' => 'IdP 01'], |
|
129
|
|
|
'discopower.weight' => 1, |
|
130
|
|
|
'tags' => ['A'], |
|
131
|
|
|
'entityid' => 'https://idp01.example.org' |
|
132
|
|
|
], |
|
133
|
|
|
], |
|
134
|
|
|
]; |
|
135
|
|
|
$this->assertEquals($expected, $idpList); |
|
136
|
|
|
$this->assertEquals($expected['A'], $idpList['A']); |
|
137
|
|
|
$this->assertEquals($expected['B'], $idpList['B']); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @covers \SimpleSAML\Module\discopower\PowerIdPDisco::mcmp |
|
142
|
|
|
*/ |
|
143
|
|
|
public function testmcmp(): void |
|
144
|
|
|
{ |
|
145
|
|
|
$this->assertEquals( |
|
146
|
|
|
-1, |
|
147
|
|
|
PowerIdPDisco::mcmp( |
|
148
|
|
|
['name' => 'B', 'entityid' => '1'], |
|
149
|
|
|
['name' => 'A', 'entityid' => '2'] |
|
150
|
|
|
), |
|
151
|
|
|
'name,name' |
|
152
|
|
|
); |
|
153
|
|
|
$this->assertEquals( |
|
154
|
|
|
-1, |
|
155
|
|
|
PowerIdPDisco::mcmp( |
|
156
|
|
|
['entityid' => '1'], |
|
157
|
|
|
['name' => 'A', 'entityid' => '2'] |
|
158
|
|
|
), |
|
159
|
|
|
'entityid,name' |
|
160
|
|
|
); |
|
161
|
|
|
$this->assertEquals( |
|
162
|
|
|
1, |
|
163
|
|
|
PowerIdPDisco::mcmp( |
|
164
|
|
|
['entityid' => '2'], |
|
165
|
|
|
['entityid' => '1'] |
|
166
|
|
|
), |
|
167
|
|
|
'entityid,entityid' |
|
168
|
|
|
); |
|
169
|
|
|
$this->assertEquals( |
|
170
|
|
|
-1, |
|
171
|
|
|
PowerIdPDisco::mcmp( |
|
172
|
|
|
['name' => 'B', 'entityid' => '1', 'discopower.weight' => 100], |
|
173
|
|
|
['name' => 'A', 'entityid' => '2'] |
|
174
|
|
|
), |
|
175
|
|
|
'weight,name' |
|
176
|
|
|
); |
|
177
|
|
|
$this->assertEquals( |
|
178
|
|
|
1, |
|
179
|
|
|
PowerIdPDisco::mcmp( |
|
180
|
|
|
['name' => 'B', 'entityid' => '1', 'discopower.weight' => 100], |
|
181
|
|
|
['name' => 'A', 'entityid' => '2', 'discopower.weight' => 200] |
|
182
|
|
|
), |
|
183
|
|
|
'weight,weight' |
|
184
|
|
|
); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|