karate

Karate testing error with HTTP 307 (redirection)


I am running FastAPI server which exposes an endpoint that can accept PATCH operation to update user profile.

In my feature file, I have defined the scenario like below:

Scenario: PATCH api/v1/profile/ UPDATE

Given path 'api/v1/profile/'
And def jsonBody =
"""
<my JSON payload>
"""
And request data = jsonBody

When method PATCH
Then status 200

Every time when I ran this scenario, Karate in the background generated a request to endpoint 'api/v1/profile' (with no trailing /)

This has caused my FastAPI server to return HTTP 307 (redirection) which attempts to redirect the request to valid endpoint 'api/v1/profile/' (with / trailing)

This issue seems to happen when API request is triggered from Karate feature file, whereas Postman web has no issue at all (When I use postman to fire the PATCH request, I can receive 200 OK)

There was previous blog that proposed a solution to solve this on the server side => https://github.com/fastapi/fastapi/issues/2060

But I wonder if there is a way for me to resolve this issue from Karate side.

Thank you. screenshot


Solution

  • This can be actually considered a bug in your server as you seem to have already figured out.

    Yes, you can force the trailing slash like this, documented here: https://github.com/karatelabs/karate#path

    * path 'api/v1/profile', '/'
    

    You can also do it like this if you want:

    * path 'api', 'v1', 'profile', '/'