Skip to content

Commit

Permalink
Fixes cardinality auth filter unit tests (#860) (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
unt01d authored and thijskh committed May 28, 2018
1 parent 2cdae6b commit 8ef7191
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 42 deletions.
211 changes: 211 additions & 0 deletions lib/SimpleSAML/Utils/HttpAdapter.php
@@ -0,0 +1,211 @@
<?php

namespace SimpleSAML\Utils;

/**
* Provides a non-static wrapper for the HTTP utility class.
*
* @package SimpleSAML\Utils
*/
class HttpAdapter
{
/**
* @see HTTP::getServerHTTPS()
*/
public function getServerHTTPS()
{
return HTTP::getServerHTTPS();
}

/**
* @see HTTP::getServerPort()
*/
public function getServerPort()
{
return HTTP::getServerPort();
}

/**
* @see HTTP::addURLParameters()
*/
public function addURLParameters($url, $parameters)
{
return HTTP::addURLParameters($url, $parameters);
}

/**
* @see HTTP::checkSessionCookie()
*/
public function checkSessionCookie($retryURL = null)
{
HTTP::checkSessionCookie($retryURL);
}

/**
* @see HTTP::checkURLAllowed()
*/
public function checkURLAllowed($url, array $trustedSites = null)
{
return HTTP::checkURLAllowed($url, $trustedSites);
}

/**
* @see HTTP::fetch()
*/
public function fetch($url, $context = array(), $getHeaders = false)
{
return HTTP::fetch($url, $context, $getHeaders);
}

/**
* @see HTTP::getAcceptLanguage()
*/
public function getAcceptLanguage()
{
return HTTP::getAcceptLanguage();
}

/**
* @see HTTP::guessBasePath()
*/
public function guessBasePath()
{
return HTTP::guessBasePath();
}

/**
* @see HTTP::getBaseURL()
*/
public function getBaseURL()
{
return HTTP::getBaseURL();
}

/**
* @see HTTP::getFirstPathElement()
*/
public function getFirstPathElement($trailingslash = true)
{
return HTTP::getFirstPathElement($trailingslash);
}

/**
* @see HTTP::getPOSTRedirectURL()
*/
public function getPOSTRedirectURL($destination, $data)
{
return HTTP::getPOSTRedirectURL($destination, $data);
}

/**
* @see HTTP::getSelfHost()
*/
public function getSelfHost()
{
return HTTP::getSelfHost();
}

/**
* @see HTTP::getSelfHostWithNonStandardPort()
*/
public function getSelfHostWithNonStandardPort()
{
return HTTP::getSelfHostWithNonStandardPort();
}

/**
* @see HTTP::getSelfHostWithPath()
*/
public function getSelfHostWithPath()
{
return HTTP::getSelfHostWithPath();
}

/**
* @see HTTP::getSelfURL()
*/
public function getSelfURL()
{
return HTTP::getSelfURL();
}

/**
* @see HTTP::getSelfURLHost()
*/
public function getSelfURLHost()
{
return HTTP::getSelfURLHost();
}

/**
* @see HTTP::getSelfURLNoQuery()
*/
public function getSelfURLNoQuery()
{
return HTTP::getSelfURLNoQuery();
}

/**
* @see HTTP::isHTTPS()
*/
public function isHTTPS()
{
return HTTP::isHTTPS();
}

/**
* @see HTTP::normalizeURL()
*/
public function normalizeURL($url)
{
return HTTP::normalizeURL($url);
}

/**
* @see HTTP::parseQueryString()
*/
public function parseQueryString($query_string)
{
return HTTP::parseQueryString($query_string);
}

/**
* @see HTTP::redirectTrustedURL()
*/
public function redirectTrustedURL($url, $parameters = array())
{
HTTP::redirectTrustedURL($url, $parameters);
}

/**
* @see HTTP::redirectUntrustedURL()
*/
public function redirectUntrustedURL($url, $parameters = array())
{
HTTP::redirectUntrustedURL($url, $parameters);
}

/**
* @see HTTP::resolveURL()
*/
public function resolveURL($url, $base = null)
{
return HTTP::resolveURL($url, $base);
}

/**
* @see HTTP::setCookie()
*/
public function setCookie($name, $value, $params = null, $throw = true)
{
HTTP::setCookie($name, $value, $params, $throw);
}

/**
* @see HTTP::submitPOSTData()
*/
public function submitPOSTData($destination, $data)
{
HTTP::submitPOSTData($destination, $data);
}
}
12 changes: 10 additions & 2 deletions modules/core/lib/Auth/Process/Cardinality.php
@@ -1,5 +1,7 @@
<?php

use SimpleSAML\Utils\HTTPAdapter;

/**
* Filter to ensure correct cardinality of attributes
*
Expand All @@ -14,18 +16,24 @@ class sspmod_core_Auth_Process_Cardinality extends SimpleSAML_Auth_ProcessingFil
/** @var array Entities that should be ignored */
private $ignoreEntities = array();

/** @var HTTP */
private $http;

/**
* Initialize this filter, parse configuration.
*
* @param array $config Configuration information about this filter.
* @param mixed $reserved For future use.
* @param HTTPAdapter $http HTTP utility service (handles redirects).
* @throws SimpleSAML_Error_Exception
*/
public function __construct($config, $reserved)
public function __construct($config, $reserved, HTTPAdapter $http = null)
{
parent::__construct($config, $reserved);
assert(is_array($config));

$this->http = $http ?: new HTTPAdapter();

foreach ($config as $attribute => $rules) {
if ($attribute === '%ignoreEntities') {
$this->ignoreEntities = $config['%ignoreEntities'];
Expand Down Expand Up @@ -157,7 +165,7 @@ public function process(&$request)
if (array_key_exists('core:cardinality:errorAttributes', $request)) {
$id = SimpleSAML_Auth_State::saveState($request, 'core:cardinality');
$url = SimpleSAML\Module::getModuleURL('core/cardinality_error.php');
\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
$this->http->redirectTrustedURL($url, array('StateId' => $id));
return;
}
}
Expand Down
12 changes: 10 additions & 2 deletions modules/core/lib/Auth/Process/CardinalitySingle.php
@@ -1,5 +1,7 @@
<?php

use SimpleSAML\Utils\HttpAdapter;

/**
* Filter to ensure correct cardinality of single-valued attributes
*
Expand All @@ -26,17 +28,23 @@ class sspmod_core_Auth_Process_CardinalitySingle extends SimpleSAML_Auth_Process
/** @var array Entities that should be ignored */
private $ignoreEntities = array();

/** @var HTTP */
private $http;

/**
* Initialize this filter, parse configuration.
*
* @param array $config Configuration information about this filter.
* @param mixed $reserved For future use.
* @param HTTPAdapter $http HTTP utility service (handles redirects).
*/
public function __construct($config, $reserved)
public function __construct($config, $reserved, HTTPAdapter $http = null)
{
parent::__construct($config, $reserved);
assert(is_array($config));

$this->http = $http ?: new HTTPAdapter();

if (array_key_exists('singleValued', $config)) {
$this->singleValued = $config['singleValued'];
}
Expand Down Expand Up @@ -102,7 +110,7 @@ public function process(&$request)
if (array_key_exists('core:cardinality:errorAttributes', $request)) {
$id = SimpleSAML_Auth_State::saveState($request, 'core:cardinality');
$url = SimpleSAML\Module::getModuleURL('core/cardinality_error.php');
\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
$this->http->redirectTrustedURL($url, array('StateId' => $id));
return;
}
}
Expand Down

0 comments on commit 8ef7191

Please sign in to comment.