HTTPCLIENT-2077: Authentication failure due to incorrect NTLM auth value check (#223)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMScheme.java
index e8ca14f..1b1beb3 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMScheme.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMScheme.java
@@ -99,9 +99,7 @@
final AuthChallenge authChallenge,
final HttpContext context) throws MalformedChallengeException {
Args.notNull(authChallenge, "AuthChallenge");
- if (authChallenge.getValue() == null) {
- throw new MalformedChallengeException("Missing auth challenge");
- }
+
this.challenge = authChallenge.getValue();
if (this.challenge == null || this.challenge.isEmpty()) {
if (this.state == State.UNINITIATED) {
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestNTLMScheme.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestNTLMScheme.java
new file mode 100644
index 0000000..42761a5
--- /dev/null
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestNTLMScheme.java
@@ -0,0 +1,55 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.impl.auth;
+
+import org.apache.hc.client5.http.auth.AuthChallenge;
+import org.apache.hc.client5.http.auth.AuthScheme;
+import org.apache.hc.client5.http.auth.ChallengeType;
+import org.apache.hc.client5.http.auth.StandardAuthScheme;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link NTLMScheme}.
+ */
+public class TestNTLMScheme {
+
+ @Test
+ public void testNTLMAuthenticationEmptyProxyChallenge() throws Exception {
+ final AuthChallenge authChallenge = new AuthChallenge(ChallengeType.PROXY, StandardAuthScheme.NTLM);
+ final AuthScheme authScheme = new NTLMScheme();
+ authScheme.processChallenge(authChallenge, null);
+
+ Assert.assertFalse(
+ "Challenge with an empty value received from NTML proxy must not interrupt authentication process.",
+ authScheme.isChallengeComplete());
+ Assert.assertTrue(
+ "Challenge with an empty value received from NTML proxy must transit status of NTLMScheme to CHALLENGE_RECEIVED.",
+ authScheme.toString().contains(NTLMScheme.State.CHALLENGE_RECEIVED.toString()));
+ }
+}
\ No newline at end of file