Пример #1
0
        public void TestDefaultProfile()
        {
            using (new FallbackFactoryTestFixture(ProfileText, null))
            {
                var creds = FallbackCredentialsFactory.GetCredentials();
                Assert.AreEqual("default_aws_access_key_id", creds.GetCredentials().AccessKey);

                var region = FallbackRegionFactory.GetRegionEndpoint(false);
                Assert.AreEqual(RegionEndpoint.USWest2, region);

                var enabled = FallbackEndpointDiscoveryEnabledFactory.GetEnabled();
                Assert.IsFalse(enabled.HasValue);

                enabled = FallbackInternalConfigurationFactory.EndpointDiscoveryEnabled;
                Assert.IsFalse(enabled.HasValue);

                var retryMode = FallbackInternalConfigurationFactory.RetryMode;
                Assert.IsFalse(retryMode.HasValue);

                var maxAttempts = FallbackInternalConfigurationFactory.MaxAttempts;
                Assert.IsFalse(maxAttempts.HasValue);
            }
        }
Пример #2
0
            public FallbackFactoryTestFixture(string sharedCredsFileContent, string awsProfileValue, Dictionary <string, string> newEnvironmentVariables = null)
            {
                sharedFixture = new SharedCredentialsFileTestFixture(sharedCredsFileContent);
                netSdkFixture = new NetSDKCredentialsFileTestFixture();

                originalCredsChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackCredentialsFactory), "credentialProfileChain");
                ReflectionHelpers.Invoke(typeof(FallbackCredentialsFactory), "credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath));

                originalRegionChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackRegionFactory), "credentialProfileChain");
                ReflectionHelpers.Invoke(typeof(FallbackRegionFactory), "credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath));

                originalEndpointDiscoveryEnabledChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackEndpointDiscoveryEnabledFactory), "credentialProfileChain");
                ReflectionHelpers.Invoke(typeof(FallbackEndpointDiscoveryEnabledFactory), "credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath));

                originalConfigurationChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackInternalConfigurationFactory), "_credentialProfileChain");
                ReflectionHelpers.Invoke(typeof(FallbackInternalConfigurationFactory), "_credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath));

                originalAWSProfileValue = Environment.GetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE);
                Environment.SetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE, awsProfileValue);

                if (newEnvironmentVariables != null)
                {
                    foreach (var envVariable in newEnvironmentVariables)
                    {
                        var originalValue = Environment.GetEnvironmentVariable(envVariable.Key);
                        Environment.SetEnvironmentVariable(envVariable.Key, envVariable.Value);
                        originalEnvironmentVariables.Add(envVariable.Key, originalValue);
                    }
                }

                // reset before use to ensure the new credentialProfileChains are used.
                FallbackCredentialsFactory.Reset();
                FallbackRegionFactory.Reset();
                FallbackEndpointDiscoveryEnabledFactory.Reset();
                FallbackInternalConfigurationFactory.Reset();
            }