Copilot commented on code in PR #2894:
URL: https://github.com/apache/tika/pull/2894#discussion_r3437169830


##########
tika-pipes/tika-pipes-plugins/tika-pipes-solr/src/main/java/org/apache/tika/pipes/plugin/solr/SolrClientHelper.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+package org.apache.tika.pipes.plugin.solr;
+
+import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
+
+import org.apache.tika.client.HttpClientFactory;
+import org.apache.tika.exception.TikaConfigException;
+import org.apache.tika.utils.StringUtils;
+
+public final class SolrClientHelper {
+
+    private SolrClientHelper() {}
+
+    /**
+     * Applies authentication and proxy settings to a {@link 
HttpJettySolrClient.Builder}.
+     * Only basic auth is supported; a non-basic auth scheme will throw {@link 
TikaConfigException}.
+     * Proxy is only configured when both host and a positive port are present 
on the factory.
+     */

Review Comment:
   `applyAuthAndProxy` introduces non-trivial config behavior (rejecting 
non-basic auth schemes; proxy only when host+port are set) but there are no 
unit tests directly asserting these edge cases. Adding a small test suite would 
help prevent regressions, especially as SolrJ/Jetty upgrade churn continues.



##########
tika-pipes/tika-pipes-plugins/tika-pipes-solr/src/main/java/org/apache/tika/pipes/plugin/solr/SolrClientHelper.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+package org.apache.tika.pipes.plugin.solr;
+
+import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
+
+import org.apache.tika.client.HttpClientFactory;
+import org.apache.tika.exception.TikaConfigException;
+import org.apache.tika.utils.StringUtils;
+
+public final class SolrClientHelper {
+
+    private SolrClientHelper() {}
+
+    /**
+     * Applies authentication and proxy settings to a {@link 
HttpJettySolrClient.Builder}.
+     * Only basic auth is supported; a non-basic auth scheme will throw {@link 
TikaConfigException}.
+     * Proxy is only configured when both host and a positive port are present 
on the factory.
+     */
+    public static void applyAuthAndProxy(HttpJettySolrClient.Builder builder,
+                                         HttpClientFactory factory) throws 
TikaConfigException {
+        if (!StringUtils.isBlank(factory.getUserName())) {
+            if (!"basic".equalsIgnoreCase(factory.getAuthScheme())) {
+                throw new TikaConfigException(
+                        "Only 'basic' auth scheme is supported by 
HttpJettySolrClient; got: '"
+                                + factory.getAuthScheme() + "'");
+            }
+            builder.withBasicAuthCredentials(factory.getUserName(), 
factory.getPassword());
+        }
+        if (!StringUtils.isBlank(factory.getProxyHost()) && 
factory.getProxyPort() > 0) {
+            builder.withProxyConfiguration(factory.getProxyHost(), 
factory.getProxyPort(), false, false);
+        }
+    }

Review Comment:
   The Javadoc says a non-basic auth scheme will throw, but the current logic 
only throws when a username is configured. If `authScheme` is set to something 
else (e.g., "ntlm") but username is blank/missing, the config will silently 
proceed and requests will be unauthenticated rather than failing fast. Consider 
validating `authScheme` independently of username so unsupported schemes are 
always rejected (per the method contract/PR description).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to