diff --git a/modules/core/lib/Auth/Process/AttributeValueMap.php b/modules/core/lib/Auth/Process/AttributeValueMap.php index 231f2d327ea7611d8179048ca43bd0dd4008e78f..4f6ce073507ea9a8c811be4ffcd1084af40b44ab 100644 --- a/modules/core/lib/Auth/Process/AttributeValueMap.php +++ b/modules/core/lib/Auth/Process/AttributeValueMap.php @@ -4,9 +4,10 @@ * Filter to create target attribute based on value(s) in source attribute * * @author Martin van Es, m7 - * @package simpleSAMLphp + * @package SimpleSAMLphp */ -class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_ProcessingFilter { +class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_ProcessingFilter +{ /** * The attributename we should assign values to (ie target) @@ -24,27 +25,29 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process private $values = array(); /** - * Wether $sourceattribute should be kept + * Whether $sourceattribute should be kept */ private $keep = false; /** - * Wether $target attribute values should be replaced by new values + * Whether $target attribute values should be replaced by new values */ private $replace = false; /** - * Initialize this filter. - * - * @param array $config Configuration information about this filter. - * @param mixed $reserved For future use. + * Initialize this filter. + * + * @param array $config Configuration information about this filter. + * @param mixed $reserved For future use. + * @throws SimpleSAML_Error_Exception If the configuration is not valid. */ - public function __construct($config, $reserved) { + public function __construct($config, $reserved) + { parent::__construct($config, $reserved); assert('is_array($config)'); - /* Validate configuration. */ + // validate configuration foreach ($config as $name => $value) { if (is_int($name)) { // check if this is an option @@ -58,17 +61,17 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process continue; } - // Set targetattribute + // set targetattribute if ($name === 'targetattribute') { $this->targetattribute = $value; } - // Set sourceattribute + // set sourceattribute if ($name === 'sourceattribute') { $this->sourceattribute = $value; } - // Set values + // set values if ($name === 'values') { $this->values = $value; } @@ -77,11 +80,12 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process /** - * Apply filter to add groups attribute. - * - * @param array &$request The current request - */ - public function process(&$request) { + * Apply filter. + * + * @param array &$request The current request + */ + public function process(&$request) + { SimpleSAML_Logger::debug('AttributeValueMap - process'); assert('is_array($request)'); @@ -109,7 +113,10 @@ class sspmod_core_Auth_Process_AttributeValueMap extends SimpleSAML_Auth_Process if ($this->replace or !@is_array($attributes[$this->targetattribute])) { $attributes[$this->targetattribute] = $targetvalues; } else { - $attributes[$this->targetattribute] = array_unique(array_merge($attributes[$this->targetattribute], $targetvalues)); + $attributes[$this->targetattribute] = array_unique(array_merge( + $attributes[$this->targetattribute], + $targetvalues + )); } } diff --git a/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php b/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php index 426f2bad080007cc1c87dafd9bb0c3c051995701..09686377fb129f58602a45f0f92a2bfb13250eff 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php @@ -13,16 +13,19 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas * @param array $request The request state. * @return array The state array after processing. */ - private static function processFilter(array $config, array $request) { + private static function processFilter(array $config, array $request) + { $filter = new sspmod_core_Auth_Process_AttributeValueMap($config, null); $filter->process($request); return $request; } + /** * Test the most basic functionality. */ - public function testBasic() { + public function testBasic() + { $config = array( 'sourceattribute' => 'memberOf', 'targetattribute' => 'eduPersonAffiliation', @@ -45,10 +48,12 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas $this->assertEquals($attributes['eduPersonAffiliation'], array('member')); } + /** * Test basic functionality, remove duplicates */ - public function testNoDuplicates() { + public function testNoDuplicates() + { $config = array( 'sourceattribute' => 'memberOf', 'targetattribute' => 'eduPersonAffiliation', @@ -72,10 +77,12 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas $this->assertEquals($attributes['eduPersonAffiliation'], array('member', 'someValue')); } + /** * Test the %replace functionality. */ - public function testReplace() { + public function testReplace() + { $config = array( 'sourceattribute' => 'memberOf', 'targetattribute' => 'eduPersonAffiliation', @@ -90,7 +97,7 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas $request = array( 'Attributes' => array( 'memberOf' => array('theGroup'), - 'eduPersonAffiliation' => array('someValue'), + 'eduPersonAffiliation' => array('someValue'), ), ); $result = self::processFilter($config, $request); @@ -100,10 +107,12 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas $this->assertEquals($attributes['eduPersonAffiliation'], array('member')); } + /** * Test the %keep functionality. */ - public function testKeep() { + public function testKeep() + { $config = array( 'sourceattribute' => 'memberOf', 'targetattribute' => 'eduPersonAffiliation', @@ -118,7 +127,7 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas $request = array( 'Attributes' => array( 'memberOf' => array('theGroup'), - 'eduPersonAffiliation' => array('someValue'), + 'eduPersonAffiliation' => array('someValue'), ), ); $result = self::processFilter($config, $request); @@ -128,12 +137,14 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas $this->assertEquals($attributes['eduPersonAffiliation'], array('someValue','member')); } + /** * Test unknown flag Exception * * @expectedException Exception */ - public function testUnknownFlag() { + public function testUnknownFlag() + { $config = array( '%test', 'values' => array( @@ -147,15 +158,17 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas 'memberOf' => array('theGroup'), ), ); - $result = self::processFilter($config, $request); + self::processFilter($config, $request); } + /** * Test missing Source attribute * * @expectedException Exception */ - public function testMissingSourceAttribute() { + public function testMissingSourceAttribute() + { $config = array( 'targetattribute' => 'affiliation', 'values' => array( @@ -169,15 +182,17 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas 'memberOf' => array('theGroup'), ), ); - $result = self::processFilter($config, $request); + self::processFilter($config, $request); } + /** * Test missing Target attribute * * @expectedException Exception */ - public function testMissingTargetAttribute() { + public function testMissingTargetAttribute() + { $config = array( 'sourceattribute' => 'memberOf', 'values' => array( @@ -191,6 +206,6 @@ class Test_Core_Auth_Process_AttributeValueMap extends PHPUnit_Framework_TestCas 'memberOf' => array('theGroup'), ), ); - $result = self::processFilter($config, $request); + self::processFilter($config, $request); } }