diqiu50 commented on code in PR #11155:
URL: https://github.com/apache/gravitino/pull/11155#discussion_r3272669572
##########
core/src/test/java/org/apache/gravitino/credential/TestCredentialOperationDispatcher.java:
##########
@@ -97,4 +103,71 @@ public boolean supportsScheme(String scheme) {
Assertions.assertEquals(Set.of("s3://bucket/a"),
filteredPathBased.getWritePaths());
Assertions.assertEquals(Set.of("s3a://bucket/c"),
filteredPathBased.getReadPaths());
}
+
+ @Test
+ public void testGetCredentialsSkipsNullCredential() throws Exception {
+ String nullType = "null-type";
+ String validType = "valid-type";
+
+ CredentialProvider nullProvider = mockCredentialProvider(nullType);
+ CredentialProvider validProvider = mockCredentialProvider(validType);
+
+ Credential validCredential = Mockito.mock(Credential.class);
+
+ CatalogCredentialManager credentialManager =
Mockito.mock(CatalogCredentialManager.class);
+ Mockito.when(credentialManager.getCredentialProvider(nullType))
+ .thenReturn(Optional.of(nullProvider));
+ Mockito.when(credentialManager.getCredentialProvider(validType))
+ .thenReturn(Optional.of(validProvider));
+ Mockito.when(
+ credentialManager.getCredential(
+ Mockito.eq(nullType), Mockito.any(CredentialContext.class)))
+ .thenReturn(Optional.empty());
+ Mockito.when(
+ credentialManager.getCredential(
+ Mockito.eq(validType), Mockito.any(CredentialContext.class)))
+ .thenReturn(Optional.of(validCredential));
+
+ CatalogOperations ops =
+ Mockito.mock(
+ CatalogOperations.class,
+
Mockito.withSettings().extraInterfaces(SupportsPathBasedCredentials.class));
+ Mockito.when(
+ ((SupportsPathBasedCredentials)
ops).getPathContext(Mockito.any(NameIdentifier.class)))
+ .thenReturn(
+ Arrays.asList(
+ new PathContext("s3://bucket/a", nullType),
+ new PathContext("s3://bucket/b", validType)));
+
+ BaseCatalog<?> baseCatalog = Mockito.mock(BaseCatalog.class);
+
Mockito.when(baseCatalog.catalogCredentialManager()).thenReturn(credentialManager);
+ Mockito.when(baseCatalog.ops()).thenReturn(ops);
+
+ CredentialOperationDispatcher dispatcher =
+ new CredentialOperationDispatcher(catalogManager, entityStore,
idGenerator);
+
+ Method method =
+ CredentialOperationDispatcher.class.getDeclaredMethod(
+ "getCredentials", BaseCatalog.class, NameIdentifier.class,
CredentialPrivilege.class);
+ method.setAccessible(true);
Review Comment:
Why don’t we call dispatcher.getCredentials() directly?
##########
core/src/main/java/org/apache/gravitino/credential/CredentialCache.java:
##########
@@ -46,8 +47,13 @@ public CredentialExpireTimeCalculator(double
credentialCacheExpireRatio) {
// Set expire time after add a credential in the cache.
@Override
- public long expireAfterCreate(T key, Credential credential, long
currentTime) {
- long credentialExpireTime = credential.expireTimeInMs();
+ public long expireAfterCreate(T key, Optional<Credential> credential, long
currentTime) {
+ // Do not cache the absence of a credential, expire it immediately.
+ if (!credential.isPresent()) {
+ return 0;
+ }
Review Comment:
Add a test to cover this case.
--
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]