dongsimang4036 2019-02-26 18:06 采纳率: 100%
浏览 92

Laravel 5.7 CSRF中间件

According to Laravel 5.7 Docs

"The CSRF middleware is automatically disabled when running tests."

But I have the following Test

public function testUserLoginSuccesfully()
{
    $data = ['email' => 'test@user.com' , 'password' => bcrypt('test12345')];
    $csrf = csrf_token();

    $response = $this->withHeaders(['_token' => $csrf])
    ->post('/login',$data);

    $response->assertStatus(302)->assertRedirect('/home');

}

In order to work properly I have to disable csrf protection in the VerifyCsrfToken.php:

protected $except = [
    //
    '/login','/register'
];

If don't modify this property I'm getting a http 419 error. I don't know what I'm missing or how can I disable csrf only for testing.

Thanks in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制