creste commented on code in PR #5953:
URL: https://github.com/apache/hadoop/pull/5953#discussion_r1453634534


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/oauth2/WorkloadIdentityTokenProvider.java:
##########
@@ -0,0 +1,109 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.azurebfs.oauth2;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.hadoop.thirdparty.com.google.common.base.Strings;
+import org.apache.hadoop.util.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.io.FileUtils;
+
+
+/**
+ * Provides tokens based on Azure AD Workload Identity.
+ */
+public class WorkloadIdentityTokenProvider extends AccessTokenProvider {

Review Comment:
   I understand the request, but I don't see a reasonable way to mock the code 
for a unit test of `AccessTokenProvider`.  Note that 
`AccessTokenProvider.getToken()` calls 
`WorkloadIdentityProvider.refreshToken()`, which calls 
[`AzureADAuthenticator.getTokenUsingJWTAssertion()`](https://github.com/apache/hadoop/pull/5953/files#diff-dff9c93d1668203c206aa1c092aef9d2921dc6e20af8888d06fae34778991531R135),
 which is a static method that eventually makes HTTP requests. That is a 
problem because:
   - All unit tests currently use Mockito version 2.28.2, which does not 
support mocking static methods. 
   - The 
[TestAzureADAuthenticator](https://github.com/apache/hadoop/blob/d37885379009d515fcee33056b9b8b1a7392a40b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAzureADAuthenticator.java#L38)
 unit tests do not show how to mock the HTTP requests made by 
`AzureADAuthenticator`.
   
   Without a way to mock the calls made by 
`WorkloadIdentityProvider.refreshToken()` or 
`AzureADAuthenticator.getTokenUsingJWTAssertion()`, all unit tests will try to 
make real HTTP requests which will always fail.
   
   Do you have any ideas on how to work around the limitations of the code to 
implement the desired unit test?



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