nastra commented on code in PR #14136:
URL: https://github.com/apache/iceberg/pull/14136#discussion_r2388406929


##########
azure/src/test/java/org/apache/iceberg/azure/TestAzureProperties.java:
##########
@@ -235,4 +240,76 @@ public void testAdlsToken() {
     verify(clientBuilder, 
never()).credential(any(StorageSharedKeyCredential.class));
     verify(clientBuilder, 
never()).credential(any(com.azure.identity.DefaultAzureCredential.class));
   }
+
+  @Test
+  public void testDefaultTokenCredentialProvider() {
+    // No SAS, no shared key, no explicit token, no refresh endpoint -> 
default token provider
+    AzureProperties props = new AzureProperties(ImmutableMap.of());
+
+    DataLakeFileSystemClientBuilder clientBuilder = 
mock(DataLakeFileSystemClientBuilder.class);
+
+    props.applyClientConfiguration("account", clientBuilder);
+
+    // Default provider should be DefaultAzureCredential
+    verify(clientBuilder).credential(any(DefaultAzureCredential.class));
+    verify(clientBuilder, never()).sasToken(any());
+    verify(clientBuilder, 
never()).credential(any(StorageSharedKeyCredential.class));
+  }
+
+  @Test
+  public void testCustomTokenCredentialProvider() {
+    ImmutableMap<String, String> properties =
+        ImmutableMap.<String, String>builder()
+            .put(
+                AzureProperties.ADLS_TOKEN_CREDENTIAL_PROVIDER,
+                
TestAzureProperties.DummyTokenCredentialProvider.class.getName())
+            .put(AzureProperties.ADLS_TOKEN_PROVIDER_PREFIX + "client-id", 
"clientId")
+            .put(AzureProperties.ADLS_TOKEN_PROVIDER_PREFIX + "client-secret", 
"clientSecret")
+            .put("custom.property", "custom.value")
+            .build();
+
+    AzureProperties props = new AzureProperties(properties);
+
+    DataLakeFileSystemClientBuilder clientBuilder = 
mock(DataLakeFileSystemClientBuilder.class);
+    ArgumentCaptor<TokenCredential> credentialCaptor =
+        ArgumentCaptor.forClass(TokenCredential.class);
+
+    props.applyClientConfiguration("account", clientBuilder);
+
+    verify(clientBuilder).credential(credentialCaptor.capture());
+    TokenCredential credential = credentialCaptor.getValue();
+    assertThat(credential).isInstanceOf(DummyTokenCredential.class);
+
+    // Provider should receive only prefixed properties, with prefix stripped
+    assertThat(DummyTokenCredentialProvider.lastInitializedProperties)
+        .containsEntry("client-id", "clientId")
+        .containsEntry("client-secret", "clientSecret")
+        .doesNotContainKey("custom.property")
+        .doesNotContainKey(AzureProperties.ADLS_TOKEN_CREDENTIAL_PROVIDER);
+
+    verify(clientBuilder, never()).sasToken(any());
+    verify(clientBuilder, 
never()).credential(any(StorageSharedKeyCredential.class));
+  }
+
+  // Helper classes for custom provider testing
+  static class DummyTokenCredential implements TokenCredential {
+    @Override
+    public Mono<AccessToken> getToken(TokenRequestContext request) {
+      return Mono.just(new AccessToken("dummy", 
OffsetDateTime.now(ZoneOffset.UTC).plusHours(1)));
+    }
+  }
+
+  static class DummyTokenCredentialProvider implements 
AdlsTokenCredentialProvider {
+    static Map<String, String> lastInitializedProperties;

Review Comment:
   why not just call this `properties`?



##########
azure/src/test/java/org/apache/iceberg/azure/TestAzureProperties.java:
##########
@@ -235,4 +240,76 @@ public void testAdlsToken() {
     verify(clientBuilder, 
never()).credential(any(StorageSharedKeyCredential.class));
     verify(clientBuilder, 
never()).credential(any(com.azure.identity.DefaultAzureCredential.class));
   }
+
+  @Test
+  public void testDefaultTokenCredentialProvider() {
+    // No SAS, no shared key, no explicit token, no refresh endpoint -> 
default token provider
+    AzureProperties props = new AzureProperties(ImmutableMap.of());
+
+    DataLakeFileSystemClientBuilder clientBuilder = 
mock(DataLakeFileSystemClientBuilder.class);
+
+    props.applyClientConfiguration("account", clientBuilder);
+
+    // Default provider should be DefaultAzureCredential
+    verify(clientBuilder).credential(any(DefaultAzureCredential.class));
+    verify(clientBuilder, never()).sasToken(any());
+    verify(clientBuilder, 
never()).credential(any(StorageSharedKeyCredential.class));
+  }
+
+  @Test
+  public void testCustomTokenCredentialProvider() {
+    ImmutableMap<String, String> properties =
+        ImmutableMap.<String, String>builder()
+            .put(
+                AzureProperties.ADLS_TOKEN_CREDENTIAL_PROVIDER,
+                
TestAzureProperties.DummyTokenCredentialProvider.class.getName())
+            .put(AzureProperties.ADLS_TOKEN_PROVIDER_PREFIX + "client-id", 
"clientId")
+            .put(AzureProperties.ADLS_TOKEN_PROVIDER_PREFIX + "client-secret", 
"clientSecret")
+            .put("custom.property", "custom.value")
+            .build();
+
+    AzureProperties props = new AzureProperties(properties);
+
+    DataLakeFileSystemClientBuilder clientBuilder = 
mock(DataLakeFileSystemClientBuilder.class);
+    ArgumentCaptor<TokenCredential> credentialCaptor =
+        ArgumentCaptor.forClass(TokenCredential.class);
+
+    props.applyClientConfiguration("account", clientBuilder);
+
+    verify(clientBuilder).credential(credentialCaptor.capture());
+    TokenCredential credential = credentialCaptor.getValue();
+    assertThat(credential).isInstanceOf(DummyTokenCredential.class);
+
+    // Provider should receive only prefixed properties, with prefix stripped
+    assertThat(DummyTokenCredentialProvider.lastInitializedProperties)
+        .containsEntry("client-id", "clientId")
+        .containsEntry("client-secret", "clientSecret")
+        .doesNotContainKey("custom.property")
+        .doesNotContainKey(AzureProperties.ADLS_TOKEN_CREDENTIAL_PROVIDER);
+
+    verify(clientBuilder, never()).sasToken(any());
+    verify(clientBuilder, 
never()).credential(any(StorageSharedKeyCredential.class));
+  }
+
+  // Helper classes for custom provider testing

Review Comment:
   can be removed



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to