From 61945d88b65c1126125aa91bb0caa01f18713d31 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Tue, 24 Sep 2024 16:23:56 -0700 Subject: [PATCH] fixed build Signed-off-by: Amardeepsingh Siglani --- .../notifications/spi/utils/ValidationHelpers.kt | 16 +++++++--------- .../core/utils/ValidationHelpers.kt | 10 +++++----- .../core/utils/ValidationHelpersTests.kt | 3 +++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/utils/ValidationHelpers.kt b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/utils/ValidationHelpers.kt index 1463b5f3..095ea3bf 100644 --- a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/utils/ValidationHelpers.kt +++ b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/utils/ValidationHelpers.kt @@ -5,11 +5,13 @@ package org.opensearch.notifications.spi.utils +import inet.ipaddr.HostName import inet.ipaddr.IPAddressString import org.apache.commons.validator.routines.DomainValidator import org.apache.hc.client5.http.classic.methods.HttpPatch import org.apache.hc.client5.http.classic.methods.HttpPost import org.apache.hc.client5.http.classic.methods.HttpPut +import org.apache.logging.log4j.LogManager import org.opensearch.core.common.Strings import org.opensearch.notifications.spi.utils.ValidationHelpers.FQDN_REGEX import java.net.InetAddress @@ -49,27 +51,23 @@ fun isValidUrl(urlString: String): Boolean { } } -"foobar.com" - - - fun isHostInDenylist(urlString: String, hostDenyList: List): Boolean { val url = URL(urlString) if (url.host != null) { - val resolvedIps = InetAddress.getAllByName(url.host); + val resolvedIps = InetAddress.getAllByName(url.host) val resolvedIpStrings = resolvedIps.map { inetAddress -> IPAddressString(inetAddress.hostAddress) } val hostStr = HostName(url.host) for (network in hostDenyList) { val denyIpStr = IPAddressString(network) val denyHostStr = HostName(network) - val hostInDenyList = denyHostStr.equals(hostStr); - var ipInDenyList = false; + val hostInDenyList = denyHostStr.equals(hostStr) + var ipInDenyList = false for (ipStr in resolvedIpStrings) { if (denyIpStr.contains(ipStr)) { - ipInDenyList = true; - break; + ipInDenyList = true + break } } diff --git a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/utils/ValidationHelpers.kt b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/utils/ValidationHelpers.kt index 59e9a63b..b72f3043 100644 --- a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/utils/ValidationHelpers.kt +++ b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/utils/ValidationHelpers.kt @@ -39,20 +39,20 @@ fun isValidUrl(urlString: String): Boolean { fun isHostInDenylist(urlString: String, hostDenyList: List): Boolean { val url = URL(urlString) if (url.host != null) { - val resolvedIps = InetAddress.getAllByName(url.host); + val resolvedIps = InetAddress.getAllByName(url.host) val resolvedIpStrings = resolvedIps.map { inetAddress -> IPAddressString(inetAddress.hostAddress) } val hostStr = HostName(url.host) for (network in hostDenyList) { val denyIpStr = IPAddressString(network) val denyHostStr = HostName(network) - val hostInDenyList = denyHostStr.equals(hostStr); - var ipInDenyList = false; + val hostInDenyList = denyHostStr.equals(hostStr) + var ipInDenyList = false for (ipStr in resolvedIpStrings) { if (denyIpStr.contains(ipStr)) { - ipInDenyList = true; - break; + ipInDenyList = true + break } } diff --git a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/utils/ValidationHelpersTests.kt b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/utils/ValidationHelpersTests.kt index 9944f6a1..ea58f783 100644 --- a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/utils/ValidationHelpersTests.kt +++ b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/utils/ValidationHelpersTests.kt @@ -5,8 +5,11 @@ package org.opensearch.notifications.core.utils +import io.mockk.every +import io.mockk.mockkStatic import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import java.net.InetAddress internal class ValidationHelpersTests {