-
Notifications
You must be signed in to change notification settings - Fork 865
/
Copy pathS3ForcePathStyleTests.cs
81 lines (72 loc) · 3.01 KB
/
S3ForcePathStyleTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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);
}
}
}