ea6a359272
* Upd: Add Symfony 4 Compatibility #SymfonyConHackday2017 * Upd: Configure visibility of services for SF4 * Updated composer to allow Symfony 4.0 * Updated composer to allow Symfony 4.0 * PropelBundle for Symfony 4 * Upd: Travis configuration * Upd: PHP 5 not supported anymore by PHPUnit * Upd: Removing old SF version + PHPUnit correction * * Removed param that was removed in symfony/yaml afb873f * Updated format of object dumping as deprecated tags using colon symfony/yaml 38d3087 * * Added commands to console.xml as symfony no longer auto registers bundle commands * Updated two services to public * * Removed deprecated getMock calls for new createMock calls. * * Add stub for additional abstract method * * Updated schema locator test * reverted unnecessary changes to abstract command and schemal locator * Added fixtures for schema testing. * * Updated schema locator test * reverted unnecessary changes to abstract command and schemal locator * Added fixtures for schema testing. * * Removed unnecessary default for services * Updated readme to reflect symfony version support
123 lines
4.7 KiB
PHP
123 lines
4.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This file is part of the PropelBundle package.
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*
|
|
* @license MIT License
|
|
*/
|
|
|
|
namespace Propel\Bundle\PropelBundle\Tests\Model\Acl;
|
|
|
|
use Propel\Bundle\PropelBundle\Model\Acl\SecurityIdentity;
|
|
use Propel\Bundle\PropelBundle\Model\Acl\SecurityIdentityQuery;
|
|
|
|
use Symfony\Component\Security\Core\Role\Role;
|
|
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
|
|
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
|
|
|
|
use Propel\Bundle\PropelBundle\Tests\AclTestCase;
|
|
|
|
/**
|
|
* @author Toni Uebernickel <tuebernickel@gmail.com>
|
|
*/
|
|
class SecurityIdentityTest extends AclTestCase
|
|
{
|
|
public function testToAclIdentityUserWithInvalidIdentifier()
|
|
{
|
|
$identity = new SecurityIdentity();
|
|
$identity->setIdentifier('invalidIdentifier');
|
|
$identity->setUsername(true);
|
|
|
|
$this->expectException('InvalidArgumentException');
|
|
SecurityIdentity::toAclIdentity($identity);
|
|
}
|
|
|
|
public function testToAclIdentityUnknownSecurityIdentity()
|
|
{
|
|
$identity = new SecurityIdentity();
|
|
$identity->setIdentifier('invalidIdentifier');
|
|
$identity->setUsername(false);
|
|
|
|
$this->expectException('InvalidArgumentException');
|
|
SecurityIdentity::toAclIdentity($identity);
|
|
}
|
|
|
|
public function testToAclIdentityValidUser()
|
|
{
|
|
$identity = new SecurityIdentity();
|
|
$identity->setIdentifier('Propel\Bundle\PropelBundle\Tests\Fixtures\UserProxy-propel');
|
|
$identity->setUsername(true);
|
|
|
|
$secIdentity = SecurityIdentity::toAclIdentity($identity);
|
|
$this->assertInstanceOf('Symfony\Component\Security\Acl\Domain\UserSecurityIdentity', $secIdentity);
|
|
}
|
|
|
|
public function testToAclIdentityMultipleDashes()
|
|
{
|
|
$identity = new SecurityIdentity();
|
|
$identity->setIdentifier('Propel\Bundle\PropelBundle\Tests\Fixtures\UserProxy-some-username@domain.com');
|
|
$identity->setUsername(true);
|
|
|
|
$secIdentity = SecurityIdentity::toAclIdentity($identity);
|
|
$this->assertInstanceOf('Symfony\Component\Security\Acl\Domain\UserSecurityIdentity', $secIdentity);
|
|
$this->assertEquals('some-username@domain.com', $secIdentity->getUsername());
|
|
}
|
|
|
|
public function testToAclIdentityValidRole()
|
|
{
|
|
$identity = new SecurityIdentity();
|
|
$identity->setIdentifier('ROLE_ADMIN');
|
|
$identity->setUsername(false);
|
|
|
|
$secIdentity = SecurityIdentity::toAclIdentity($identity);
|
|
$this->assertInstanceOf('Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity', $secIdentity);
|
|
|
|
$identity = new SecurityIdentity();
|
|
$identity->setIdentifier('IS_AUTHENTICATED_ANONYMOUSLY');
|
|
$identity->setUsername(false);
|
|
|
|
$secIdentity = SecurityIdentity::toAclIdentity($identity);
|
|
$this->assertInstanceOf('Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity', $secIdentity);
|
|
}
|
|
|
|
public function testFromAclIdentityWithInvalid()
|
|
{
|
|
$secIdentity = $this->getMockBuilder('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface')->getMock();
|
|
|
|
$this->expectException('InvalidArgumentException');
|
|
SecurityIdentity::fromAclIdentity($secIdentity, $this->con);
|
|
}
|
|
|
|
public function testFromAclIdentityWithUser()
|
|
{
|
|
$secIdentity = new UserSecurityIdentity('propel', 'Propel\Bundle\PropelBundle\Tests\Fixtures\UserProxy');
|
|
|
|
$identity = SecurityIdentity::fromAclIdentity($secIdentity, $this->con);
|
|
|
|
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Model\Acl\SecurityIdentity', $identity);
|
|
$this->assertEquals(true, $identity->getUsername());
|
|
$this->assertEquals('Propel\Bundle\PropelBundle\Tests\Fixtures\UserProxy-propel', $identity->getIdentifier());
|
|
$this->assertGreaterThan(0, $identity->getId());
|
|
|
|
$dbEntry = SecurityIdentityQuery::create()->findPk($identity->getId());
|
|
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Model\Acl\SecurityIdentity', $dbEntry);
|
|
}
|
|
|
|
public function testFromAclIdentityWithRole()
|
|
{
|
|
$secIdentity = new RoleSecurityIdentity(new Role('ROLE_USER'));
|
|
|
|
$identity = SecurityIdentity::fromAclIdentity($secIdentity, $this->con);
|
|
|
|
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Model\Acl\SecurityIdentity', $identity);
|
|
$this->assertEquals(false, $identity->getUsername());
|
|
$this->assertEquals('ROLE_USER', $identity->getIdentifier());
|
|
$this->assertGreaterThan(0, $identity->getId());
|
|
|
|
$dbEntry = SecurityIdentityQuery::create()->findPk($identity->getId());
|
|
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Model\Acl\SecurityIdentity', $dbEntry);
|
|
}
|
|
}
|