我正在使用 Symfony 4.4 和api-platform/api-pack v1.2.1
我创建了一个支持带前缀的字符串的自定义选民PERM_
我将端点 ( /api/roles) 设置为security: 'is_granted("PERM_READ_USER")'
我创建了一个如下所示的测试:
/**
* @depends testLoginRegularUser
* @param $token
* @return string JWT Token
*/
public function testRegularUserReadRole($token)
{
$this->expectException(AccessDeniedHttpException::class);
$this->expectExceptionCode(403);
$response = static ::createClient()->request('GET', '/api/roles',[
'json' => [
'page' => 1
],
'headers' => [
'Authorization' => 'Bearer ' . $token,
]
]);
return $token;
}
而且我总是收到错误消息:
Testing App\Tests\Functional\GroupRoleTest
.2020-01-06T00:49:48+00:00 [error] Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: "Access Denied." at /home/vagrant/Code/wikaunting/vendor/symfony/security-http/Firewall/ExceptionListener.php line 137
FS 3 / 3 (100%)
Time: 14.27 seconds, Memory: 44.50 MB
There was 1 failure:
1) App\Tests\Functional\GroupRoleTest::testRegularUserReadRole
Failed asserting that exception of type "Symfony\Component\HttpClient\Exception\AccessDeniedHttpException" is thrown.
当我使用休息客户端(失眠症)进行测试时,它返回
翻翻过去那场雪
暮色呼如