Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"core": {
"changeLogMessages": [
"Fix regression in V4 where the credentials resolver would attempt to fetch a profile even when its name was empty or null (https://github.com/aws/aws-sdk-net/issues/4028)"
],
"type": "patch",
"updateMinimum": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ BaseIdentity IIdentityResolver.ResolveIdentity(IClientConfig clientConfig)
public AWSCredentials ResolveIdentity(IClientConfig clientConfig)
{
var profile = clientConfig?.Profile;
if (profile != null)
if (!string.IsNullOrEmpty(profile?.Name))
{
var source = new CredentialProfileStoreChain(profile.Location);
if (source.TryGetProfile(profile.Name, out CredentialProfile storedProfile))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
* permissions and limitations under the License.
*/

using Amazon;
using Amazon.Runtime;
using Amazon.Runtime.CredentialManagement;
using Amazon.Runtime.Credentials;
using Amazon.S3;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

Expand Down Expand Up @@ -88,5 +90,31 @@ public void CredentialsAreReevaluatedWhenProfileChanges()
Environment.SetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE, "non-existent-profile");
Assert.ThrowsException<ProfileNotFoundException>(() => identityResolver.ResolveIdentity(clientConfig: null));
}

/// <summary>
/// Reported in https://github.com/aws/aws-sdk-net/issues/4028
/// <para />
/// If the name property in the "Profile" property is not set (which can happen when its value
/// is only set in a non-production environment), the resolver should not throw an exception and
/// move to the next provider in the chain (which in this test will be the access / secret key pair
/// set in the environment variables).
/// </summary>
[DataTestMethod]
[DataRow("")]
[DataRow(null)]
public void CredentialsResolver_HandlesEmptyProfileNameInConfig(string profileName)
{
Environment.SetEnvironmentVariable(EnvironmentVariablesAWSCredentials.ENVIRONMENT_VARIABLE_ACCESSKEY, "foo");
Environment.SetEnvironmentVariable(EnvironmentVariablesAWSCredentials.ENVIRONMENT_VARIABLE_SECRETKEY, "bar");

var identityResolver = new DefaultAWSCredentialsIdentityResolver();
var resolvedIdentity = identityResolver.ResolveIdentity(new AmazonS3Config
{
Profile = new Profile(profileName)
});

Assert.IsNotNull(resolvedIdentity);
Assert.IsTrue(resolvedIdentity is EnvironmentVariablesAWSCredentials);
}
}
}