Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.7.0 upgrade - nullPointerException when performing request with missing or invalid basic auth credentials #342

Closed
YOU54F opened this issue Mar 7, 2018 · 13 comments
Assignees
Milestone

Comments

@YOU54F
Copy link

YOU54F commented Mar 7, 2018

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!

@mdarke
Copy link

mdarke commented Mar 7, 2018

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

@ptrthomas ptrthomas self-assigned this Mar 8, 2018
@ptrthomas ptrthomas added the bug label Mar 8, 2018
@ptrthomas ptrthomas added this to the v0.7.1 milestone Mar 8, 2018
@ptrthomas
Copy link
Member

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

83a5814

@rahtr
Copy link

rahtr commented Mar 8, 2018

@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.

@YOU54F
Copy link
Author

YOU54F commented Mar 8, 2018

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

@ptrthomas
Copy link
Member

@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 ?

@YOU54F
Copy link
Author

YOU54F commented Mar 8, 2018

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 YOU54F changed the title 0.7.0 upgrade - nullPointerException with PATCH request. 0.7.0 upgrade - nullPointerException when performing request with missing or invalid basic auth credentials Mar 8, 2018
@ptrthomas
Copy link
Member

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

@YOU54F
Copy link
Author

YOU54F commented Mar 8, 2018

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!

@ptrthomas
Copy link
Member

@YOU54F great, thanks !

ptrthomas added a commit that referenced this issue Mar 8, 2018
@ptrthomas
Copy link
Member

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>

@ptrthomas ptrthomas added the fixed label Mar 8, 2018
@YOU54F
Copy link
Author

YOU54F commented Mar 8, 2018

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?

@ptrthomas
Copy link
Member

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

@ptrthomas
Copy link
Member

released 0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants