-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issue #3479 where S3ForcePathStyle is unable to be read from a …
…credential profile
- Loading branch information
1 parent
ad13fd4
commit b808075
Showing
5 changed files
with
158 additions
and
5 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
generator/.DevConfigs/666f52b5-8ab6-4817-b54c-f42d2d41bb46.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"core": { | ||
"changeLogMessages": [ | ||
"Add S3ForcePathStyle as a config option in for credential profiles." | ||
], | ||
"type": "patch", | ||
"updateMinimum": true | ||
}, | ||
"services": [ | ||
{ | ||
"serviceName": "S3", | ||
"type": "patch", | ||
"changeLogMessages": [ | ||
"Fixes [issue 3479](https://github.com/aws/aws-sdk-net/issues/3479) where ForcePathStyle is unable to be read from the config file" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
sdk/test/Services/S3/UnitTests/Custom/S3ForcePathStyleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Amazon.S3; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.IO; | ||
using AWSSDK_DotNet.CommonTest.Utils; | ||
using Amazon.Runtime.CredentialManagement; | ||
|
||
namespace AWSSDK.UnitTests | ||
{ | ||
[TestClass] | ||
public class S3ForcePathStyleTests | ||
{ | ||
private static readonly string ProfileText = | ||
@"[enable_force_path_style] | ||
region = us-west-2 | ||
aws_access_key_id = default_aws_access_key_id | ||
aws_secret_access_key = default_aws_secret_access_key | ||
s3_force_path_style = true | ||
[disable_force_path_style] | ||
region = us-west-2 | ||
aws_access_key_id = other_aws_access_key_id | ||
aws_secret_access_key = other_aws_secret_access_key | ||
s3_force_path_style = false"; | ||
|
||
private const string AWSProfileVariable = "AWS_PROFILE"; | ||
private string _beginningAWSProfileEnvironmentValue; | ||
private string _tempCredentialsFilePath; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
// Save off current environment variable value to restore later | ||
_beginningAWSProfileEnvironmentValue = Environment.GetEnvironmentVariable(AWSProfileVariable); | ||
|
||
// Then clear the current value so every test is starting from a clean slate | ||
Environment.SetEnvironmentVariable(AWSProfileVariable, ""); | ||
|
||
// set credentials file and use it to load CredentialProfileStoreChain | ||
_tempCredentialsFilePath = Path.GetTempFileName(); | ||
File.WriteAllText(_tempCredentialsFilePath, ProfileText); | ||
ReflectionHelpers.Invoke(typeof(AmazonS3Config), "credentialProfileChain", new CredentialProfileStoreChain(_tempCredentialsFilePath)); | ||
ReflectionHelpers.Invoke(typeof(AmazonS3Config), "_triedToResolveProfile", false); | ||
} | ||
|
||
[TestCleanup] | ||
public void RestoreOriginalSettings() | ||
{ | ||
Environment.SetEnvironmentVariable(AWSProfileVariable, _beginningAWSProfileEnvironmentValue); | ||
File.Delete(_tempCredentialsFilePath); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("S3")] | ||
public void CredentialProfileEnable_ShouldApplyToS3Config() | ||
{ | ||
Environment.SetEnvironmentVariable(AWSProfileVariable, "enable_force_path_style"); | ||
var config = new AmazonS3Config(); | ||
Assert.IsTrue(config.ForcePathStyle); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("S3")] | ||
public void UnsetForcePathStyleShouldDefaultToFalse() | ||
{ | ||
var config = new AmazonS3Config(); | ||
Assert.IsFalse(config.ForcePathStyle); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("S3")] | ||
public void ConfigShouldOverrideProfile() | ||
{ | ||
Environment.SetEnvironmentVariable(AWSProfileVariable, "enable_force_path_style"); | ||
var config = new AmazonS3Config | ||
{ | ||
ForcePathStyle = false | ||
}; | ||
Assert.IsFalse(config.ForcePathStyle); | ||
} | ||
} | ||
} |