Release 2.26 (#5189)

* bring back deprecated methods
* bump packages
* fix SAML redirect
* config flag for break times
* use class constant instead of string in attributes
* throw if all tags were not found - fixes #4792
This commit is contained in:
Kevin Papst
2024-12-05 10:42:07 +01:00
committed by GitHub
parent 70741eebfd
commit 82a3b99a31
39 changed files with 437 additions and 397 deletions

View File

@@ -15,6 +15,7 @@ use App\Saml\Security\SamlAuthenticationSuccessHandler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Http\HttpUtils;
/**
@@ -22,19 +23,9 @@ use Symfony\Component\Security\Http\HttpUtils;
*/
class SamlAuthenticationSuccessHandlerTest extends TestCase
{
public function testWithAlwaysUseDefaultTargetPath(): void
{
$httpUtils = new HttpUtils($this->getUrlGenerator());
$handler = new SamlAuthenticationSuccessHandler($httpUtils, ['always_use_default_target_path' => true]);
$defaultTargetPath = $httpUtils->generateUri($this->getRequest('/sso/login'), $this->getOption($handler, 'default_target_path', '/'));
$response = $handler->onAuthenticationSuccess($this->getRequest('/login', 'http://localhost/relayed'), $this->getSamlToken());
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertTrue($response->isRedirect($defaultTargetPath));
}
public function testRelayState(): void
{
$handler = new SamlAuthenticationSuccessHandler(new HttpUtils($this->getUrlGenerator()), ['always_use_default_target_path' => false]);
$handler = new SamlAuthenticationSuccessHandler(new HttpUtils($this->getUrlGenerator()));
$response = $handler->onAuthenticationSuccess($this->getRequest('/sso/login', 'http://localhost/relayed'), $this->getSamlToken());
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertTrue($response->isRedirect('http://localhost/relayed'));
@@ -43,8 +34,8 @@ class SamlAuthenticationSuccessHandlerTest extends TestCase
public function testWithoutRelayState(): void
{
$httpUtils = new HttpUtils($this->getUrlGenerator());
$handler = new SamlAuthenticationSuccessHandler($httpUtils, ['always_use_default_target_path' => false]);
$defaultTargetPath = $httpUtils->generateUri($this->getRequest('/sso/login'), $this->getOption($handler, 'default_target_path', '/'));
$handler = new SamlAuthenticationSuccessHandler($httpUtils);
$defaultTargetPath = $httpUtils->generateUri($this->getRequest('/sso/login'), '/');
$response = $handler->onAuthenticationSuccess($this->getRequest(), $this->getSamlToken());
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertTrue($response->isRedirect($defaultTargetPath));
@@ -53,16 +44,16 @@ class SamlAuthenticationSuccessHandlerTest extends TestCase
public function testRelayStateLoop(): void
{
$httpUtils = new HttpUtils($this->getUrlGenerator());
$handler = new SamlAuthenticationSuccessHandler($httpUtils, ['always_use_default_target_path' => false]);
$loginPath = $httpUtils->generateUri($this->getRequest('/sso/login'), $this->getOption($handler, 'login_path', '/login'));
$handler = new SamlAuthenticationSuccessHandler($httpUtils);
$loginPath = $httpUtils->generateUri($this->getRequest('/sso/login'), '/login');
$response = $handler->onAuthenticationSuccess($this->getRequest($loginPath), $this->getSamlToken());
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertTrue(!$response->isRedirect($loginPath));
}
private function getUrlGenerator()
private function getUrlGenerator(): UrlGeneratorInterface
{
$urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock();
$urlGenerator = $this->getMockBuilder(UrlGeneratorInterface::class)->getMock();
$urlGenerator
->expects($this->any())
->method('generate')
@@ -74,7 +65,7 @@ class SamlAuthenticationSuccessHandlerTest extends TestCase
return $urlGenerator;
}
private function getRequest($path = '/', $relayState = null)
private function getRequest(string $path = '/', ?string $relayState = null): Request
{
$params = [];
if (null !== $relayState) {
@@ -84,7 +75,7 @@ class SamlAuthenticationSuccessHandlerTest extends TestCase
return Request::create($path, 'get', $params);
}
private function getSamlToken()
private function getSamlToken(): SamlToken
{
$user = new User();
$user->setUserIdentifier('admin');
@@ -94,17 +85,4 @@ class SamlAuthenticationSuccessHandlerTest extends TestCase
return $token;
}
private function getOption($handler, $name, $default = null)
{
$reflection = new \ReflectionObject($handler);
$options = $reflection->getProperty('options');
$options->setAccessible(true);
$arr = $options->getValue($handler);
if (!\is_array($arr) || !isset($arr[$name])) {
return $default;
}
return $arr[$name];
}
}