. */ namespace App\Tests\Security; use App\Entity\UserSystem\User; use App\Security\EnsureSAMLUserForSAMLLoginChecker; use Hslavich\OneloginSamlBundle\Security\Http\Authenticator\Token\SamlToken; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent; use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException; class EnsureSAMLUserForSAMLLoginCheckerTest extends WebTestCase { /** @var EnsureSAMLUserForSAMLLoginChecker */ protected $service; protected function setUp(): void { self::bootKernel(); $this->service = self::getContainer()->get(EnsureSAMLUserForSAMLLoginChecker::class); } public function testOnAuthenticationSuccessFailsOnSSOLoginWithLocalUser(): void { $local_user = new User(); $saml_token = $this->createMock(SamlToken::class); $saml_token->method('getUser')->willReturn($local_user); $event = new AuthenticationSuccessEvent($saml_token); $this->expectException(CustomUserMessageAccountStatusException::class); $this->service->onAuthenticationSuccess($event); } public function testOnAuthenticationSuccessFailsOnLocalLoginWithSAMLUser(): void { $saml_user = (new User())->setSamlUser(true); $saml_token = $this->createMock(UsernamePasswordToken::class); $saml_token->method('getUser')->willReturn($saml_user); $event = new AuthenticationSuccessEvent($saml_token); $this->expectException(CustomUserMessageAccountStatusException::class); $this->service->onAuthenticationSuccess($event); } }