dannycranmer commented on a change in pull request #12944:
URL: https://github.com/apache/flink/pull/12944#discussion_r475410998



##########
File path: 
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/util/AwsV2UtilTest.java
##########
@@ -0,0 +1,407 @@
+/*
+ * 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.flink.streaming.connectors.kinesis.util;
+
+import org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants;
+import 
org.apache.flink.streaming.connectors.kinesis.config.ConsumerConfigConstants;
+
+import com.amazonaws.ClientConfiguration;
+import com.amazonaws.ClientConfigurationFactory;
+import org.junit.Test;
+import software.amazon.awssdk.auth.credentials.AwsCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import 
software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
+import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
+import 
software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider;
+import 
software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider;
+import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
+import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
+import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
+import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.kinesis.KinesisAsyncClientBuilder;
+import 
software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider;
+
+import java.net.URI;
+import java.nio.file.Paths;
+import java.time.Duration;
+import java.util.Properties;
+
+import static 
org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants.AWS_CREDENTIALS_PROVIDER;
+import static 
org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants.AWS_REGION;
+import static 
org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants.roleArn;
+import static 
org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants.roleSessionName;
+import static 
org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants.webIdentityTokenFile;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link AwsV2Util}.
+ */
+public class AwsV2UtilTest {
+
+       @Test
+       public void testGetCredentialsProviderEnvironmentVariables() {
+               Properties properties = properties(AWS_CREDENTIALS_PROVIDER, 
"ENV_VAR");
+
+               AwsCredentialsProvider credentialsProvider = 
AwsV2Util.getCredentialsProvider(properties);
+
+               assertTrue(credentialsProvider instanceof 
EnvironmentVariableCredentialsProvider);
+       }
+
+       @Test
+       public void testGetCredentialsProviderSystemProperties() {
+               Properties properties = properties(AWS_CREDENTIALS_PROVIDER, 
"SYS_PROP");
+
+               AwsCredentialsProvider credentialsProvider = 
AwsV2Util.getCredentialsProvider(properties);
+
+               assertTrue(credentialsProvider instanceof 
SystemPropertyCredentialsProvider);
+       }
+
+       @Test
+       public void 
testGetCredentialsProviderWebIdentityTokenFileCredentialsProvider() {
+               Properties properties = properties(AWS_CREDENTIALS_PROVIDER, 
"WEB_IDENTITY_TOKEN");
+
+               AwsCredentialsProvider credentialsProvider = 
AwsV2Util.getCredentialsProvider(properties);
+
+               assertTrue(credentialsProvider instanceof 
WebIdentityTokenFileCredentialsProvider);
+       }
+
+       @Test
+       public void testGetWebIdentityTokenFileCredentialsProvider() {
+               Properties properties = properties(AWS_CREDENTIALS_PROVIDER, 
"WEB_IDENTITY_TOKEN");
+               properties.setProperty(roleArn(AWS_CREDENTIALS_PROVIDER), 
"roleArn");
+               
properties.setProperty(roleSessionName(AWS_CREDENTIALS_PROVIDER), 
"roleSessionName");
+
+               WebIdentityTokenFileCredentialsProvider.Builder builder = 
mockWebIdentityTokenFileCredentialsProviderBuilder();

Review comment:
       @tzulitai I had a look at [one of the 
builders](https://github.com/aws/aws-sdk-java-v2/blob/master/core/auth/src/main/java/software/amazon/awssdk/auth/credentials/WebIdentityTokenFileCredentialsProvider.java),
 and unfortunately it does not have an `equals` implementation. That was a good 
idea though. 
   
   The other option is to create our own implementation of the builders. But 
that would be a lot of boilerplate and essentially doing the same thing Mockito 
does, albeit more verbose. I will assume we are leaving these as is, but let me 
know if you would like me to remove Mockito and implement test builders.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to