Skip to content
Snippets Groups Projects
Unverified Commit d684e5d5 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst Committed by GitHub
Browse files

Merge pull request #754 from simplesamlphp/feature/replace-deprecated-create_function

Replace deprecated create_function
parents a886c26d efb27479
No related branches found
No related tags found
No related merge requests found
...@@ -53,9 +53,13 @@ try { ...@@ -53,9 +53,13 @@ try {
$pgtiouxml = "\n<cas:proxyGrantingTicket>$pgtiou</cas:proxyGrantingTicket>\n"; $pgtiouxml = "\n<cas:proxyGrantingTicket>$pgtiou</cas:proxyGrantingTicket>\n";
} }
$proxiesxml = join("\n", array_map(create_function('$a', 'return "<cas:proxy>$a</cas:proxy>";'), $ticketcontent['proxies'])); $proxiesxml = join("\n", array_map(
if ($proxiesxml) $proxiesxml = "<cas:proxies>\n$proxiesxml\n</cas:proxies>\n"; function($a) { return "<cas:proxy>$a</cas:proxy>"; },
returnResponse('YES', $function, $attributes[$usernamefield][0], $dosendattributes ? $attributes : array(), $pgtiouxml.$proxiesxml); $ticketcontent['proxies']));
if ($proxiesxml) {
$proxiesxml = "<cas:proxies>\n$proxiesxml\n</cas:proxies>\n";
}
returnResponse('YES', $function, $attributes[$usernamefield][0], $dosendattributes ? $attributes : array(), $pgtiouxml.$proxiesxml);
} else { } else {
returnResponse('NO', $function); returnResponse('NO', $function);
} }
......
...@@ -48,7 +48,7 @@ class sspmod_core_Auth_Process_PHP extends SimpleSAML_Auth_ProcessingFilter ...@@ -48,7 +48,7 @@ class sspmod_core_Auth_Process_PHP extends SimpleSAML_Auth_ProcessingFilter
assert(is_array($request)); assert(is_array($request));
assert(array_key_exists('Attributes', $request)); assert(array_key_exists('Attributes', $request));
$function = create_function('&$attributes', $this->code); $function = function(&$attributes) { eval($this->code); };
$function($request['Attributes']); $function($request['Attributes']);
} }
} }
...@@ -26,12 +26,14 @@ class Test_Core_Auth_Process_PHP extends TestCase ...@@ -26,12 +26,14 @@ class Test_Core_Auth_Process_PHP extends TestCase
/** /**
* Test the configuration of the filter. * Test the configuration of the filter.
*
* @expectedException SimpleSAML_Error_Exception
*/ */
public function testInvalidConfiguration() public function testInvalidConfiguration()
{ {
$config = array(); $config = array();
$this->setExpectedException(
"SimpleSAML_Error_Exception",
"core:PHP: missing mandatory configuration option 'code'."
);
new sspmod_core_Auth_Process_PHP($config, null); new sspmod_core_Auth_Process_PHP($config, null);
} }
...@@ -43,16 +45,71 @@ class Test_Core_Auth_Process_PHP extends TestCase ...@@ -43,16 +45,71 @@ class Test_Core_Auth_Process_PHP extends TestCase
{ {
$config = array( $config = array(
'code' => ' 'code' => '
$attributes["key"] = "value"; $attributes["key"] = array("value");
', ',
); );
$request = array('Attributes' => array()); $request = array('Attributes' => array());
$expected = array( $expected = array(
'Attributes' => array( 'Attributes' => array(
'key' => 'value', 'key' => array('value'),
),
);
$this->assertEquals($expected, $this->processFilter($config, $request));
}
/**
* Check that the incoming attributes are also available after processing
*/
public function testPreserveIncomingAttributes()
{
$config = array(
'code' => '
$attributes["orig2"] = array("value0");
',
);
$request = array(
'Attributes' => array(
'orig1' => array('value1', 'value2'),
'orig2' => array('value3'),
'orig3' => array('value4')
)
);
$expected = array(
'Attributes' => array(
'orig1' => array('value1', 'value2'),
'orig2' => array('value0'),
'orig3' => array('value4')
), ),
); );
$this->assertEquals($expected, $this->processFilter($config, $request)); $this->assertEquals($expected, $this->processFilter($config, $request));
} }
/**
* Check that throwing an Exception inside the PHP code of the
* filter (a documented use case) works.
*/
public function testThrowExceptionFromFilter()
{
$config = array(
'code' => '
if (empty($attributes["uid"])) {
throw new Exception("Missing uid attribute.");
}
$attributes["uid"][0] = strtoupper($attributes["uid"][0]);
',
);
$request = array(
'Attributes' => array(
'orig1' => array('value1', 'value2'),
)
);
$this->setExpectedException(
"Exception",
"Missing uid attribute."
);
$this->processFilter($config, $request);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment