eoinmcdonnell113 commented on code in PR #1232:
URL: https://github.com/apache/ranger/pull/1232#discussion_r4212088934


##########
security-admin/src/main/java/org/apache/ranger/biz/ServiceMgr.java:
##########
@@ -741,6 +752,41 @@ private VXResponse generateResponseForTestConn(Map<String, 
Object> responseData,
         return vXResponse;
     }
 
+    /**
+     * Returns true when Test Connection failure text would disclose whether a 
host/port is reachable
+     * (for example Connection refused vs timeout), which can be used as a 
lightweight port probe.
+     */
+    static boolean disclosesHostPortReachability(String... texts) {
+        if (texts == null) {
+            return false;
+        }
+
+        for (String text : texts) {
+            if (StringUtils.isBlank(text)) {
+                continue;
+            }
+
+            String normalized = text.toLowerCase();
+
+            if (normalized.contains("connection refused")
+                    || normalized.contains("connectexception")
+                    || normalized.contains("unknownhostexception")
+                    || normalized.contains("noroutetohostexception")
+                    || normalized.contains("no route to host")
+                    || normalized.contains("network is unreachable")
+                    || normalized.contains("sockettimeoutexception")
+                    || normalized.contains("socketexception")
+                    || normalized.contains("connection timed out")
+                    || normalized.contains("connect timed out")
+                    || normalized.contains("connection reset")
+                    || normalized.contains("connection reset by peer")) {

Review Comment:
   Done. Removed the redundant "connection reset by peer" pattern (covered by 
"connection reset"), and refactored to a HOST_PORT_REACHABILITY_PATTERNS list 
with a stream-based match using Locale.ROOT. Kept an early null check so we 
don't NPE on null texts.



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