orangehrm / orangehrm

OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures all the essential functionalities required for any enterprise.
GNU General Public License v3.0
746 stars 537 forks source link

error={"error":"invalid_csrf_token", "message":"CSRF token validation failed"} #1771

Closed jstawow closed 5 months ago

jstawow commented 6 months ago

OrangeHRM version

5.5

Environment details

Describe the bug

I wrote such apiLogin test in playwright: It seems that I wrote all the same as in your cypress tests Why response that I got is html Why there is an error which I put down in bold What and how should I get from that response cookies or token in order to pass to another request When I use those credentials in website then I am logged in successfully to the orangehrm application on localhost test.only('Api login', async ({ request }) => {

const newIssue = await request.post('http://localhost:8888/web/index.php/auth/validate', {
  data: {
    username: 'user is correct',
    password: 'password is correct',
  },
});

expect(newIssue.ok()).toBeTruthy();

const responseBody = await newIssue.text();
console.log(responseBody);

}); output is as follow: Running 1 test using 1 worker [desktop-chromium] › functional/tests/pimPage.spec.ts:212:8 › Admin user should be able to manage on pim page › Api login <!DOCTYPE html>

OrangeHRM

To reproduce

No response

Expected behavior

No response

Relevant log output

No response

devishke-orange commented 6 months ago

Hi @jstawow

Thank you for your interest in writing tests for OrangeHRM 5.5!

You will not be able to log in directly. If you look at the relevant code in our cypress test, you can see that we have a separate plugin that we use for testing: https://github.com/orangehrm/orangehrm/blob/main/src/test/functional/cypress/support/commands.js#L38-L47

This plugin is located in src/test/functional/tools/plugins/orangehrmFunctionalTestingPlugin.

In order to setup for testing:

This will copy the plugin to src/plugins and create a savepoint for the database. You can verify that it's working by running the cypress tests (README: https://github.com/orangehrm/orangehrm/blob/main/src/test/functional/Readme.md)