Skip to content

Commit 44348af

Browse files
authored
[Fix] Handle login.html incorrect validation for private link (#340)
## Changes 1. query returned can be null, however its not handled correctly 2. checking if query is null or not before checking for error code `private-link-validation-error` ## Tests Unit Tests
1 parent c9fb324 commit 44348af

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/PrivateLinkInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public String errorMessage() {
5353

5454
public static boolean isPrivateLinkRedirect(Response resp) {
5555
return resp.getUrl().getPath().equals("/login.html")
56-
&& resp.getUrl().getQuery().contains("error=private-link-validation-error");
56+
&& (resp.getUrl().getQuery() != null
57+
&& resp.getUrl().getQuery().contains("error=private-link-validation-error"));
5758
}
5859

5960
static PrivateLinkValidationError createPrivateLinkValidationError(Response resp) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.databricks.sdk.core.error;
2+
3+
import com.databricks.sdk.core.error.platform.*;
4+
import com.databricks.sdk.core.http.Request;
5+
import com.databricks.sdk.core.http.Response;
6+
import org.junit.jupiter.api.Test;
7+
8+
public class PrivateLinkInfoTest {
9+
@Test
10+
void testIsPrivateLinkRedirectWithLoginHtmlAndQueryParamSet() {
11+
Response response =
12+
new Response(
13+
new Request("GET", "https://example.com/login.html")
14+
.withQueryParam("error", "private-link-validation-error"),
15+
307,
16+
"Temporary Redirect",
17+
null);
18+
assert PrivateLinkInfo.isPrivateLinkRedirect(response) == true;
19+
}
20+
21+
@Test
22+
void testIsPrivateLinkRedirectWithLoginHtmlAndQueryParamNotSet() {
23+
Response response =
24+
new Response(
25+
new Request("GET", "https://example.com/login.html"), 307, "Temporary Redirect", null);
26+
assert PrivateLinkInfo.isPrivateLinkRedirect(response) == false;
27+
}
28+
29+
@Test
30+
void testIsPrivateLinkRedirectNotLoginPage() {
31+
Response response =
32+
new Response(
33+
new Request("GET", "https://example.com/not-login.html"),
34+
307,
35+
"Temporary Redirect",
36+
null);
37+
assert PrivateLinkInfo.isPrivateLinkRedirect(response) == false;
38+
}
39+
}

0 commit comments

Comments
 (0)