Skip to content

Commit

Permalink
SNOW-1460355: Fix getHostFromServerUrl (#1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa authored Jun 10, 2024
1 parent a79f58d commit e66fae5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/net/snowflake/client/core/SFLoginInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/net/snowflake/client/core/SFLoginInputTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit e66fae5

Please sign in to comment.