Bug 65363 - NullPointerException in HTTPHC4Impl$ManagedCredentialsProvider.getAuthorizationForAuthScope when 401 response from remote and httpclient4.auth.preemptive=false
Summary: NullPointerException in HTTPHC4Impl$ManagedCredentialsProvider.getAuthorizati...
Status: NEEDINFO
Alias: None
Product: JMeter
Classification: Unclassified
Component: HTTP (show other bugs)
Version: 5.4.1
Hardware: PC Mac OS X 10.1
: P2 normal (vote)
Target Milestone: JMETER_5.5
Assignee: JMeter issues mailing list
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2021-06-07 12:20 UTC by Peter Lynch
Modified: 2021-06-07 19:48 UTC (History)
0 users



Attachments
JMeter test file issue reproduce case (5.38 KB, application/xml)
2021-06-07 12:20 UTC, Peter Lynch
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Lynch 2021-06-07 12:20:38 UTC
Created attachment 37892 [details]
JMeter test file issue reproduce case

1. Configure jmeter property to turn off pre-emptive auth. ( httpclient4.auth.preemptive=false )
2. Have a server endpoint return 401 challenge to a request. ( in my example jmeter test, the endpoint is http://httpbin.org/basic-auth/admin/admin123 )
3. Execute the attached example JMeter test case that sends a single request to the server endpoint.
4. In the View Results Tree, select the sampler result tree node which indicates an error.

Problem 1: On the Sampler result tab, notice that the sampler result indicates something not helpful to end user. The following:

Response code:Non HTTP response code: java.lang.NullPointerException
Response message:Non HTTP response message: null

Expected: Response code should be 401 as that is what was actually returned by the server.

Problem 2: on the Response data tab, Response headers tab, there are no response headers from the 401 response.

Expected: there should be all the response headers that were returned by the server.

Problem 3: Select the "Valid Response Codes" assertion node in the View Results Tree. The "Assertion result" tab shows the following message:

Assertion error:false
Assertion failure:true
Assertion failure message:Test failed: code expected something using /

****** received  : [[[Non HTTP response code: java.lang.NullPointerException]]]

****** comparison: [[[200                                                   ]]]

Expected: Instead the "received" section should show the 401 status code


-----------------

Examining jmeter DEBUG logs we see the following stack trace at DEBUG level:

2021-06-07 09:13:35,074 DEBUG o.a.j.p.h.s.HTTPHC4Impl: RuntimeException
java.lang.NullPointerException: null
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl$ManagedCredentialsProvider.getAuthorizationForAuthScope(HTTPHC4Impl.java:252) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl$ManagedCredentialsProvider.getCredentials(HTTPHC4Impl.java:233) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.http.impl.client.AuthenticationStrategyImpl.select(AuthenticationStrategyImpl.java:197) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.http.impl.client.TargetAuthenticationStrategy.select(TargetAuthenticationStrategy.java:44) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.http.impl.auth.HttpAuthenticator.handleAuthChallenge(HttpAuthenticator.java:151) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.http.impl.execchain.MainClientExec.needAuthentication(MainClientExec.java:588) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:293) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[httpclient-4.5.12.jar:4.5.12]
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:935) ~[ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:646) [ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:66) [ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1296) [ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1285) [ApacheJMeter_http.jar:5.4.1]
	at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:638) [ApacheJMeter_core.jar:?]
	at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558) [ApacheJMeter_core.jar:?]
	at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:?]
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:?]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_275]


Expected: Avoid the NullPointerException on no auth manager present to process the server challenge. Instead propagate the actual response code returned by the server.


This bug seems to have been introduced by the fix for bug 64267.
Comment 1 Felix Schumacher 2021-06-07 19:48:34 UTC
Thanks for the detailed report and the test plan. I have added a guard to check for the missing auth manager. It would be great, if you could test a build from trunk and report back.

commit 975906ca28ece489706c2eeb5e4d6e1a125aa961
AuthorDate: Mon Jun 7 21:20:59 2021 +0200

    NullPointerException in HTTPHC4Impl$ManagedCredentialsProvider.getAuthorizationForAuthScope
    
    when 401 response from remote and httpclient4.auth.preemptive=false
    and no AuthManager is configured.
    
    Bugzilla Id: 65363
---
 .../java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java     | 4 ++++
 xdocs/changes.xml                                                     | 1 +
 2 files changed, 5 insertions(+)