Skip to content
Snippets Groups Projects
Commit 5aa7c187 authored by Patrick Radtke's avatar Patrick Radtke Committed by Thijs Kinkhorst
Browse files

Ignore invalid hook names

Sometimes we patch or edit a hook to meet our specific needs.
Somtimes this leaves behind a file like FILENAME.orig. The hook
detection login still runs these other files, making for confusing
debugging issues. Use a stricter match on what makes a valid hook name
to avoid these issues.
parent 3768f63f
No related branches found
No related tags found
No related merge requests found
...@@ -496,7 +496,7 @@ class Module ...@@ -496,7 +496,7 @@ class Module
continue; continue;
} }
if (!preg_match('/hook_(\w+)\.php/', $file, $matches)) { if (!preg_match('/^hook_(\w+)\.php$/', $file, $matches)) {
continue; continue;
} }
$hook_name = $matches[1]; $hook_name = $matches[1];
......
...@@ -112,4 +112,26 @@ class ModuleTest extends TestCase ...@@ -112,4 +112,26 @@ class ModuleTest extends TestCase
'\SimpleSAML\Auth\ProcessingFilter' '\SimpleSAML\Auth\ProcessingFilter'
)); ));
} }
/**
* Test for SimpleSAML\Module::getModuleHooks(). It covers happy path.
*/
public function testGetModuleHooks(): void
{
$hooks = Module::getModuleHooks('saml');
$this->assertArrayHasKey('metadata_hosted', $hooks);
$this->assertEquals('saml_hook_metadata_hosted', $hooks['metadata_hosted']['func']);
$expectedFile = dirname(__DIR__, 3) . '/modules/saml/hooks/hook_metadata_hosted.php';
$this->assertEquals($expectedFile, $hooks['metadata_hosted']['file']);
}
/**
* Test for SimpleSAML\Module::getModuleHooks(). It covers invalid hook names
*/
public function testGetModuleHooksIgnoresInvalidHooks(): void
{
$hooks = Module::getModuleHooks('../tests/modules/unittest');
$this->assertArrayHasKey('valid', $hooks, 'hooks=' . var_export($hooks, true));
$this->assertCount(1, $hooks, "Invalid hooks should be ignored");
}
} }
For some unit tests we need a module that has a specific setup or issues.
<?php
// Hook detection should not load this file since it does not conform to the hook naming scheme
<?php
use SimpleSAML\Assert\Assert;
use SimpleSAML\Auth;
/**
* Hook to for use with unit tests
*
* @param array &$data Some data
*/
function unittest_hook_valid(array &$data)
{
$data['summary'][] = 'success';
}
<?php
// Hook detection should not load this file since it does not conform to the hook naming scheme
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