|
1 | 1 | <?php |
| 2 | + |
2 | 3 | /** |
3 | 4 | * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors |
4 | 5 | * SPDX-License-Identifier: AGPL-3.0-or-later |
@@ -133,6 +134,41 @@ public function theSettingIsSetTo(string $settingName, string $value): void { |
133 | 134 | ) |
134 | 135 | ); |
135 | 136 | } |
| 137 | + /** |
| 138 | + * @Given The config :configName is :value |
| 139 | + */ |
| 140 | + public function theConfigIs(string $configName, string $value): void { |
| 141 | + shell_exec( |
| 142 | + sprintf( |
| 143 | + '%s %s saml:config:set --"%s"="%s" %d', |
| 144 | + PHP_BINARY, |
| 145 | + __DIR__ . '/../../../../../../occ', |
| 146 | + $configName, |
| 147 | + $value, |
| 148 | + 1 |
| 149 | + ) |
| 150 | + ); |
| 151 | + } |
| 152 | + /** |
| 153 | + * @Then The config :configName should be :expectedValue |
| 154 | + */ |
| 155 | + public function theConfigShouldBe(string $configName, string $expectedValue): void { |
| 156 | + $json = shell_exec( |
| 157 | + sprintf( |
| 158 | + '%s %s saml:config:get --providerId %d --output json', |
| 159 | + PHP_BINARY, |
| 160 | + __DIR__ . '/../../../../../../occ', |
| 161 | + 1 |
| 162 | + ) |
| 163 | + ); |
| 164 | + $json = json_decode($json); |
| 165 | + $value = $json->{'1'}->$configName; |
| 166 | + if ($value !== $expectedValue) { |
| 167 | + throw new UnexpectedValueException( |
| 168 | + sprintf('Config value for %s is %s, but expected was %s', $configName, $value, $expectedValue) |
| 169 | + ); |
| 170 | + } |
| 171 | + } |
136 | 172 |
|
137 | 173 | /** |
138 | 174 | * @Then The setting :settingName is currently :expectedValue |
@@ -189,6 +225,24 @@ public function iSendAGetRequestTo($url) { |
189 | 225 | ] |
190 | 226 | ); |
191 | 227 | } |
| 228 | + /** |
| 229 | + * @When I send a GET request with query params to :url |
| 230 | + */ |
| 231 | + public function iSendAGetRequestWithQueryParamsTo($url) { |
| 232 | + $url = $url . '&idp=1'; |
| 233 | + $query = parse_url($url)['query']; |
| 234 | + $url = str_replace('?' . $query, '', $url); |
| 235 | + $this->response = $this->client->request( |
| 236 | + 'GET', |
| 237 | + $url, |
| 238 | + [ |
| 239 | + 'headers' => [ |
| 240 | + 'Accept' => 'text/html', |
| 241 | + ], |
| 242 | + 'query' => $query |
| 243 | + ] |
| 244 | + ); |
| 245 | + } |
192 | 246 |
|
193 | 247 | /** |
194 | 248 | * @Then I should be redirected to :targetUrl |
@@ -223,15 +277,65 @@ public function iShouldBeRedirectedTo($targetUrl) { |
223 | 277 | } |
224 | 278 | } |
225 | 279 | } |
| 280 | + /** |
| 281 | + * @Then I should be redirected to :targetUrl with query params |
| 282 | + * |
| 283 | + * @param string $targetUrl |
| 284 | + * @throws InvalidArgumentException |
| 285 | + */ |
| 286 | + public function iShouldBeRedirectedToWithQueryParams($targetUrl) { |
| 287 | + $redirectHeader = $this->response->getHeader('X-Guzzle-Redirect-History'); |
| 288 | + $firstUrl = $redirectHeader[0]; |
| 289 | + $firstUrlParsed = parse_url($firstUrl); |
| 290 | + $targetUrl = parse_url($targetUrl); |
| 291 | + $paramsToCheck = [ |
| 292 | + 'scheme', |
| 293 | + 'host', |
| 294 | + 'path', |
| 295 | + 'query' |
| 296 | + ]; |
| 297 | + |
| 298 | + // Remove everything after a comma in the URL since cookies are passed there |
| 299 | + [$firstUrlParsed['path']] = explode(';', $firstUrlParsed['path']); |
| 300 | + $passthroughParams = $targetUrl['query']; |
| 301 | + foreach ($paramsToCheck as $param) { |
| 302 | + if ($param == 'query') { |
| 303 | + foreach (explode('&', $passthroughParams) as $passthrough) { |
| 304 | + if (!str_contains($firstUrl, $passthrough)) { |
| 305 | + throw new InvalidArgumentException( |
| 306 | + sprintf( |
| 307 | + 'Expected to find %s for parameter %s', |
| 308 | + $passthrough, |
| 309 | + $param, |
| 310 | + ) |
| 311 | + ); |
| 312 | + } |
| 313 | + } |
| 314 | + } else { |
| 315 | + if ($targetUrl[$param] !== $firstUrlParsed[$param]) { |
| 316 | + throw new InvalidArgumentException( |
| 317 | + sprintf( |
| 318 | + 'Expected %s for parameter %s, got %s', |
| 319 | + $targetUrl[$param], |
| 320 | + $param, |
| 321 | + $firstUrlParsed[$param] |
| 322 | + ) |
| 323 | + ); |
| 324 | + } |
| 325 | + } |
| 326 | + } |
| 327 | + } |
226 | 328 |
|
227 | 329 | /** |
228 | 330 | * @Then I send a POST request to :url with the following data |
229 | 331 | * |
230 | 332 | * @param string $url |
231 | 333 | * @param TableNode $table |
232 | 334 | */ |
233 | | - public function iSendAPostRequestToWithTheFollowingData($url, |
234 | | - TableNode $table) { |
| 335 | + public function iSendAPostRequestToWithTheFollowingData( |
| 336 | + $url, |
| 337 | + TableNode $table, |
| 338 | + ) { |
235 | 339 | $postParams = $table->getColumnsHash()[0]; |
236 | 340 | $this->response = $this->client->request( |
237 | 341 | 'POST', |
@@ -351,7 +455,8 @@ public function theGroupHasExactlyTheMembers(string $group, string $memberList): |
351 | 455 | 'format' => 'json', |
352 | 456 | ], |
353 | 457 | 'auth' => [ |
354 | | - 'admin', 'admin' |
| 458 | + 'admin', |
| 459 | + 'admin' |
355 | 460 | ], |
356 | 461 | 'cookies' => '', |
357 | 462 | ] |
|
0 commit comments