Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<immutables.value.version>2.9.2</immutables.value.version>
<httpclient.version>4.5.14</httpclient.version>
<commons-io.version>2.14.0</commons-io.version>
<databricks-sdk.version>0.31.1</databricks-sdk.version>
<databricks-sdk.version>0.37.0</databricks-sdk.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<sql-logic-test.version>0.3</sql-logic-test.version>
<lz4-compression.version>1.8.0</lz4-compression.version>
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/databricks/jdbc/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class TestConstants {
ByteBuffer.allocate(Long.BYTES).putLong(123456789L).array();
public static final String TEST_CLIENT_ID = "test-client-id";
public static final String TEST_TOKEN_URL = "https://test.token.url";
public static final String TEST_AUTH_URL = "https://test.auth.url";
public static final String TEST_DISCOVERY_URL = "https://test.discovery.url";
public static final String TEST_JWT_KID = "test-kid";
public static final String TEST_SCOPE = "test-scope";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.databricks.jdbc.auth;

import static com.databricks.jdbc.TestConstants.TEST_AUTH_URL;
import static com.databricks.jdbc.TestConstants.TEST_TOKEN_URL;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
Expand All @@ -11,11 +13,11 @@
import com.databricks.sdk.core.HeaderFactory;
import com.databricks.sdk.core.commons.CommonsHttpClient;
import com.databricks.sdk.core.http.Response;
import com.databricks.sdk.core.oauth.OAuthResponse;
import com.databricks.sdk.core.oauth.OpenIDConnectEndpoints;
import com.databricks.sdk.core.oauth.Token;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import org.apache.http.HttpHeaders;
Expand All @@ -34,6 +36,9 @@ public class OAuthRefreshCredentialsProviderTest {
@Mock DatabricksConfig databricksConfig;
@Mock CommonsHttpClient httpClient;
@Mock Response httpResponse;
@Mock OAuthResponse oAuthResponse;

@Mock Response response;
private OAuthRefreshCredentialsProvider credentialsProvider;
private static final String REFRESH_TOKEN_URL_DEFAULT =
"jdbc:databricks://host:4423/default;transportMode=http;ssl=1;AuthMech=11;AuthFlow=0;httpPath=/sql/1.0/warehouses/erg6767gg;OAuthRefreshToken=refresh-token";
Expand Down Expand Up @@ -89,27 +94,21 @@ void testRefreshSuccess(String refreshTokenUrl) throws Exception {
boolean isDefaultEndpointPath = connectionContext.getTokenEndpoint() == null;
if (isDefaultEndpointPath) {
when(databricksConfig.getOidcEndpoints())
.thenReturn(
new OpenIDConnectEndpoints(
"https://oauth.example.com/oidc/v1/token",
"https://oauth.example.com/oidc/v1/authorize"));
.thenReturn(new OpenIDConnectEndpoints(TEST_TOKEN_URL, TEST_AUTH_URL));
}
credentialsProvider = new OAuthRefreshCredentialsProvider(connectionContext, databricksConfig);

// Reinitialize the OAUTH_RESPONSE InputStream for each test run
InputStream oauthResponse =
new ByteArrayInputStream(
new JSONObject()
.put("access_token", "access-token")
.put("token_type", "token-type")
.put("expires_in", 360)
.put("refresh_token", "refresh-token")
.toString()
.getBytes());
String jsonResponse =
new JSONObject()
.put("access_token", "access-token")
.put("token_type", "token-type")
.put("expires_in", 360)
.put("refresh_token", "refresh-token")
.toString();

when(databricksConfig.getHttpClient()).thenReturn(httpClient);
when(httpClient.execute(any())).thenReturn(httpResponse);
when(httpResponse.getBody()).thenReturn(oauthResponse);
when(httpClient.execute(any())).thenReturn(new Response(jsonResponse, new URL(TEST_TOKEN_URL)));
HeaderFactory headerFactory = credentialsProvider.configure(databricksConfig);
Map<String, String> headers = headerFactory.headers();
assertNotNull(headers.get(HttpHeaders.AUTHORIZATION));
Expand Down
Loading