Skip to content
Snippets Groups Projects
Commit 617bbdd9 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst
Browse files

Add more testing scenarios for core:PHP authproc

parent 99b9c69b
No related branches found
No related tags found
No related merge requests found
......@@ -26,12 +26,14 @@ class Test_Core_Auth_Process_PHP extends TestCase
/**
* Test the configuration of the filter.
*
* @expectedException SimpleSAML_Error_Exception
*/
public function testInvalidConfiguration()
{
$config = array();
$this->setExpectedException(
"SimpleSAML_Error_Exception",
"core:PHP: missing mandatory configuration option 'code'."
);
new sspmod_core_Auth_Process_PHP($config, null);
}
......@@ -43,16 +45,71 @@ class Test_Core_Auth_Process_PHP extends TestCase
{
$config = array(
'code' => '
$attributes["key"] = "value";
$attributes["key"] = array("value");
',
);
$request = array('Attributes' => array());
$expected = 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));
}
/**
* 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