mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-01 14:04:30 +02:00
Added tests on some security related classes.
This commit is contained in:
parent
6ddc937ec5
commit
bf8455fa42
6 changed files with 169 additions and 38 deletions
|
@ -89,8 +89,9 @@ class ColumnSecurity
|
|||
if ($object instanceof NamedDBElement) {
|
||||
if (\is_string($this->placeholder) && '' !== $this->placeholder) {
|
||||
$object->setName($this->placeholder);
|
||||
} else {
|
||||
$object->setName('???');
|
||||
}
|
||||
$object->setName('???');
|
||||
}
|
||||
|
||||
return $object;
|
||||
|
@ -99,6 +100,7 @@ class ColumnSecurity
|
|||
if (null === $this->placeholder) {
|
||||
switch ($this->type) {
|
||||
case 'integer':
|
||||
case 'int':
|
||||
return 0;
|
||||
case 'float':
|
||||
return 0.0;
|
||||
|
@ -109,11 +111,10 @@ class ColumnSecurity
|
|||
case 'collection':
|
||||
return new ArrayCollection();
|
||||
case 'boolean':
|
||||
case 'bool':
|
||||
return false;
|
||||
case 'datetime':
|
||||
$date = new \DateTime();
|
||||
|
||||
return $date->setTimestamp(0);
|
||||
return (new \DateTime())->setTimestamp(0);
|
||||
default:
|
||||
throw new InvalidArgumentException('Unknown type! You have to specify a placeholder!');
|
||||
}
|
||||
|
|
|
@ -30,11 +30,9 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
class UserChecker implements UserCheckerInterface
|
||||
{
|
||||
protected $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
public function __construct()
|
||||
{
|
||||
$this->translator = $translator;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,7 +56,8 @@ abstract class ExtendedVoter extends Voter
|
|||
|
||||
// if the user is anonymous, we use the anonymous user.
|
||||
if (!$user instanceof User) {
|
||||
$user = $this->entityManager->find(User::class, User::ID_ANONYMOUS);
|
||||
$repo = $this->entityManager->getRepository(User::class);
|
||||
$user = $repo->getAnonymousUser();
|
||||
if (null === $user) {
|
||||
return false;
|
||||
}
|
||||
|
@ -71,6 +72,7 @@ abstract class ExtendedVoter extends Voter
|
|||
*
|
||||
* @param $attribute
|
||||
* @param $subject
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function voteOnUser($attribute, $subject, User $user): bool;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue