Refactor authentication system (#2602)
Make auth configuration available via UI, remove FOSUserBundle and SAML-Bundle dependency
This commit is contained in:
@@ -11,12 +11,14 @@ namespace App\Tests\Saml\Logout;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Saml\Logout\SamlLogoutHandler;
|
||||
use App\Saml\SamlAuth;
|
||||
use Hslavich\OneloginSamlBundle\Security\Authentication\Token\SamlToken;
|
||||
use App\Saml\SamlAuthFactory;
|
||||
use App\Saml\Token\SamlToken;
|
||||
use OneLogin\Saml2\Auth;
|
||||
use OneLogin\Saml2\Error;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
|
||||
/**
|
||||
* @covers \App\Saml\Logout\SamlLogoutHandler
|
||||
@@ -25,7 +27,7 @@ class SamlLogoutHandlerTest extends TestCase
|
||||
{
|
||||
public function testLogout()
|
||||
{
|
||||
$auth = $this->getMockBuilder(SamlAuth::class)->disableOriginalConstructor()->getMock();
|
||||
$auth = $this->getMockBuilder(Auth::class)->disableOriginalConstructor()->getMock();
|
||||
$auth->expects($this->once())->method('processSLO')->willThrowException(new Error('blub'));
|
||||
$auth->expects($this->once())->method('getSLOurl')->willReturn('');
|
||||
|
||||
@@ -33,13 +35,33 @@ class SamlLogoutHandlerTest extends TestCase
|
||||
$response = new Response();
|
||||
$token = new SamlToken([]);
|
||||
|
||||
$sut = new SamlLogoutHandler($auth);
|
||||
$factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock();
|
||||
$factory->expects($this->once())->method('create')->willReturn($auth);
|
||||
|
||||
$sut = new SamlLogoutHandler($factory);
|
||||
$sut->logout($request, $response, $token);
|
||||
}
|
||||
|
||||
public function testLogoutWithWrongTokenWillNotCallMethods()
|
||||
{
|
||||
$auth = $this->getMockBuilder(Auth::class)->disableOriginalConstructor()->getMock();
|
||||
$auth->expects($this->never())->method('processSLO');
|
||||
$auth->expects($this->never())->method('getSLOurl');
|
||||
|
||||
$request = new Request();
|
||||
$response = new Response();
|
||||
$token = new UsernamePasswordToken(new User(), [], 'test');
|
||||
|
||||
$factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock();
|
||||
$factory->expects($this->never())->method('create');
|
||||
|
||||
$sut = new SamlLogoutHandler($factory);
|
||||
$sut->logout($request, $response, $token);
|
||||
}
|
||||
|
||||
public function testLogoutWithLogoutUrl()
|
||||
{
|
||||
$auth = $this->getMockBuilder(SamlAuth::class)->disableOriginalConstructor()->getMock();
|
||||
$auth = $this->getMockBuilder(Auth::class)->disableOriginalConstructor()->getMock();
|
||||
$auth->expects($this->once())->method('processSLO')->willThrowException(new Error('blub'));
|
||||
$auth->expects($this->once())->method('getSLOurl')->willReturn('/logout');
|
||||
$auth->expects($this->once())->method('logout')->willReturnCallback(function () {
|
||||
@@ -56,7 +78,10 @@ class SamlLogoutHandlerTest extends TestCase
|
||||
$token->setUser((new User())->setUsername('tony'));
|
||||
$token->setAttribute('sessionIndex', 'foo-bar');
|
||||
|
||||
$sut = new SamlLogoutHandler($auth);
|
||||
$factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock();
|
||||
$factory->expects($this->once())->method('create')->willReturn($auth);
|
||||
|
||||
$sut = new SamlLogoutHandler($factory);
|
||||
$sut->logout($request, $response, $token);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user