From 5a54ca02dc5e8fb473ab86999e9ddacb9dcbee4f Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 28 Jan 2017 15:25:16 +0100 Subject: [PATCH 1/2] Account for subject to not be an object --- PublishWorkflow/Voter/PublishTimePeriodVoter.php | 10 +++++----- PublishWorkflow/Voter/PublishableVoter.php | 8 ++++---- Security/Authorization/Voter/PublishedVoter.php | 8 ++++---- .../Voter/PublishTimePeriodVoterTest.php | 6 ++++++ .../PublishWorkflow/Voter/PublishableVoterTest.php | 6 ++++++ 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/PublishWorkflow/Voter/PublishTimePeriodVoter.php b/PublishWorkflow/Voter/PublishTimePeriodVoter.php index 8e84f499..1686f1d8 100644 --- a/PublishWorkflow/Voter/PublishTimePeriodVoter.php +++ b/PublishWorkflow/Voter/PublishTimePeriodVoter.php @@ -66,16 +66,16 @@ public function supportsClass($class) /** * {@inheritdoc} * - * @param PublishTimePeriodReadInterface $object + * @param PublishTimePeriodReadInterface $subject */ - public function vote(TokenInterface $token, $object, array $attributes) + public function vote(TokenInterface $token, $subject, array $attributes) { - if (!$this->supportsClass(get_class($object))) { + if (!is_object($subject) || !$this->supportsClass(get_class($subject))) { return self::ACCESS_ABSTAIN; } - $startDate = $object->getPublishStartDate(); - $endDate = $object->getPublishEndDate(); + $startDate = $subject->getPublishStartDate(); + $endDate = $subject->getPublishEndDate(); $decision = self::ACCESS_GRANTED; foreach ($attributes as $attribute) { diff --git a/PublishWorkflow/Voter/PublishableVoter.php b/PublishWorkflow/Voter/PublishableVoter.php index f108efeb..a6d8a36d 100644 --- a/PublishWorkflow/Voter/PublishableVoter.php +++ b/PublishWorkflow/Voter/PublishableVoter.php @@ -44,11 +44,11 @@ public function supportsClass($class) /** * {@inheritdoc} * - * @param PublishableReadInterface $object + * @param PublishableReadInterface $subject */ - public function vote(TokenInterface $token, $object, array $attributes) + public function vote(TokenInterface $token, $subject, array $attributes) { - if (!$this->supportsClass(get_class($object))) { + if (!is_object($subject) || !$this->supportsClass(get_class($subject))) { return self::ACCESS_ABSTAIN; } @@ -61,7 +61,7 @@ public function vote(TokenInterface $token, $object, array $attributes) $decision = self::ACCESS_ABSTAIN; continue; } - if (!$object->isPublishable()) { + if (!$subject->isPublishable()) { return self::ACCESS_DENIED; } } diff --git a/Security/Authorization/Voter/PublishedVoter.php b/Security/Authorization/Voter/PublishedVoter.php index e1e36ecc..7060547d 100644 --- a/Security/Authorization/Voter/PublishedVoter.php +++ b/Security/Authorization/Voter/PublishedVoter.php @@ -57,11 +57,11 @@ public function supportsClass($class) /** * {@inheritdoc} * - * @param object $object + * @param object $subject */ - public function vote(TokenInterface $token, $object, array $attributes) + public function vote(TokenInterface $token, $subject, array $attributes) { - if (!$this->supportsClass(get_class($object))) { + if (!is_object($subject) || !$this->supportsClass(get_class($subject))) { return self::ACCESS_ABSTAIN; } foreach ($attributes as $attribute) { @@ -70,7 +70,7 @@ public function vote(TokenInterface $token, $object, array $attributes) } } - if ($this->publishWorkflowChecker->isGranted($attributes, $object)) { + if ($this->publishWorkflowChecker->isGranted($attributes, $subject)) { return self::ACCESS_GRANTED; } diff --git a/Tests/Unit/PublishWorkflow/Voter/PublishTimePeriodVoterTest.php b/Tests/Unit/PublishWorkflow/Voter/PublishTimePeriodVoterTest.php index 5dc5085e..3255e692 100644 --- a/Tests/Unit/PublishWorkflow/Voter/PublishTimePeriodVoterTest.php +++ b/Tests/Unit/PublishWorkflow/Voter/PublishTimePeriodVoterTest.php @@ -132,4 +132,10 @@ public function testUnsupportedClass() ); $this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result); } + + public function testNonClassSubject() + { + $result = $this->voter->vote($this->token, array(1, 2, 3), array(PublishWorkflowChecker::VIEW_ATTRIBUTE)); + $this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result); + } } diff --git a/Tests/Unit/PublishWorkflow/Voter/PublishableVoterTest.php b/Tests/Unit/PublishWorkflow/Voter/PublishableVoterTest.php index 745c708f..2373c8e9 100644 --- a/Tests/Unit/PublishWorkflow/Voter/PublishableVoterTest.php +++ b/Tests/Unit/PublishWorkflow/Voter/PublishableVoterTest.php @@ -100,4 +100,10 @@ public function testUnsupportedClass() ); $this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result); } + + public function testNonClassSubject() + { + $result = $this->voter->vote($this->token, array(1, 2, 3), array(PublishWorkflowChecker::VIEW_ATTRIBUTE)); + $this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result); + } } From c9ff106f1ed5f21e4928d09e27ae59877fdd2ba2 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sun, 29 Jan 2017 11:55:54 +0100 Subject: [PATCH 2/2] USe weak deprecations node --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 15bef9f1..77f5d1b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ cache: env: matrix: SYMFONY_VERSION=2.8.* - global: SYMFONY_DEPRECATIONS_HELPER=7 + global: SYMFONY_DEPRECATIONS_HELPER=weak matrix: include: