Answer the question
In order to leave comments, you need to log in
How to log in using the HTTP client to the admin panel?
I'm making a script to check for broken links in the admin panel. It must login and follow all the links on a particular page. I use Guzzle as a client: https://github.com/guzzle/guzzle
But it turns out that when trying to log in from this client, in fact, I make a fake request, which CSRF protection successfully repels) How can I solve this problem? Temporarily disable CSRF while testing? Should be standard practice for this case.
Answer the question
In order to leave comments, you need to log in
I'm making a script to check for broken links in the admin panel.
There should be a standard practice for this case.
// Тут предварительно логинимся (метод amLogin() не родной,
// надо создать его в классе AcceptanceTester)
public function _before(AcceptanceTester $I)
{
$I->amLogin('admin', 'admin');
$I->amOnPage('/admin');
}
/** Ниже добавляем через аннотацию провайдер всех ссылок
* и данный тест будет выполняться для каждой ссылки в админке
* @dataProvider linksInAdminPanel
*
* Или вычесать все ссылки с каждой страницы в методе
* и записать в массив и потом по ним идти, проверяя -- была ссылка или нет
*
*/
public function linkIsCorrect(AcceptanceTester $I, \Codeception\Example $pageAdmin)
{
$I->amOnPage($pageAdmin['url']);
$I->seeResponseCodeIs(HttpCode::OK);
}
// Перечень ссылок в админке
protected function linksInAdminPanel()
{
return [
['url' => '/admin/users'],
['url' => '/admin/settings'],
['url' => '/admin/products'],
....
];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question