Skip to content
Snippets Groups Projects
Commit 2d91732b authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Fix several issues reported by scrutinizer

parent 2ac79bde
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ use SimpleSAML\Configuration; ...@@ -9,6 +9,7 @@ use SimpleSAML\Configuration;
use SimpleSAML\Error; use SimpleSAML\Error;
use SimpleSAML\HTTP\RunnableResponse; use SimpleSAML\HTTP\RunnableResponse;
use SimpleSAML\Logger; use SimpleSAML\Logger;
use SimpleSAML\Session;
use SimpleSAML\Utils; use SimpleSAML\Utils;
use SimpleSAML\XHTML\Template; use SimpleSAML\XHTML\Template;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
...@@ -30,6 +31,9 @@ class ErrorReport ...@@ -30,6 +31,9 @@ class ErrorReport
/** @var \SimpleSAML\Configuration */ /** @var \SimpleSAML\Configuration */
protected Configuration $config; protected Configuration $config;
/** @var \SimpleSAML\Session */
protected Configuration $session;
/** /**
* Controller constructor. * Controller constructor.
...@@ -37,11 +41,13 @@ class ErrorReport ...@@ -37,11 +41,13 @@ class ErrorReport
* It initializes the global configuration for the controllers implemented here. * It initializes the global configuration for the controllers implemented here.
* *
* @param \SimpleSAML\Configuration $config The configuration to use by the controllers. * @param \SimpleSAML\Configuration $config The configuration to use by the controllers.
* @param \SimpleSAML\Session $config The session to use by the controllers.
*/ */
public function __construct( public function __construct(
Configuration $config Configuration $config
) { ) {
$this->config = $config; $this->config = $config;
$this->session = $session;
} }
...@@ -66,10 +72,10 @@ class ErrorReport ...@@ -66,10 +72,10 @@ class ErrorReport
throw new Error\Exception('Invalid reportID'); throw new Error\Exception('Invalid reportID');
} }
$data = null;
try { try {
$data = $this->session->getData('core:errorreport', $reportId); $data = $this->session->getData('core:errorreport', $reportId);
} catch (Exception $e) { } catch (Exception $e) {
$data = null;
Logger::error('Error loading error report data: ' . var_export($e->getMessage(), true)); Logger::error('Error loading error report data: ' . var_export($e->getMessage(), true));
} }
...@@ -82,7 +88,7 @@ class ErrorReport ...@@ -82,7 +88,7 @@ class ErrorReport
'referer' => 'not set', 'referer' => 'not set',
]; ];
if (isset($session)) { if (isset($this->session)) {
$data['trackId'] = $session->getTrackID(); $data['trackId'] = $session->getTrackID();
} }
} }
......
...@@ -129,14 +129,12 @@ class Cron ...@@ -129,14 +129,12 @@ class Cron
{ {
$configKey = $this->cronconfig->getOptionalString('key', 'secret'); $configKey = $this->cronconfig->getOptionalString('key', 'secret');
if ($key !== $configKey) { if ($key !== $configKey) {
Logger::error('Cron - Wrong key provided. Cron will not run.'); throw new Error\Exception('Cron - Wrong key provided. Cron will not run.');
exit;
} }
$cron = new \SimpleSAML\Module\cron\Cron(); $cron = new \SimpleSAML\Module\cron\Cron();
if (!$cron->isValidTag($tag)) { if (!$cron->isValidTag($tag)) {
Logger::error('Cron - Illegal tag [' . $tag . '].'); throw new Error\Exception(sprintf('Cron - Illegal tag [%s].', $tag));
exit;
} }
$httpUtils = new Utils\HTTP(); $httpUtils = new Utils\HTTP();
......
...@@ -137,6 +137,5 @@ class WebBrowserSingleSignOn ...@@ -137,6 +137,5 @@ class WebBrowserSingleSignOn
} catch (UnsupportedBindingException $e) { } catch (UnsupportedBindingException $e) {
throw new Error\Error('SSOPARAMS', $e, 400); throw new Error\Error('SSOPARAMS', $e, 400);
} }
Assert::true(false);
} }
} }
...@@ -247,7 +247,6 @@ class Error extends Exception ...@@ -247,7 +247,6 @@ class Error extends Exception
) { ) {
// enable error reporting // enable error reporting
$httpUtils = new Utils\HTTP(); $httpUtils = new Utils\HTTP();
$baseurl = $httpUtils->getBaseURL();
$data['errorReportAddress'] = Module::getModuleURL('core/errorReport'); $data['errorReportAddress'] = Module::getModuleURL('core/errorReport');
} }
......
...@@ -9,6 +9,7 @@ use SimpleSAML\Configuration; ...@@ -9,6 +9,7 @@ use SimpleSAML\Configuration;
use SimpleSAML\Error; use SimpleSAML\Error;
use SimpleSAML\HTTP\RunnableResponse; use SimpleSAML\HTTP\RunnableResponse;
use SimpleSAML\Module\core\Controller; use SimpleSAML\Module\core\Controller;
use SimpleSAML\Session;
use SimpleSAML\XHTML\Template; use SimpleSAML\XHTML\Template;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
...@@ -23,6 +24,9 @@ class ErrorReportTest extends TestCase ...@@ -23,6 +24,9 @@ class ErrorReportTest extends TestCase
/** @var \SimpleSAML\Configuration */ /** @var \SimpleSAML\Configuration */
protected Configuration $config; protected Configuration $config;
/** @var \SimpleSAML\Session */
protected Session $session;
/** /**
* Set up for each test. * Set up for each test.
...@@ -41,6 +45,8 @@ class ErrorReportTest extends TestCase ...@@ -41,6 +45,8 @@ class ErrorReportTest extends TestCase
); );
Configuration::setPreLoadedConfig($this->config, 'config.php'); Configuration::setPreLoadedConfig($this->config, 'config.php');
$this->session = Session::getSessionFromRequest();
} }
...@@ -54,7 +60,7 @@ class ErrorReportTest extends TestCase ...@@ -54,7 +60,7 @@ class ErrorReportTest extends TestCase
'GET', 'GET',
); );
$c = new Controller\ErrorReport($this->config); $c = new Controller\ErrorReport($this->config, $this->session);
$response = $c->main($request); $response = $c->main($request);
...@@ -74,7 +80,7 @@ class ErrorReportTest extends TestCase ...@@ -74,7 +80,7 @@ class ErrorReportTest extends TestCase
['reportId' => 'abc123'], ['reportId' => 'abc123'],
); );
$c = new Controller\ErrorReport($this->config); $c = new Controller\ErrorReport($this->config, $this->session);
$this->expectException(Error\Exception::class); $this->expectException(Error\Exception::class);
$this->expectExceptionMessage('Invalid reportID'); $this->expectExceptionMessage('Invalid reportID');
...@@ -98,7 +104,7 @@ class ErrorReportTest extends TestCase ...@@ -98,7 +104,7 @@ class ErrorReportTest extends TestCase
], ],
); );
$c = new Controller\ErrorReport($this->config); $c = new Controller\ErrorReport($this->config, $this->session);
$response = $c->main($request); $response = $c->main($request);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment