Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to symfony 7 #117

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 77 additions & 13 deletions Tests/Dbal/AclProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace Symfony\Component\Security\Acl\Tests\Dbal;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Dbal\Schema;
Expand Down Expand Up @@ -146,41 +148,103 @@

protected function setUp(): void
{
$this->connection = DriverManager::getConnection([
$configuration = new Configuration();
if (\method_exists($configuration, 'setSchemaManagerFactory')) {

Check failure on line 152 in Tests/Dbal/AclProviderTest.php

View workflow job for this annotation

GitHub Actions / Psalm

RedundantCondition

Tests/Dbal/AclProviderTest.php:152:13: RedundantCondition: Type Doctrine\DBAL\Configuration for $configuration is always method-exists-setSchemaManagerFactory (see https://psalm.dev/122)
$configuration->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

$this->connection = DriverManager::getConnection(
[
'driver' => 'pdo_sqlite',
'memory' => true,
]);
],
$configuration
);

// import the schema
$schema = new Schema($this->getOptions());
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->executeStatement($sql);
}

// populate the schema with some test data
$insertClassStmt = $this->connection->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
$qb = $this->connection->createQueryBuilder();

foreach ($this->getClassData() as $data) {
$insertClassStmt->executeStatement($data);
$qb
->insert('acl_classes')
->values(
[
'id' => '?',
'class_type' => '?',
]
)
->setParameters($data)
->executeQuery();
}

$insertSidStmt = $this->connection->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
foreach ($this->getSidData() as $data) {
$insertSidStmt->executeStatement($data);
$qb
->insert('acl_security_identities')
->values(
[
'id' => '?',
'identifier' => '?',
'username' => '?',
]
)
->setParameters($data)
->executeQuery();
}

$insertOidStmt = $this->connection->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
foreach ($this->getOidData() as $data) {
$insertOidStmt->executeStatement($data);
$qb
->insert('acl_object_identities')
->values(
[
'id' => '?',
'class_id' => '?',
'object_identifier' => '?',
'parent_object_identity_id' => '?',
'entries_inheriting' => '?',
]
)
->setParameters($data)
->executeQuery();
}

$insertEntryStmt = $this->connection->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
foreach ($this->getEntryData() as $data) {
$insertEntryStmt->executeStatement($data);
$qb
->insert('acl_entries')
->values(
[
'id' => '?',
'class_id' => '?',
'object_identity_id' => '?',
'field_name' => '?',
'ace_order' => '?',
'security_identity_id' => '?',
'mask' => '?',
'granting' => '?',
'granting_strategy' => '?',
'audit_success' => '?',
'audit_failure' => '?',
]
)
->setParameters($data)
->executeQuery();
}

$insertOidAncestorStmt = $this->connection->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
foreach ($this->getOidAncestorData() as $data) {
$insertOidAncestorStmt->executeStatement($data);
$qb
->insert('acl_object_identity_ancestors')
->values(
[
'object_identity_id' => '?',
'ancestor_id' => '?',
]
)
->setParameters($data)
->executeQuery();
}
}

Expand Down
22 changes: 17 additions & 5 deletions Tests/Dbal/MutableAclProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Component\Security\Acl\Tests\Dbal;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Dbal\MutableAclProvider;
Expand All @@ -23,6 +25,7 @@
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\AclAlreadyExistsException;
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
use Symfony\Component\Security\Acl\Exception\ConcurrentModificationException;
use Symfony\Component\Security\Acl\Model\AuditableEntryInterface;
Expand Down Expand Up @@ -59,7 +62,7 @@

public function testCreateAclThrowsExceptionWhenAclAlreadyExists()
{
$this->expectException(\Symfony\Component\Security\Acl\Exception\AclAlreadyExistsException::class);
$this->expectException(AclAlreadyExistsException::class);

$provider = $this->getProvider();
$oid = new ObjectIdentity('123456', 'FOO');
Expand Down Expand Up @@ -518,10 +521,19 @@

protected function setUp(): void
{
$this->connection = DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'memory' => true,
]);
$configuration = new Configuration();
if (\method_exists($configuration, 'setSchemaManagerFactory')) {

Check failure on line 525 in Tests/Dbal/MutableAclProviderTest.php

View workflow job for this annotation

GitHub Actions / Psalm

RedundantCondition

Tests/Dbal/MutableAclProviderTest.php:525:13: RedundantCondition: Type Doctrine\DBAL\Configuration for $configuration is always method-exists-setSchemaManagerFactory (see https://psalm.dev/122)
$configuration->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

$this->connection = DriverManager::getConnection(
[
'driver' => 'pdo_sqlite',
'memory' => true,
],
$configuration
);
$this->connection->setNestTransactionsWithSavepoints(true);

// import the schema
$schema = new Schema($this->getOptions());
Expand Down
2 changes: 1 addition & 1 deletion Tests/Domain/SecurityIdentityRetrievalStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function getRoles(): array
return [];
}

public function eraseCredentials()
public function eraseCredentials(): void
{
}

Expand Down
28 changes: 27 additions & 1 deletion Voter/AclVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,39 @@
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

if (class_exists(\Symfony\Component\Security\Core\Security::class)) {
/**
* @internal
*/
trait AclVoterTrait
{
public function vote(TokenInterface $token, $subject, array $attributes)
{
return $this->doVote($token, $subject, $attributes);
}
}
} else {
/**
* @internal
*/
trait AclVoterTrait
{
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
{
return $this->doVote($token, $subject, $attributes);
}
}
}

/**
* This voter can be used as a base class for implementing your own permissions.
*
* @author Johannes M. Schmitt <[email protected]>
*/
class AclVoter implements VoterInterface
{
use AclVoterTrait;

private $aclProvider;
private $permissionMap;
private $objectIdentityRetrievalStrategy;
Expand All @@ -51,7 +77,7 @@ public function supportsAttribute($attribute)
return \is_string($attribute) && $this->permissionMap->contains($attribute);
}

public function vote(TokenInterface $token, $subject, array $attributes)
private function doVote(TokenInterface $token, $subject, array $attributes)
{
foreach ($attributes as $attribute) {
if (!$this->supportsAttribute($attribute)) {
Expand Down
59 changes: 29 additions & 30 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="Symfony Security Component ACL Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<groups>
<exclude>
<group>benchmark</group>
</exclude>
</groups>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Symfony Security Component ACL Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>benchmark</group>
</exclude>
</groups>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
Loading