Skip to content

Commit

Permalink
Merge pull request #157 from OpenConext/feature/test-environment-adju…
Browse files Browse the repository at this point in the history
…stments

Test environment adjustments
  • Loading branch information
MKodde committed Oct 16, 2018
2 parents 236628b + 7d5c127 commit f2cce28
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Develop

**Improvments for testing**
* Ensure middleware API is used in test mode #157
* Use 'shared' certificates and private keys when in test mode #157

## 2.10.1
**Bugfixes**
* Prevent form loading issue #155
Expand Down
12 changes: 12 additions & 0 deletions app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@ nelmio_security:
img: [ self, 'data:' ]
script: [ self, unsafe-inline ]
style: [ self, unsafe-inline ]

surfnet_saml:
hosted:
service_provider:
public_key: /vagrant/deploy/tests/behat/fixtures/test_public_key.crt
private_key: /vagrant/deploy/tests/behat/fixtures/test_private_key.key
metadata:
public_key: /vagrant/deploy/tests/behat/fixtures/test_public_key.crt
private_key: /vagrant/deploy/tests/behat/fixtures/test_private_key.key
remote:
identity_provider:
certificate: MIIC6jCCAdICCQC9cRx5wiwWOjANBgkqhkiG9w0BAQsFADA3MRwwGgYDVQQDDBNTZWxmU2VydmljZSBTQU1MIFNQMRcwFQYDVQQKDA5EZXZlbG9wbWVudCBWTTAeFw0xODA3MzAxMjMwNDdaFw0yMzA3MjkxMjMwNDdaMDcxHDAaBgNVBAMME1NlbGZTZXJ2aWNlIFNBTUwgU1AxFzAVBgNVBAoMDkRldmVsb3BtZW50IFZNMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqhbI0Xy682DuvWchg6FYnI+DNwLXef2XExM4YVRBaMMsOZ3rBtQUTMSqYan6SK/BOEXLs0rNiJjyM0dn+F98wg3fv5zIADlvfk3LBVdcGsrpVfFUWtSa73yMgbROy8/RJADbUJE/HUB3ZmdjdiuD2Cui2aoWwT2HR8ukJwmoxiu45IWFPbqPQ7/1mH644JPOWTPLTv4OGGLQo8MNrP1oRCiZ0IEL4CQeGOOju5rfIJ0bTVm0UmelT4hGaqZovBMwXp3QV41akJ7UEMEBK2YMnLQy47Xuzi7aTDhJlvHcJ8mfH2NbjRh7hJoACVRTvQloxajgkr1iGMiWiiqT0e+YYwIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBwZ0gRHvR8B8KivrXrhWNL9uLvWhEAH7OiDqo+fywkBp5KEuDJcbbvEPftHunSAGylg7M2xKuBIGamFpp74WDJccrtZ1jJ4qqnacUDRQrTLqqMZKqGpFOU0xjKkSxSGRuMtGN9/7er/TeonjQ0XBvjYvTomy3b5aCLVWRvEfKu2g1sDd8uhr62RY/HfMgidEt7LHDolkCVg+6JzY3OTcgeHga3cvYObOYPplxw1YPq5+BqqxaUW4nfb5DtK33bZBYMeyV6BZtSggc5Z/19aPx/s0bf6ySTUyB3lRqe5d3etCns4bGidORCl/6EZiXwVcPvmYmxYXqmuNWfps7isUvo
29 changes: 27 additions & 2 deletions app/config/services_test.yml
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%"
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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function fromSecondFactorType($type)
private function __construct($type)
{
if (!isset($this->supportedTypes[$type])) {
throw InvalidArgumentException::invalidType('valid second factor type', 'type', $type);
throw InvalidArgumentException::invalidType('Invalid second factor type', 'type', $type);
}
$this->type = $type;
}
Expand Down

0 comments on commit f2cce28

Please sign in to comment.