Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+100 -89
View File
@@ -11,17 +11,18 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Doctrine\Persistence\PropertyChangedListener;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
class AclTest extends \PHPUnit_Framework_TestCase
class AclTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
$acl = new Acl(1, $oid = new ObjectIdentity('foo', 'foo'), $permissionStrategy = new PermissionGrantingStrategy(), array(), true);
$acl = new Acl(1, $oid = new ObjectIdentity('foo', 'foo'), $permissionStrategy = new PermissionGrantingStrategy(), [], true);
$this->assertSame(1, $acl->getId());
$this->assertSame($oid, $acl->getObjectIdentity());
@@ -30,11 +31,12 @@ class AclTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getDeleteAceTests
*/
public function testDeleteAceThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'delete'.$type.'Ace'}(0);
}
@@ -49,9 +51,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl->{'insert'.$type.'Ace'}(new RoleSecurityIdentity('foo'), 2, 1);
$acl->{'insert'.$type.'Ace'}(new RoleSecurityIdentity('foo'), 3, 2);
$listener = $this->getListener(array(
$listener = $this->getListener([
$type.'Aces', 'aceOrder', 'aceOrder', $type.'Aces',
));
]);
$acl->addPropertyChangedListener($listener);
$this->assertCount(3, $acl->{'get'.$type.'Aces'}());
@@ -68,18 +70,19 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getDeleteAceTests()
{
return array(
array('class'),
array('object'),
);
return [
['class'],
['object'],
];
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getDeleteFieldAceTests
*/
public function testDeleteFieldAceThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'delete'.$type.'Ace'}('foo', 0);
}
@@ -94,9 +97,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl->{'insert'.$type.'Ace'}('foo', new RoleSecurityIdentity('foo'), 2, 1);
$acl->{'insert'.$type.'Ace'}('foo', new RoleSecurityIdentity('foo'), 3, 2);
$listener = $this->getListener(array(
$listener = $this->getListener([
$type.'Aces', 'aceOrder', 'aceOrder', $type.'Aces',
));
]);
$acl->addPropertyChangedListener($listener);
$this->assertCount(3, $acl->{'get'.$type.'Aces'}('foo'));
@@ -113,10 +116,10 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getDeleteFieldAceTests()
{
return array(
array('classField'),
array('objectField'),
);
return [
['classField'],
['objectField'],
];
}
/**
@@ -126,9 +129,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
{
$acl = $this->getAcl();
$listener = $this->getListener(array(
$listener = $this->getListener([
$property, 'aceOrder', $property, 'aceOrder', $property,
));
]);
$acl->addPropertyChangedListener($listener);
$sid = new RoleSecurityIdentity('foo');
@@ -143,21 +146,22 @@ class AclTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getInsertAceTests
*/
public function testInsertClassAceThrowsExceptionOnInvalidIndex($property, $method)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->$method(new RoleSecurityIdentity('foo'), 1, 1);
}
public function getInsertAceTests()
{
return array(
array('classAces', 'insertClassAce'),
array('objectAces', 'insertObjectAce'),
);
return [
['classAces', 'insertClassAce'],
['objectAces', 'insertObjectAce'],
];
}
/**
@@ -167,10 +171,10 @@ class AclTest extends \PHPUnit_Framework_TestCase
{
$acl = $this->getAcl();
$listener = $this->getListener(array(
$listener = $this->getListener([
$property, $property, 'aceOrder', $property,
'aceOrder', 'aceOrder', $property,
));
]);
$acl->addPropertyChangedListener($listener);
$sid = new RoleSecurityIdentity('foo');
@@ -187,35 +191,36 @@ class AclTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getInsertFieldAceTests
*/
public function testInsertClassFieldAceThrowsExceptionOnInvalidIndex($property, $method)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->$method('foo', new RoleSecurityIdentity('foo'), 1, 1);
}
public function getInsertFieldAceTests()
{
return array(
array('classFieldAces', 'insertClassFieldAce'),
array('objectFieldAces', 'insertObjectFieldAce'),
);
return [
['classFieldAces', 'insertClassFieldAce'],
['objectFieldAces', 'insertObjectFieldAce'],
];
}
public function testIsFieldGranted()
{
$sids = array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_IDDQD'));
$masks = array(1, 2, 4);
$strategy = $this->getMock('Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface');
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), $strategy, array(), true);
$sids = [new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_IDDQD')];
$masks = [1, 2, 4];
$strategy = $this->createMock('Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface');
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), $strategy, [], true);
$strategy
->expects($this->once())
->method('isFieldGranted')
->with($this->equalTo($acl), $this->equalTo('foo'), $this->equalTo($masks), $this->equalTo($sids), $this->isTrue())
->will($this->returnValue(true))
->willReturn(true)
;
$this->assertTrue($acl->isFieldGranted('foo', $masks, $sids, true));
@@ -223,16 +228,16 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function testIsGranted()
{
$sids = array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_IDDQD'));
$masks = array(1, 2, 4);
$strategy = $this->getMock('Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface');
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), $strategy, array(), true);
$sids = [new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_IDDQD')];
$masks = [1, 2, 4];
$strategy = $this->createMock('Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface');
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), $strategy, [], true);
$strategy
->expects($this->once())
->method('isGranted')
->with($this->equalTo($acl), $this->equalTo($masks), $this->equalTo($sids), $this->isTrue())
->will($this->returnValue(true))
->willReturn(true)
;
$this->assertTrue($acl->isGranted($masks, $sids, true));
@@ -243,7 +248,7 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$parentAcl = $this->getAcl();
$listener = $this->getListener(array('parentAcl'));
$listener = $this->getListener(['parentAcl']);
$acl->addPropertyChangedListener($listener);
$this->assertNull($acl->getParentAcl());
@@ -258,7 +263,7 @@ class AclTest extends \PHPUnit_Framework_TestCase
{
$acl = $this->getAcl();
$listener = $this->getListener(array('entriesInheriting'));
$listener = $this->getListener(['entriesInheriting']);
$acl->addPropertyChangedListener($listener);
$this->assertTrue($acl->isEntriesInheriting());
@@ -276,29 +281,30 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function testIsSidLoaded()
{
$acl = new Acl(1, new ObjectIdentity('1', 'foo'), new PermissionGrantingStrategy(), array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('johannes', 'Bar')), true);
$acl = new Acl(1, new ObjectIdentity('1', 'foo'), new PermissionGrantingStrategy(), [new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('johannes', 'Bar')], true);
$this->assertTrue($acl->isSidLoaded(new UserSecurityIdentity('foo', 'Foo')));
$this->assertTrue($acl->isSidLoaded(new UserSecurityIdentity('johannes', 'Bar')));
$this->assertTrue($acl->isSidLoaded(array(
$this->assertTrue($acl->isSidLoaded([
new UserSecurityIdentity('foo', 'Foo'),
new UserSecurityIdentity('johannes', 'Bar'),
)));
]));
$this->assertFalse($acl->isSidLoaded(new RoleSecurityIdentity('ROLE_FOO')));
$this->assertFalse($acl->isSidLoaded(new UserSecurityIdentity('schmittjoh@gmail.com', 'Moo')));
$this->assertFalse($acl->isSidLoaded(array(
$this->assertFalse($acl->isSidLoaded([
new UserSecurityIdentity('foo', 'Foo'),
new UserSecurityIdentity('johannes', 'Bar'),
new RoleSecurityIdentity('ROLE_FOO'),
)));
]));
}
/**
* @dataProvider getUpdateAceTests
* @expectedException \OutOfBoundsException
*/
public function testUpdateAceThrowsOutOfBoundsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'update'.$type}(0, 1);
}
@@ -311,9 +317,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$acl->{'insert'.$type}(new RoleSecurityIdentity('foo'), 1);
$listener = $this->getListener(array(
$listener = $this->getListener([
'mask', 'mask', 'strategy',
));
]);
$acl->addPropertyChangedListener($listener);
$aces = $acl->{'get'.$type.'s'}();
@@ -332,18 +338,19 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getUpdateAceTests()
{
return array(
array('classAce'),
array('objectAce'),
);
return [
['classAce'],
['objectAce'],
];
}
/**
* @dataProvider getUpdateFieldAceTests
* @expectedException \OutOfBoundsException
*/
public function testUpdateFieldAceThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'update'.$type}(0, 'foo', 1);
}
@@ -356,9 +363,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$acl->{'insert'.$type}('foo', new UserSecurityIdentity('foo', 'Foo'), 1);
$listener = $this->getListener(array(
$listener = $this->getListener([
'mask', 'mask', 'strategy',
));
]);
$acl->addPropertyChangedListener($listener);
$aces = $acl->{'get'.$type.'s'}('foo');
@@ -377,18 +384,19 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getUpdateFieldAceTests()
{
return array(
array('classFieldAce'),
array('objectFieldAce'),
);
return [
['classFieldAce'],
['objectFieldAce'],
];
}
/**
* @dataProvider getUpdateAuditingTests
* @expectedException \OutOfBoundsException
*/
public function testUpdateAuditingThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'update'.$type.'Auditing'}(0, true, false);
}
@@ -401,9 +409,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$acl->{'insert'.$type.'Ace'}(new RoleSecurityIdentity('foo'), 1);
$listener = $this->getListener(array(
$listener = $this->getListener([
'auditFailure', 'auditSuccess', 'auditFailure',
));
]);
$acl->addPropertyChangedListener($listener);
$aces = $acl->{'get'.$type.'Aces'}();
@@ -422,28 +430,30 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getUpdateAuditingTests()
{
return array(
array('class'),
array('object'),
);
return [
['class'],
['object'],
];
}
/**
* @expectedException \InvalidArgumentException
* @dataProvider getUpdateFieldAuditingTests
*/
public function testUpdateFieldAuditingThrowsExceptionOnInvalidField($type)
{
$this->expectException(\InvalidArgumentException::class);
$acl = $this->getAcl();
$acl->{'update'.$type.'Auditing'}(0, 'foo', true, true);
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getUpdateFieldAuditingTests
*/
public function testUpdateFieldAuditingThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'insert'.$type.'Ace'}('foo', new RoleSecurityIdentity('foo'), 1);
$acl->{'update'.$type.'Auditing'}(1, 'foo', true, false);
@@ -457,9 +467,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$acl->{'insert'.$type.'Ace'}('foo', new RoleSecurityIdentity('foo'), 1);
$listener = $this->getListener(array(
$listener = $this->getListener([
'auditSuccess', 'auditSuccess', 'auditFailure',
));
]);
$acl->addPropertyChangedListener($listener);
$aces = $acl->{'get'.$type.'Aces'}('foo');
@@ -478,36 +488,37 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getUpdateFieldAuditingTests()
{
return array(
array('classField'),
array('objectField'),
);
return [
['classField'],
['objectField'],
];
}
protected function getListener($expectedChanges)
{
$aceProperties = array('aceOrder', 'mask', 'strategy', 'auditSuccess', 'auditFailure');
$aceProperties = ['aceOrder', 'mask', 'strategy', 'auditSuccess', 'auditFailure'];
$listener = $this->getMock('Doctrine\Common\PropertyChangedListener');
$arguments = [];
$listener = $this->createMock(PropertyChangedListener::class);
foreach ($expectedChanges as $index => $property) {
if (in_array($property, $aceProperties)) {
if (\in_array($property, $aceProperties)) {
$class = 'Symfony\Component\Security\Acl\Domain\Entry';
} else {
$class = 'Symfony\Component\Security\Acl\Domain\Acl';
}
$listener
->expects($this->at($index))
->method('propertyChanged')
->with($this->isInstanceOf($class), $this->equalTo($property))
;
$arguments[] = [$this->isInstanceOf($class), $this->equalTo($property)];
}
$listener
->method('propertyChanged')
->withConsecutive(...$arguments)
;
return $listener;
}
protected function getAcl()
{
return new Acl(1, new ObjectIdentity(1, 'foo'), new PermissionGrantingStrategy(), array(), true);
return new Acl(1, new ObjectIdentity(1, 'foo'), new PermissionGrantingStrategy(), [], true);
}
}
+10 -10
View File
@@ -11,7 +11,7 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
class AuditLoggerTest extends \PHPUnit_Framework_TestCase
class AuditLoggerTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider getTestLogData
@@ -25,7 +25,7 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase
$ace
->expects($this->once())
->method('isAuditSuccess')
->will($this->returnValue($audit))
->willReturn($audit)
;
$ace
@@ -41,7 +41,7 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase
$ace
->expects($this->once())
->method('isAuditFailure')
->will($this->returnValue($audit))
->willReturn($audit)
;
}
@@ -63,17 +63,17 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase
public function getTestLogData()
{
return array(
array(true, false),
array(true, true),
array(false, false),
array(false, true),
);
return [
[true, false],
[true, true],
[false, false],
[false, true],
];
}
protected function getEntry()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface');
}
protected function getLogger()
@@ -11,33 +11,34 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Doctrine\Common\Cache\ArrayCache;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Domain\DoctrineAclCache;
use Doctrine\Common\Cache\ArrayCache;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
class DoctrineAclCacheTest extends \PHPUnit_Framework_TestCase
class DoctrineAclCacheTest extends \PHPUnit\Framework\TestCase
{
protected $permissionGrantingStrategy;
/**
* @expectedException \InvalidArgumentException
* @dataProvider getEmptyValue
*/
public function testConstructorDoesNotAcceptEmptyPrefix($empty)
{
$this->expectException(\InvalidArgumentException::class);
new DoctrineAclCache(new ArrayCache(), $this->getPermissionGrantingStrategy(), $empty);
}
public function getEmptyValue()
{
return array(
array(null),
array(false),
array(''),
);
return [
[null],
[false],
[''],
];
}
public function test()
@@ -64,7 +65,7 @@ class DoctrineAclCacheTest extends \PHPUnit_Framework_TestCase
{
static $id = 1;
$acl = new Acl($id, new ObjectIdentity($id, 'foo'), $this->getPermissionGrantingStrategy(), array(), $depth > 0);
$acl = new Acl($id, new ObjectIdentity($id, 'foo'), $this->getPermissionGrantingStrategy(), [], $depth > 0);
// insert some ACEs
$sid = new UserSecurityIdentity('johannes', 'Foo');
+3 -3
View File
@@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\Entry;
class EntryTest extends \PHPUnit_Framework_TestCase
class EntryTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -109,11 +109,11 @@ class EntryTest extends \PHPUnit_Framework_TestCase
protected function getAcl()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface');
}
protected function getSid()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
}
}
@@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\FieldEntry;
class FieldEntryTest extends \PHPUnit_Framework_TestCase
class FieldEntryTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -64,11 +64,11 @@ class FieldEntryTest extends \PHPUnit_Framework_TestCase
protected function getAcl()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface');
}
protected function getSid()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
}
}
@@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\ObjectIdentityRetrievalStrategy;
class ObjectIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
class ObjectIdentityRetrievalStrategyTest extends \PHPUnit\Framework\TestCase
{
public function testGetObjectIdentityReturnsNullForInvalidDomainObject()
{
@@ -28,7 +28,7 @@ class ObjectIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$objectIdentity = $strategy->getObjectIdentity($domainObject);
$this->assertEquals($domainObject->getId(), $objectIdentity->getIdentifier());
$this->assertEquals(get_class($domainObject), $objectIdentity->getType());
$this->assertEquals(\get_class($domainObject), $objectIdentity->getType());
}
}
@@ -12,8 +12,9 @@
namespace Symfony\Component\Security\Acl\Tests\Domain
{
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Model\DomainObjectInterface;
class ObjectIdentityTest extends \PHPUnit_Framework_TestCase
class ObjectIdentityTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -34,17 +35,17 @@ namespace Symfony\Component\Security\Acl\Tests\Domain
public function testFromDomainObjectPrefersInterfaceOverGetId()
{
$domainObject = $this->getMock('Symfony\Component\Security\Acl\Model\DomainObjectInterface');
$domainObject
->expects($this->once())
->method('getObjectIdentifier')
->will($this->returnValue('getObjectIdentifier()'))
;
$domainObject
->expects($this->never())
->method('getId')
->will($this->returnValue('getId()'))
;
$domainObject = new class() implements DomainObjectInterface {
public function getObjectIdentifier()
{
return 'getObjectIdentifier()';
}
public function getId()
{
return 'getId()';
}
};
$id = ObjectIdentity::fromDomainObject($domainObject);
$this->assertEquals('getObjectIdentifier()', $id->getIdentifier());
@@ -98,12 +99,12 @@ namespace Symfony\Component\Security\Acl\Tests\Domain
public function getCompareData()
{
return array(
array(new ObjectIdentity('123', 'foo'), new ObjectIdentity('123', 'foo'), true),
array(new ObjectIdentity('123', 'foo'), new ObjectIdentity(123, 'foo'), true),
array(new ObjectIdentity('1', 'foo'), new ObjectIdentity('2', 'foo'), false),
array(new ObjectIdentity('1', 'bla'), new ObjectIdentity('1', 'blub'), false),
);
return [
[new ObjectIdentity('123', 'foo'), new ObjectIdentity('123', 'foo'), true],
[new ObjectIdentity('123', 'foo'), new ObjectIdentity(123, 'foo'), true],
[new ObjectIdentity('1', 'foo'), new ObjectIdentity('2', 'foo'), false],
[new ObjectIdentity('1', 'bla'), new ObjectIdentity('1', 'blub'), false],
];
}
}
@@ -11,14 +11,14 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Exception\NoAceFoundException;
class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
class PermissionGrantingStrategyTest extends \PHPUnit\Framework\TestCase
{
public function testIsGrantedObjectAcesHavePriority()
{
@@ -28,7 +28,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertClassAce($sid, 1);
$acl->insertObjectAce($sid, 1, 0, false);
$this->assertFalse($strategy->isGranted($acl, array(1), array($sid)));
$this->assertFalse($strategy->isGranted($acl, [1], [$sid]));
}
public function testIsGrantedFallsBackToClassAcesIfNoApplicableObjectAceWasFound()
@@ -38,7 +38,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$sid = new UserSecurityIdentity('johannes', 'Foo');
$acl->insertClassAce($sid, 1);
$this->assertTrue($strategy->isGranted($acl, array(1), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [1], [$sid]));
}
public function testIsGrantedFavorsLocalAcesOverParentAclAces()
@@ -53,7 +53,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->setParentAcl($parentAcl);
$parentAcl->insertClassAce($sid, 1, 0, false);
$this->assertTrue($strategy->isGranted($acl, array(1), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [1], [$sid]));
}
public function testIsGrantedFallsBackToParentAcesIfNoLocalAcesAreApplicable()
@@ -69,19 +69,18 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->setParentAcl($parentAcl);
$parentAcl->insertClassAce($sid, 1);
$this->assertTrue($strategy->isGranted($acl, array(1), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [1], [$sid]));
}
/**
* @expectedException \Symfony\Component\Security\Acl\Exception\NoAceFoundException
*/
public function testIsGrantedReturnsExceptionIfNoAceIsFound()
{
$this->expectException(\Symfony\Component\Security\Acl\Exception\NoAceFoundException::class);
$strategy = new PermissionGrantingStrategy();
$acl = $this->getAcl($strategy);
$sid = new UserSecurityIdentity('johannes', 'Foo');
$strategy->isGranted($acl, array(1), array($sid));
$strategy->isGranted($acl, [1], [$sid]);
}
public function testIsGrantedFirstApplicableEntryMakesUltimateDecisionForPermissionIdentityCombination()
@@ -94,11 +93,11 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertClassAce($aSid, 1);
$acl->insertClassAce($sid, 1, 1, false);
$acl->insertClassAce($sid, 1, 2);
$this->assertFalse($strategy->isGranted($acl, array(1), array($sid, $aSid)));
$this->assertFalse($strategy->isGranted($acl, [1], [$sid, $aSid]));
$acl->insertObjectAce($sid, 1, 0, false);
$acl->insertObjectAce($aSid, 1, 1);
$this->assertFalse($strategy->isGranted($acl, array(1), array($sid, $aSid)));
$this->assertFalse($strategy->isGranted($acl, [1], [$sid, $aSid]));
}
public function testIsGrantedCallsAuditLoggerOnGrant()
@@ -107,7 +106,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl($strategy);
$sid = new UserSecurityIdentity('johannes', 'Foo');
$logger = $this->getMock('Symfony\Component\Security\Acl\Model\AuditLoggerInterface');
$logger = $this->createMock('Symfony\Component\Security\Acl\Model\AuditLoggerInterface');
$logger
->expects($this->once())
->method('logIfNeeded')
@@ -117,7 +116,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertObjectAce($sid, 1);
$acl->updateObjectAuditing(0, true, false);
$this->assertTrue($strategy->isGranted($acl, array(1), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [1], [$sid]));
}
public function testIsGrantedCallsAuditLoggerOnDeny()
@@ -126,7 +125,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl($strategy);
$sid = new UserSecurityIdentity('johannes', 'Foo');
$logger = $this->getMock('Symfony\Component\Security\Acl\Model\AuditLoggerInterface');
$logger = $this->createMock('Symfony\Component\Security\Acl\Model\AuditLoggerInterface');
$logger
->expects($this->once())
->method('logIfNeeded')
@@ -136,7 +135,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertObjectAce($sid, 1, 0, false);
$acl->updateObjectAuditing(0, false, true);
$this->assertFalse($strategy->isGranted($acl, array(1), array($sid)));
$this->assertFalse($strategy->isGranted($acl, [1], [$sid]));
}
/**
@@ -151,36 +150,35 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertObjectAce($sid, $aceMask, 0, true, $maskStrategy);
if (false === $result) {
try {
$strategy->isGranted($acl, array($requiredMask), array($sid));
$this->fail('The ACE is not supposed to match.');
} catch (NoAceFoundException $e) {
}
$this->expectException(NoAceFoundException::class);
$this->expectExceptionMessage('No applicable ACE was found.');
$strategy->isGranted($acl, [$requiredMask], [$sid]);
} else {
$this->assertTrue($strategy->isGranted($acl, array($requiredMask), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [$requiredMask], [$sid]));
}
}
public function getAllStrategyTests()
{
return array(
array('all', 1 << 0 | 1 << 1, 1 << 0, true),
array('all', 1 << 0 | 1 << 1, 1 << 2, false),
array('all', 1 << 0 | 1 << 10, 1 << 0 | 1 << 10, true),
array('all', 1 << 0 | 1 << 1, 1 << 0 | 1 << 1 || 1 << 2, false),
array('any', 1 << 0 | 1 << 1, 1 << 0, true),
array('any', 1 << 0 | 1 << 1, 1 << 0 | 1 << 2, true),
array('any', 1 << 0 | 1 << 1, 1 << 2, false),
array('equal', 1 << 0 | 1 << 1, 1 << 0, false),
array('equal', 1 << 0 | 1 << 1, 1 << 1, false),
array('equal', 1 << 0 | 1 << 1, 1 << 0 | 1 << 1, true),
);
return [
['all', 1 << 0 | 1 << 1, 1 << 0, true],
['all', 1 << 0 | 1 << 1, 1 << 2, false],
['all', 1 << 0 | 1 << 10, 1 << 0 | 1 << 10, true],
['all', 1 << 0 | 1 << 1, 1 << 0 | 1 << 1 || 1 << 2, false],
['any', 1 << 0 | 1 << 1, 1 << 0, true],
['any', 1 << 0 | 1 << 1, 1 << 0 | 1 << 2, true],
['any', 1 << 0 | 1 << 1, 1 << 2, false],
['equal', 1 << 0 | 1 << 1, 1 << 0, false],
['equal', 1 << 0 | 1 << 1, 1 << 1, false],
['equal', 1 << 0 | 1 << 1, 1 << 0 | 1 << 1, true],
];
}
protected function getAcl($strategy)
{
static $id = 1;
return new Acl($id++, new ObjectIdentity(1, 'Foo'), $strategy, array(), true);
return new Acl($id++, new ObjectIdentity(1, 'Foo'), $strategy, [], true);
}
}
@@ -11,11 +11,11 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
class RoleSecurityIdentityTest extends \PHPUnit_Framework_TestCase
class RoleSecurityIdentityTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -24,8 +24,15 @@ class RoleSecurityIdentityTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('ROLE_FOO', $id->getRole());
}
/**
* @group legacy
*/
public function testConstructorWithRoleInstance()
{
if (!class_exists(\Symfony\Component\Security\Core\Role\Role::class)) {
$this->markTestSkipped();
}
$id = new RoleSecurityIdentity(new Role('ROLE_FOO'));
$this->assertEquals('ROLE_FOO', $id->getRole());
@@ -43,13 +50,26 @@ class RoleSecurityIdentityTest extends \PHPUnit_Framework_TestCase
}
}
/**
* @group legacy
*/
public function testDeprecatedRoleClassEquals()
{
if (!class_exists(Role::class)) {
$this->markTestSkipped();
}
$id1 = new RoleSecurityIdentity('ROLE_FOO');
$id2 = new RoleSecurityIdentity(new Role('ROLE_FOO'));
$this->assertTrue($id1->equals($id2));
}
public function getCompareData()
{
return array(
array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_FOO'), true),
array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity(new Role('ROLE_FOO')), true),
array(new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity('ROLE_FOO'), false),
array(new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false),
);
return [
[new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_FOO'), true],
[new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity('ROLE_FOO'), false],
[new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false],
];
}
}
@@ -11,12 +11,17 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\SecurityIdentityRetrievalStrategy;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\User\UserInterface;
class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
class SecurityIdentityRetrievalStrategyTest extends TestCase
{
/**
* @dataProvider getSecurityIdentityRetrievalTests
@@ -24,18 +29,18 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
public function testGetSecurityIdentities($user, array $roles, $authenticationStatus, array $sids)
{
if ('anonymous' === $authenticationStatus) {
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken')
->disableOriginalConstructor()
->getMock();
$token = $this->getMockBuilder(AnonymousToken::class)
->disableOriginalConstructor()
->getMock();
} else {
$class = '';
if (is_string($user)) {
if (\is_string($user)) {
$class = 'MyCustomTokenImpl';
}
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
->setMockClassName($class)
->getMock();
$token = $this->getMockBuilder(AbstractToken::class)
->setMockClassName($class)
->getMock();
}
if (method_exists($token, 'getRoleNames')) {
@@ -44,7 +49,7 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$token
->expects($this->once())
->method('getRoleNames')
->will($this->returnValue(array('foo')))
->willReturn(['foo'])
;
} else {
$strategy = $this->getStrategy($roles, $authenticationStatus, true);
@@ -52,7 +57,7 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$token
->expects($this->once())
->method('getRoles')
->will($this->returnValue(array(new Role('foo'))))
->willReturn([new Role('foo')])
;
}
@@ -65,7 +70,7 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$token
->expects($this->once())
->method('getUser')
->will($this->returnValue($user))
->willReturn($user)
;
}
@@ -84,55 +89,58 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
public function getSecurityIdentityRetrievalTests()
{
return array(
array($this->getAccount('johannes', 'FooUser'), array('ROLE_USER', 'ROLE_SUPERADMIN'), 'fullFledged', array(
return [
[$this->getAccount('johannes', 'FooUser'), ['ROLE_USER', 'ROLE_SUPERADMIN'], 'fullFledged', [
new UserSecurityIdentity('johannes', 'FooUser'),
new RoleSecurityIdentity('ROLE_USER'),
new RoleSecurityIdentity('ROLE_SUPERADMIN'),
new RoleSecurityIdentity('IS_AUTHENTICATED_FULLY'),
new RoleSecurityIdentity('IS_AUTHENTICATED_REMEMBERED'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
array('johannes', array('ROLE_FOO'), 'fullFledged', array(
]],
['johannes', ['ROLE_FOO'], 'fullFledged', [
new UserSecurityIdentity('johannes', 'MyCustomTokenImpl'),
new RoleSecurityIdentity('ROLE_FOO'),
new RoleSecurityIdentity('IS_AUTHENTICATED_FULLY'),
new RoleSecurityIdentity('IS_AUTHENTICATED_REMEMBERED'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
array(new CustomUserImpl('johannes'), array('ROLE_FOO'), 'fullFledged', array(
]],
[new CustomUserImpl('johannes'), ['ROLE_FOO'], 'fullFledged', [
new UserSecurityIdentity('johannes', 'Symfony\Component\Security\Acl\Tests\Domain\CustomUserImpl'),
new RoleSecurityIdentity('ROLE_FOO'),
new RoleSecurityIdentity('IS_AUTHENTICATED_FULLY'),
new RoleSecurityIdentity('IS_AUTHENTICATED_REMEMBERED'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
array($this->getAccount('foo', 'FooBarUser'), array('ROLE_FOO'), 'rememberMe', array(
]],
[$this->getAccount('foo', 'FooBarUser'), ['ROLE_FOO'], 'rememberMe', [
new UserSecurityIdentity('foo', 'FooBarUser'),
new RoleSecurityIdentity('ROLE_FOO'),
new RoleSecurityIdentity('IS_AUTHENTICATED_REMEMBERED'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
array('guest', array('ROLE_FOO'), 'anonymous', array(
]],
['guest', ['ROLE_FOO'], 'anonymous', [
new RoleSecurityIdentity('ROLE_FOO'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
);
]],
];
}
protected function getAccount($username, $class)
{
$account = $this->getMock('Symfony\Component\Security\Core\User\UserInterface', array(), array(), $class);
$account = $this->getMockBuilder(UserInterface::class)
->setMockClassName($class)
->getMock()
;
$account
->expects($this->any())
->method('getUsername')
->will($this->returnValue($username))
->willReturn($username)
;
return $account;
}
protected function getStrategy(array $roles = array(), $authenticationStatus = 'fullFledged', $isBC = false)
protected function getStrategy(array $roles = [], $authenticationStatus = 'fullFledged', $isBC = false)
{
$roleHierarchyBuilder = $this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleHierarchyInterface')
->disableProxyingToOriginalMethods()
@@ -146,7 +154,7 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
->expects($this->any())
->method('getReachableRoles')
->with($this->equalTo([new Role('foo')]))
->will($this->returnValue($roles));
->willReturn($roles);
} else {
$roleHierarchy = $roleHierarchyBuilder->setMethods(['getReachableRoleNames'])
->getMockForAbstractClass();
@@ -155,23 +163,21 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
->expects($this->any())
->method('getReachableRoleNames')
->with($this->equalTo(['foo']))
->will($this->returnValue($roles));
->willReturn($roles);
}
$trustResolver = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface', array(), array('', ''));
$trustResolver = $this->createMock(AuthenticationTrustResolverInterface::class);
$trustResolver
->expects($this->at(0))
->method('isAnonymous')
->will($this->returnValue('anonymous' === $authenticationStatus))
->willReturn('anonymous' === $authenticationStatus)
;
if ('fullFledged' === $authenticationStatus) {
$trustResolver
->expects($this->once())
->method('isFullFledged')
->will($this->returnValue(true))
->willReturn(true)
;
$trustResolver
->expects($this->never())
@@ -181,28 +187,27 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$trustResolver
->expects($this->once())
->method('isFullFledged')
->will($this->returnValue(false))
->willReturn(false)
;
$trustResolver
->expects($this->once())
->method('isRememberMe')
->will($this->returnValue(true))
->willReturn(true)
;
} else {
$trustResolver
->expects($this->at(1))
->method('isAnonymous')
->will($this->returnValue(true))
->willReturn(true)
;
$trustResolver
->expects($this->once())
->method('isFullFledged')
->will($this->returnValue(false))
->willReturn(false)
;
$trustResolver
->expects($this->once())
->method('isRememberMe')
->will($this->returnValue(false))
->willReturn(false)
;
}
@@ -14,7 +14,7 @@ namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
class UserSecurityIdentityTest extends \PHPUnit_Framework_TestCase
class UserSecurityIdentityTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -49,25 +49,25 @@ class UserSecurityIdentityTest extends \PHPUnit_Framework_TestCase
$account
->expects($this->any())
->method('getUsername')
->will($this->returnValue('foo'))
->willReturn('foo')
;
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$token = $this->createMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$token
->expects($this->any())
->method('getUser')
->will($this->returnValue($account))
->willReturn($account)
;
return array(
array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('foo', 'Foo'), true),
array(new UserSecurityIdentity('foo', 'Bar'), new UserSecurityIdentity('foo', 'Foo'), false),
array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('bar', 'Foo'), false),
array(new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromAccount($account), false),
array(new UserSecurityIdentity('bla', 'Foo'), new UserSecurityIdentity('blub', 'Foo'), false),
array(new UserSecurityIdentity('foo', 'Foo'), new RoleSecurityIdentity('foo'), false),
array(new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromToken($token), false),
array(new UserSecurityIdentity('foo', 'USI_AccountImpl'), UserSecurityIdentity::fromToken($token), true),
);
return [
[new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('foo', 'Foo'), true],
[new UserSecurityIdentity('foo', 'Bar'), new UserSecurityIdentity('foo', 'Foo'), false],
[new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('bar', 'Foo'), false],
[new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromAccount($account), false],
[new UserSecurityIdentity('bla', 'Foo'), new UserSecurityIdentity('blub', 'Foo'), false],
[new UserSecurityIdentity('foo', 'Foo'), new RoleSecurityIdentity('foo'), false],
[new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromToken($token), false],
[new UserSecurityIdentity('foo', 'USI_AccountImpl'), UserSecurityIdentity::fromToken($token), true],
];
}
}