Skip to content

Commit

Permalink
[Fix] Handle login.html incorrect validation for private link (#340)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
satviksr-db authored Sep 3, 2024
1 parent c9fb324 commit 44348af
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public String errorMessage() {

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

static PrivateLinkValidationError createPrivateLinkValidationError(Response resp) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.databricks.sdk.core.error;

import com.databricks.sdk.core.error.platform.*;
import com.databricks.sdk.core.http.Request;
import com.databricks.sdk.core.http.Response;
import org.junit.jupiter.api.Test;

public class PrivateLinkInfoTest {
@Test
void testIsPrivateLinkRedirectWithLoginHtmlAndQueryParamSet() {
Response response =
new Response(
new Request("GET", "https://example.com/login.html")
.withQueryParam("error", "private-link-validation-error"),
307,
"Temporary Redirect",
null);
assert PrivateLinkInfo.isPrivateLinkRedirect(response) == true;
}

@Test
void testIsPrivateLinkRedirectWithLoginHtmlAndQueryParamNotSet() {
Response response =
new Response(
new Request("GET", "https://example.com/login.html"), 307, "Temporary Redirect", null);
assert PrivateLinkInfo.isPrivateLinkRedirect(response) == false;
}

@Test
void testIsPrivateLinkRedirectNotLoginPage() {
Response response =
new Response(
new Request("GET", "https://example.com/not-login.html"),
307,
"Temporary Redirect",
null);
assert PrivateLinkInfo.isPrivateLinkRedirect(response) == false;
}
}

0 comments on commit 44348af

Please sign in to comment.