|
13 | 13 | * permissions and limitations under the License.
|
14 | 14 | */
|
15 | 15 |
|
| 16 | +using Amazon; |
16 | 17 | using Amazon.Runtime;
|
17 | 18 | using Amazon.Runtime.CredentialManagement;
|
18 | 19 | using Amazon.Runtime.Credentials;
|
| 20 | +using Amazon.S3; |
19 | 21 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
20 | 22 | using System;
|
21 | 23 |
|
@@ -88,5 +90,31 @@ public void CredentialsAreReevaluatedWhenProfileChanges()
|
88 | 90 | Environment.SetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE, "non-existent-profile");
|
89 | 91 | Assert.ThrowsException<ProfileNotFoundException>(() => identityResolver.ResolveIdentity(clientConfig: null));
|
90 | 92 | }
|
| 93 | + |
| 94 | + /// <summary> |
| 95 | + /// Reported in https://github.com/aws/aws-sdk-net/issues/4028 |
| 96 | + /// <para /> |
| 97 | + /// If the name property in the "Profile" property is not set (which can happen when its value |
| 98 | + /// is only set in a non-production environment), the resolver should not throw an exception and |
| 99 | + /// move to the next provider in the chain (which in this test will be the access / secret key pair |
| 100 | + /// set in the environment variables). |
| 101 | + /// </summary> |
| 102 | + [DataTestMethod] |
| 103 | + [DataRow("")] |
| 104 | + [DataRow(null)] |
| 105 | + public void CredentialsResolver_HandlesEmptyProfileNameInConfig(string profileName) |
| 106 | + { |
| 107 | + Environment.SetEnvironmentVariable(EnvironmentVariablesAWSCredentials.ENVIRONMENT_VARIABLE_ACCESSKEY, "foo"); |
| 108 | + Environment.SetEnvironmentVariable(EnvironmentVariablesAWSCredentials.ENVIRONMENT_VARIABLE_SECRETKEY, "bar"); |
| 109 | + |
| 110 | + var identityResolver = new DefaultAWSCredentialsIdentityResolver(); |
| 111 | + var resolvedIdentity = identityResolver.ResolveIdentity(new AmazonS3Config |
| 112 | + { |
| 113 | + Profile = new Profile(profileName) |
| 114 | + }); |
| 115 | + |
| 116 | + Assert.IsNotNull(resolvedIdentity); |
| 117 | + Assert.IsTrue(resolvedIdentity is EnvironmentVariablesAWSCredentials); |
| 118 | + } |
91 | 119 | }
|
92 | 120 | }
|
0 commit comments