Skip to content

Commit c9fc008

Browse files
fix
1 parent 3dad770 commit c9fc008

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/ExternalBrowserCredentialsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public HeaderFactory configure(DatabricksConfig config) {
5353

5454
LOGGER.debug("Using cached token, will immediately refresh");
5555
cachedCreds.token = cachedCreds.refresh();
56-
tokenCache.save(cachedToken);
56+
tokenCache.save(cachedCreds.getToken());
5757
return cachedCreds.configure(config);
5858
} catch (Exception e) {
5959
// If token refresh fails, log and continue to browser auth

databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/ExternalBrowserCredentialsProviderTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.HashMap;
1919
import java.util.Map;
2020
import org.junit.jupiter.api.Test;
21+
import org.mockito.ArgumentCaptor;
2122
import org.mockito.Mockito;
2223

2324
public class ExternalBrowserCredentialsProviderTest {
@@ -264,6 +265,21 @@ void cacheWithValidTokenTest() throws IOException {
264265

265266
// Verify token was saved back to cache
266267
Mockito.verify(mockTokenCache, Mockito.times(1)).save(any(Token.class));
268+
269+
// Capture the token that was saved to cache to verify it's the refreshed token
270+
ArgumentCaptor<Token> tokenCaptor = ArgumentCaptor.forClass(Token.class);
271+
Mockito.verify(mockTokenCache).save(tokenCaptor.capture());
272+
Token savedToken = tokenCaptor.getValue();
273+
274+
// Verify the saved token contains the refreshed values from the HTTP response
275+
assertEquals(
276+
"refreshed_access_token",
277+
savedToken.getAccessToken(),
278+
"Should save refreshed access token to cache");
279+
assertEquals(
280+
"new_refresh_token",
281+
savedToken.getRefreshToken(),
282+
"Should save new refresh token to cache");
267283
}
268284

269285
@Test
@@ -326,6 +342,21 @@ void cacheWithInvalidAccessTokenValidRefreshTest() throws IOException {
326342

327343
// Verify token was saved back to cache
328344
Mockito.verify(mockTokenCache, Mockito.times(1)).save(any(Token.class));
345+
346+
// Capture the token that was saved to cache to verify it's the refreshed token
347+
ArgumentCaptor<Token> tokenCaptor = ArgumentCaptor.forClass(Token.class);
348+
Mockito.verify(mockTokenCache).save(tokenCaptor.capture());
349+
Token savedToken = tokenCaptor.getValue();
350+
351+
// Verify the saved token contains the refreshed values from the HTTP response
352+
assertEquals(
353+
"refreshed_access_token",
354+
savedToken.getAccessToken(),
355+
"Should save refreshed access token to cache");
356+
assertEquals(
357+
"new_refresh_token",
358+
savedToken.getRefreshToken(),
359+
"Should save new refresh token to cache");
329360
}
330361

331362
@Test

0 commit comments

Comments
 (0)