diff --git a/src/main/java/net/snowflake/client/core/SFLoginInput.java b/src/main/java/net/snowflake/client/core/SFLoginInput.java index 13a52604c..18ebfaa57 100644 --- a/src/main/java/net/snowflake/client/core/SFLoginInput.java +++ b/src/main/java/net/snowflake/client/core/SFLoginInput.java @@ -426,7 +426,11 @@ static boolean getBooleanValue(Object v) { String getHostFromServerUrl() throws SFException { URL url; try { - url = new URL(serverUrl); + if (!serverUrl.startsWith("http")) { + url = new URL("https://" + serverUrl); + } else { + url = new URL(serverUrl); + } } catch (MalformedURLException e) { throw new SFException( e, ErrorCode.INTERNAL_ERROR, "Invalid serverUrl for retrieving host name"); diff --git a/src/test/java/net/snowflake/client/core/SFLoginInputTest.java b/src/test/java/net/snowflake/client/core/SFLoginInputTest.java new file mode 100644 index 000000000..7d8a5b67b --- /dev/null +++ b/src/test/java/net/snowflake/client/core/SFLoginInputTest.java @@ -0,0 +1,22 @@ +package net.snowflake.client.core; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class SFLoginInputTest { + + @Test + public void testGetHostFromServerUrlWithoutProtocolShouldNotThrow() throws SFException { + SFLoginInput sfLoginInput = new SFLoginInput(); + sfLoginInput.setServerUrl("host.com:443"); + assertEquals("host.com", sfLoginInput.getHostFromServerUrl()); + } + + @Test + public void testGetHostFromServerUrlWithProtocolShouldNotThrow() throws SFException { + SFLoginInput sfLoginInput = new SFLoginInput(); + sfLoginInput.setServerUrl("https://host.com"); + assertEquals("host.com", sfLoginInput.getHostFromServerUrl()); + } +}