Skip to content

[Security] Fix tests in 2.8 #15961

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

Merged
merged 1 commit into from
Sep 28, 2015
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,72 @@ public function testVote(array $attributes, $expectedVote, $object, $message)

$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
}

/**
* @dataProvider getTests
* @group legacy
*/
public function testVoteLegacy(array $attributes, $expectedVote, $object, $message)
{
$voter = new AbstractVoterTest_LegacyVoter();

$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
}

/**
* @group legacy
* @expectedException \BadMethodCallException
*/
public function testNoOverriddenMethodsThrowsException()
{
$voter = new AbstractVoterTest_NothingImplementedVoter();
$voter->vote($this->token, new \stdClass(), array('EDIT'));
}
}

class AbstractVoterTest_Voter extends AbstractVoter
{
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
{
return 'EDIT' === $attribute;
}

protected function supports($attribute, $class)
{
return $this->isClassInstanceOf($class, 'stdClass')
&& in_array($attribute, array('EDIT', 'CREATE'));
}
}

class AbstractVoterTest_LegacyVoter extends AbstractVoter
{
protected function getSupportedClasses()
{
return array('stdClass');
return array('AbstractVoterTest_Object');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be reverted, it should accept stdClass.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaics, this should fix the tests (but I'm on a mobile now, sp can't be 100% sure).

}

protected function getSupportedAttributes()
{
return array('EDIT', 'CREATE');
}

protected function voteOnAttribute($attribute, $object, TokenInterface $token)
protected function isGranted($attribute, $object, $user = null)
{
return $attribute === 'foo';
return 'EDIT' === $attribute;
}
}

class DeprecatedVoterFixture extends AbstractVoter
class AbstractVoterTest_NothingImplementedVoter extends AbstractVoter
{
protected function getSupportedClasses()
{
return array(
'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
);
return array('AbstractVoterTest_Object');
}

protected function getSupportedAttributes()
{
return array('foo', 'bar', 'baz');
return array('EDIT', 'CREATE');
}

protected function isGranted($attribute, $object, $user = null)
{
return 'EDIT' === $attribute;
}
// this is a bad voter that hasn't overridden isGranted or voteOnAttribute
}