Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

【cakephp3】CSRFコンポーネントロード時のテストコードのリクエストの送り方

More than 1 year has passed since last update.

バージョン

Cakephp3 3.5

背景

$this->loadComponent('Csrf')で
CSRFコンポーネントをロードしているコントローラにて
テストコードを書いた際、$this->postが403Forbiddenになり困った。

解決

$this->_csrfToken = true; //この行を追加

$this->get('users/add');

$email = 'test@email.com';
$button = 'confirm';

$this->session($this->_requestSession->read());
$this->post('users/add',compact(['email','button']);

※1行目が無いと403Forbiddenがレスポンスされる。

gano
ブロックチェーン関連のプログラミングしてます
https://www.facebook.com/gano.global
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away