Skip to content

Commit

Permalink
Handle login.html incorrect validation for PL
Browse files Browse the repository at this point in the history
  • Loading branch information
satviksr-db committed Sep 3, 2024
1 parent c9fb324 commit 7c45a4b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,17 @@ public DatabricksConfig setAzureUseMsi(boolean azureUseMsi) {
return this;
}

/** @deprecated Use {@link #getAzureUseMsi()} instead. */
/**
* @deprecated Use {@link #getAzureUseMsi()} instead.
*/
@Deprecated()
public boolean getAzureUseMSI() {
return azureUseMsi;
}

/** @deprecated Use {@link #setAzureUseMsi(boolean)} instead. */
/**
* @deprecated Use {@link #setAzureUseMsi(boolean)} instead.
*/
@Deprecated
public DatabricksConfig setAzureUseMSI(boolean azureUseMsi) {
this.azureUseMsi = azureUseMsi;
Expand Down
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 7c45a4b

Please sign in to comment.