Unable to authenticate user when doing unit testing |
10-01-2024, 08:21 AM
(This post was last modified: 10-01-2024, 11:39 AM by Morph. Edit Reason: Cleaned up code )
I'm building an API with CodeIgniter v4.5.5.
I'm also using Shield and using the token based authentication. I can successfully register and login a user through a POST request using a REST client. However, I am unable to login the user in a unit test. Other POST requests (like registering a new user) work fine in unit tests. This is the section of code which authenticates a user: PHP Code: // Attempt to login Works fine with a REST client. This is the output of dump($result) when attempting to POST to /login in my unit tests: Code: CodeIgniter\Shield\Result^ {#498 So when attempting the POST request through the framework , Shield is refusing to authenticate due to a bearer token missing. This endpoint (/login) is excluded from the tokens filter in the Filters.php configuration. How do I workaround this with a POST request to /login? |
Messages In This Thread |
Unable to authenticate user when doing unit testing - by Morph - 10-01-2024, 08:21 AM
RE: Unable to authenticate user when doing unit testing - by kenjis - 10-03-2024, 09:34 PM
RE: Unable to authenticate user when doing unit testing - by Morph - 10-03-2024, 10:23 PM
|