justinmclean opened a new issue, #8087:
URL: https://github.com/apache/gravitino/issues/8087

   ### What would you like to be improved?
   
   Fix OAuth2 token provider to automatically fetch a new token when the 
current one is missing or expired, avoiding null returns and authentication 
failures.
   
   Here's a unit test that will help:
   ```
   @Test
     public void testFetchTokenWhenNull() throws Exception {
       HTTPClient client = mock(HTTPClient.class);
       OAuth2TokenResponse response = new OAuth2TokenResponse("new_token", 
null, "bearer", 1, null, null);
       when(client.postForm(anyString(), anyMap(), any(), anyMap(), 
any())).thenReturn(response);
   
       DefaultOAuth2TokenProvider provider = newProvider(client);
   
       String token = provider.getAccessToken();
       Assertions.assertEquals("new_token", token);
       verify(client).postForm(anyString(), anyMap(), any(), anyMap(), any());
     }
   
     private DefaultOAuth2TokenProvider newProvider(HTTPClient client) throws 
Exception {
       Constructor<DefaultOAuth2TokenProvider> ctor =
           DefaultOAuth2TokenProvider.class.getDeclaredConstructor();
       ctor.setAccessible(true);
       DefaultOAuth2TokenProvider provider = ctor.newInstance();
   
       Field clientField = OAuth2TokenProvider.class.getDeclaredField("client");
       clientField.setAccessible(true);
       clientField.set(provider, client);
   
       Field credentialField = 
DefaultOAuth2TokenProvider.class.getDeclaredField("credential");
       credentialField.setAccessible(true);
       credentialField.set(provider, "cred");
   
       Field scopeField = 
DefaultOAuth2TokenProvider.class.getDeclaredField("scope");
       scopeField.setAccessible(true);
       scopeField.set(provider, "scope");
   
       Field pathField = 
DefaultOAuth2TokenProvider.class.getDeclaredField("path");
       pathField.setAccessible(true);
       pathField.set(provider, "/token");
   
       Field tokenField = 
DefaultOAuth2TokenProvider.class.getDeclaredField("token");
       tokenField.setAccessible(true);
       tokenField.set(provider, null);
       return provider;
     }
   ```
   
   ### How should we improve?
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to