fix deprecations (move same controller) (#2440)

This commit is contained in:
Kevin Papst
2021-03-16 14:06:15 +01:00
committed by GitHub
parent 75e62b800c
commit 16e8e8a5e5
11 changed files with 128 additions and 34 deletions

View File

@@ -91,7 +91,11 @@ class SystemConfigurationTest extends TestCase
]
],
'weekends' => true,
]
],
'saml' => [
'activate' => false,
'title' => 'Fantastic OAuth login'
],
];
}
@@ -135,14 +139,17 @@ class SystemConfigurationTest extends TestCase
$this->assertEquals('RUB', $sut->find('defaults.customer.currency'));
$this->assertTrue($sut->find('timesheet.rules.allow_future_times'));
$this->assertEquals(7, $sut->find('timesheet.active_entries.hard_limit'));
$this->assertFalse($sut->isSamlActive());
}
public function testDefaultWithMixedConfigs()
{
$sut = $this->getSut($this->getDefaultSettings(), [
(new Configuration())->setName('timesheet.rules.allow_future_times')->setValue(''),
(new Configuration())->setName('saml.activate')->setValue(true),
]);
$this->assertFalse($sut->find('timesheet.rules.allow_future_times'));
$this->assertTrue($sut->isSamlActive());
}
public function testUnknownConfigs()

View File

@@ -7,15 +7,18 @@
* file that was distributed with this source code.
*/
namespace App\Tests\Saml\Controller;
namespace App\Tests\Controller\Auth;
use App\Saml\Controller\SamlController;
use App\Configuration\SystemConfiguration;
use App\Controller\Auth\SamlController;
use App\Tests\Configuration\TestConfigLoader;
use App\Tests\Mocks\Saml\SamlAuthFactory;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Xml;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Security;
/**
@@ -23,18 +26,44 @@ use Symfony\Component\Security\Core\Security;
*/
class SamlControllerTest extends TestCase
{
/**
* @param array $settings
* @param array $loaderSettings
* @return SystemConfiguration
*/
protected function getSystemConfigurationMock(array $settings, array $loaderSettings = [])
{
$loader = new TestConfigLoader($loaderSettings);
return new SystemConfiguration($loader, $settings);
}
protected function getDefaultSettings(bool $activated = true)
{
return [
'saml' => [
'activate' => $activated,
]
];
}
protected function getAuth()
{
return (new SamlAuthFactory($this))->create();
}
protected function getSystemConfiguration(bool $activated = true)
{
return $this->getSystemConfigurationMock($this->getDefaultSettings($activated), []);
}
public function testAssertionConsumerServiceAction()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('You must configure the check path in your firewall.');
$oauth = $this->getAuth();
$sut = new SamlController($oauth);
$sut = new SamlController($oauth, $this->getSystemConfiguration());
$sut->assertionConsumerServiceAction();
}
@@ -44,7 +73,7 @@ class SamlControllerTest extends TestCase
$this->expectExceptionMessage('You must configure the logout path in your firewall.');
$oauth = $this->getAuth();
$sut = new SamlController($oauth);
$sut = new SamlController($oauth, $this->getSystemConfiguration());
$sut->logoutAction();
}
@@ -75,7 +104,7 @@ class SamlControllerTest extends TestCase
EOD;
$oauth = $this->getAuth();
$sut = new SamlController($oauth);
$sut = new SamlController($oauth, $this->getSystemConfiguration());
$result = $sut->metadataAction();
self::assertInstanceOf(Response::class, $result);
@@ -98,7 +127,43 @@ EOD;
$request->attributes->set(Security::AUTHENTICATION_ERROR, new \Exception('My test error'));
$oauth = $this->getAuth();
$sut = new SamlController($oauth);
$sut = new SamlController($oauth, $this->getSystemConfiguration());
$sut->loginAction($request);
}
public function testLoginActionThrowsExceptionOnDisabledSaml()
{
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('SAML deactivated');
$sut = new SamlController($this->getAuth(), $this->getSystemConfiguration(false));
$sut->loginAction(new Request());
}
public function testMetadataActionThrowsExceptionOnDisabledSaml()
{
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('SAML deactivated');
$sut = new SamlController($this->getAuth(), $this->getSystemConfiguration(false));
$sut->metadataAction();
}
public function testLogoutActionThrowsExceptionOnDisabledSaml()
{
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('SAML deactivated');
$sut = new SamlController($this->getAuth(), $this->getSystemConfiguration(false));
$sut->logoutAction();
}
public function testAcsActionThrowsExceptionOnDisabledSaml()
{
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('SAML deactivated');
$sut = new SamlController($this->getAuth(), $this->getSystemConfiguration(false));
$sut->assertionConsumerServiceAction();
}
}

View File

@@ -12,6 +12,8 @@ namespace App\Tests\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetSubscriber;
/**
* @covers \App\EventSubscriber\Actions\AbstractActionsSubscriber
* @covers \App\EventSubscriber\Actions\AbstractTimesheetSubscriber
* @covers \App\EventSubscriber\Actions\TimesheetSubscriber
*/
class TimesheetSubscriberTest extends AbstractActionsSubscriberTest

View File

@@ -12,6 +12,8 @@ namespace App\Tests\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetTeamMultiUpdateSubscriber;
/**
* @covers \App\EventSubscriber\Actions\AbstractActionsSubscriber
* @covers \App\EventSubscriber\Actions\TimesheetTeamMultiUpdateSubscriber
* @covers \App\EventSubscriber\Actions\TimesheetTeamMultiUpdateSubscriber
*/
class TimesheetTeamMultiUpdateSubscriberTest extends AbstractActionsSubscriberTest

View File

@@ -12,6 +12,8 @@ namespace App\Tests\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetsSubscriber;
/**
* @covers \App\EventSubscriber\Actions\AbstractActionsSubscriber
* @covers \App\EventSubscriber\Actions\AbstractTimesheetsSubscriber
* @covers \App\EventSubscriber\Actions\TimesheetsSubscriber
*/
class TimesheetsSubscriberTest extends AbstractActionsSubscriberTest

View File

@@ -12,6 +12,8 @@ namespace App\Tests\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetsTeamSubscriber;
/**
* @covers \App\EventSubscriber\Actions\AbstractActionsSubscriber
* @covers \App\EventSubscriber\Actions\AbstractTimesheetsSubscriber
* @covers \App\EventSubscriber\Actions\TimesheetsTeamSubscriber
*/
class TimesheetsTeamSubscriberTest extends AbstractActionsSubscriberTest