-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from OpenConext/feature/test-environment-adju…
…stments Test environment adjustments
- Loading branch information
Showing
5 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
# Use this service definition file to override services and parameters in the test environment. | ||
# For example to mock certain services, or override a password for test. | ||
|
||
# Use this service definition file to override services in the test environment. For example to mock certain services | ||
parameters: | ||
middleware_credentials_password: secret | ||
|
||
services: | ||
surfnet_stepup_self_service_self_service.service.sms_second_factor: | ||
class: Surfnet\StepupSelfService\SelfServiceBundle\Tests\TestDouble\Service\SmsSecondFactorService | ||
class: Surfnet\StepupSelfService\SelfServiceBundle\Tests\TestDouble\Service\SmsSecondFactorService | ||
arguments: | ||
- "@surfnet_stepup_self_service_self_service.service.command" | ||
|
||
|
||
# The middleware client bundle guzzle client is overloaded to be able to pass the testcookie to the ensure MW is | ||
# loaded in test mode. This way people setting the testcookie in prod will not switch their mw api into testmode | ||
# resulting in 500 errors. | ||
surfnet_stepup_middleware_client.guzzle.api: | ||
public: false | ||
class: GuzzleHttp\Client | ||
factory: ['Surfnet\StepupSelfService\SelfServiceBundle\Tests\TestDouble\Factory\GuzzleApiFactory', createApiGuzzleClient] | ||
arguments: | ||
- "%middleware_url_api%" | ||
- "%middleware_credentials_username%" | ||
- "%middleware_credentials_password%" | ||
|
||
surfnet_stepup_middleware_client.guzzle.commands: | ||
public: false | ||
class: GuzzleHttp\Client | ||
factory: ['Surfnet\StepupSelfService\SelfServiceBundle\Tests\TestDouble\Factory\GuzzleApiFactory', createCommandGuzzleClient] | ||
arguments: | ||
- "%middleware_url_command_api%" |
87 changes: 87 additions & 0 deletions
87
...Surfnet/StepupSelfService/SelfServiceBundle/Tests/TestDouble/Factory/GuzzleApiFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2018 SURFnet bv | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Surfnet\StepupSelfService\SelfServiceBundle\Tests\TestDouble\Factory; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Cookie\CookieJar; | ||
|
||
/** | ||
* This factory builds replacements for the Guzzle clients that are normally provided by the middleware bundle. The | ||
* added extra in this factory is that the testcookie is added to the configuration. | ||
*/ | ||
class GuzzleApiFactory | ||
{ | ||
/** | ||
* @param $apiUri | ||
* @param $username | ||
* @param $password | ||
* @return Client | ||
* | ||
* @see \Surfnet\StepupMiddlewareClientBundle\DependencyInjection\SurfnetStepupMiddlewareClientExtension::configureMiddlewareReadApiClient | ||
*/ | ||
public static function createApiGuzzleClient($apiUri, $username, $password) | ||
{ | ||
$arguments = [ | ||
'base_uri' => $apiUri, | ||
'auth' => [ | ||
$username, | ||
$password, | ||
'basic', | ||
], | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
], | ||
'cookies' => self::makeCookieJar($apiUri), | ||
]; | ||
|
||
return new Client($arguments); | ||
} | ||
|
||
/** | ||
* @param $apiUri | ||
* @return Client | ||
* | ||
* @see \Surfnet\StepupMiddlewareClientBundle\DependencyInjection\SurfnetStepupMiddlewareClientExtension::configureMiddlewareCommandApiUrl | ||
*/ | ||
public static function createCommandGuzzleClient($apiUri) | ||
{ | ||
return new Client( | ||
[ | ||
'base_uri' => $apiUri, | ||
'cookies' => self::makeCookieJar($apiUri), | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @param string $uri | ||
* @return CookieJar | ||
*/ | ||
private static function makeCookieJar($uri) | ||
{ | ||
$cookieDomain = parse_url($uri, PHP_URL_HOST); | ||
|
||
return CookieJar::fromArray( | ||
[ | ||
'testcookie' => 'testcookie', | ||
], | ||
$cookieDomain | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters