Karate: 0.7.0 upgrade - nullPointerException when performing request with missing or invalid basic auth credentials

Created on 7 Mar 2018  Â·  13Comments  Â·  Source: intuit/karate

The following scenario passes on 0.6.2 but fails on 0.7.0

  Scenario: Basic Auth Credentials must be supplied for POST
    Given path '/apath'
    And request
    """
      {
        "foo": "bar"
      }
    """
    When method PUT
    Then status 401
    And match response.errors[0].code == "unauthorized"
    And match response.errors[0].message == "Not authorized"

I get the response

15:56:05.225 [main] DEBUG com.intuit.karate - 
1 > PUT SOMEENDPOINT
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 128
1 > Content-Type: application/json; charset=UTF-81 > Host: SOMEHOST
1 > User-Agent: Apache-HttpClient/4.5.4 (Java/1.8.0_112)
{"foo":"bar"}
15:56:05.391 [main] ERROR com.intuit.karate - java.lang.NullPointerException, http call failed after 167 milliseconds for URL: SOMEENDPOINT
15:56:05.391 [main] ERROR com.intuit.karate - http request failed: 
java.lang.NullPointerException
com.intuit.karate.exception.KarateException:
java.lang.NullPointerException
  at com.intuit.karate.StepDefs.method(StepDefs.java:364)
  at ✽.When method PUT(.feature:209)

If I revert back to 0.6.2 it works again!

bug fixed

All 13 comments

I see the same behaviour in my restful get call. Seems to happen when the http authorization header is absent in 0.7.0. Reverting to 0.6.2 or adding the auth header solves the issue.
karate/authtoken/outcome
0.6.2 /yes/success
0.6.2 /no/success
0.7.0 /yes/success
0.7.0 /no/npe
NoAuthHeader.txt

@YOU54F @mdarke I really need a way to replicate this. I just tried to write a test and it works:

https://github.com/intuit/karate/commit/83a5814c3cf6c60743c414d9fa5a8c815dbdf64c

@here .Same issue for me.After upgrade getting the following error

13:31:56.783 [main] ERROR com.intuit.karate - java.lang.NullPointerException, http call failed after 1345 milliseconds for URL: https://test.com/Testingf3ccf108-8efe-41fc-ba83-addd9f3a362c?overwrite=false 13:31:56.783 [main] ERROR com.intuit.karate - http request failed: java.lang.NullPointerException 13:31:56.784 [main] ERROR com.intuit.karate - feature call failed: classpath:com/create-test.feature java.lang.NullPointerException

Downgrading to '0.6.2' works for me too.

Cheers Peter, when i get on my machine I will pull that branch down and test

@YOU54F and everybody else. it is not a branch. I'm confused with the title it says PATCH but then the example says PUT.

can someone please create a simple minimal example that I can run to replicate this problem please. it can use some public / fake end-point if it works. does that make sense ?

Sorry that is my fault, the issue occurs with any method. Please see below examples @ptrthomas - thanks again my friend


Feature: test basic auth

  Background:
    * url 'https://httpbin.org'

  Scenario: dont pass basic auth creds, service should respond with error
    Given path '/basic-auth/user/passwd'
    When method GET
    Then status 401

  Scenario: pass invalid basic auth creds, service should respond with error
    Given path '/basic-auth/user/passwd'
    And header authorization = 'test'
    When method GET
    Then status 401

  Scenario: pass valid basic auth creds, service should respond with 200
    Given path '/basic-auth/user/passwd'
    And header authorization = 'Basic dXNlcjpwYXNzd2Q='
    When method GET
    Then status 200

@YOU54F thanks, able to replicate ! looking into it. quick one - if you switch to karate-jersey does that work ?

I can confirm that it works with karate-jersey and I receive the 401's as expected for the first 2 tests.

Top man as always chap!

@YOU54F great, thanks !

this is a bug in Apache ! https://issues.apache.org/jira/browse/HTTPCLIENT-1888

fixed in dev.

for those who need a workaround but don't want to use karate-jersey this is a possible workaround in the pom.xml.

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.5</version>
    <scope>test</scope>
</dependency>

Brilliant thank you so much @ptrthomas, I have retested with karate-apache and the adding in the 4.5.5 version of httpclient and it's all sorted :)

Do you want me to close down the issue now?

@YOU54F no we can keep this open until the 0.7.1 release. thanks !

released 0.8.0

Was this page helpful?
0 / 5 - 0 ratings