/// Ensure that the STS Regional Flag is set according to the value /// in the Shared Credentials File public void TestCredentialsFileStsFlag(string profile, StsRegionalEndpointsValue expectedValue) { /* // This test can not currently be run because SharedCredentialsFileTestFixture * // is not referenced within the SecurityToken project. It causes errors when * // building the project individually. * using (var testFixture = new SharedCredentialsFileTestFixture(ProfileText)) * { * var oldProfile = Environment.GetEnvironmentVariable(AwsProfileEnvironmentVariable); * var oldSts = Environment.GetEnvironmentVariable(AwsStsRegionalEndpointsEnvironmentVariable); * try * { * Environment.SetEnvironmentVariable(AwsProfileEnvironmentVariable, profile); * // Environment Variable takes precedence over credentials file value so set it to null to avoid conflict * Environment.SetEnvironmentVariable(AwsStsRegionalEndpointsEnvironmentVariable, null); * ReflectionHelpers.Invoke(typeof(AmazonSecurityTokenServiceConfig), "credentialProfileChain", new CredentialProfileStoreChain(testFixture.CredentialsFilePath)); * var config = new AmazonSecurityTokenServiceConfig(); * Assert.AreEqual(expectedValue, config.StsRegionalEndpoints); * } * finally * { * Environment.SetEnvironmentVariable(AwsProfileEnvironmentVariable, oldProfile); * Environment.SetEnvironmentVariable(AwsStsRegionalEndpointsEnvironmentVariable, oldSts); * } * * }*/ }
/// /// If the STS regional endpoints environment variable is set to /// regional, then the endpoint created by DetermineEndpoint /// should always be specific to the customer's region /// If it is set to legacy, it should be the default sts /// endpoint for legacy global regions /// public void TestDetermineEndpointStsFlag(StsRegionalEndpointsValue stsRegionalFlag, string region, string expected) { var endpointResolver = new EndpointResolver(); var executionContext = CreateExecutionContextSTS(SetupSTSConfig(RegionEndpoint.GetBySystemName(region), stsRegionalFlag)); Uri endpoint = endpointResolver.DetermineEndpoint(executionContext.RequestContext); Assert.AreEqual(expected, endpoint.ToString()); }
/// Ensure that the STS Regional Flag is set according to the value /// the customer sets in the ClientConfig public void ClientConfigStsFlag(StsRegionalEndpointsValue stsFlagValue) { var config = new AmazonSecurityTokenServiceConfig() { StsRegionalEndpoints = stsFlagValue }; Assert.AreEqual(stsFlagValue, config.StsRegionalEndpoints); }
/// Ensure that the STS Regional Flag is set according to the value /// in the environment public void TestEnvStsFlag(string stsFlagValue, StsRegionalEndpointsValue expectedValue) { var oldStsEnv = Environment.GetEnvironmentVariable(AwsStsRegionalEndpointsEnvironmentVariable); try { Environment.SetEnvironmentVariable(AwsStsRegionalEndpointsEnvironmentVariable, stsFlagValue); var config = new AmazonSecurityTokenServiceConfig(); Assert.AreEqual(expectedValue, config.StsRegionalEndpoints); } finally { Environment.SetEnvironmentVariable(AwsStsRegionalEndpointsEnvironmentVariable, oldStsEnv); } }
private static AmazonSecurityTokenServiceConfig SetupSTSConfig(RegionEndpoint endpoint, StsRegionalEndpointsValue stsRegionalEndpoints) { var config = new AmazonSecurityTokenServiceConfig(); config.RegionEndpoint = endpoint; config.StsRegionalEndpoints = stsRegionalEndpoints; return(config); }
/// <summary> /// Initialize the Sts Regional Flag value /// by checking the environment variable /// and shared credentials file field /// </summary> protected override void Initialize() { var tempStsRegionalEndpoints = CheckSTSEnvironmentVariable() ?? CheckCredentialsFile(); this.StsRegionalEndpoints = tempStsRegionalEndpoints ?? StsRegionalEndpointsValue.Legacy; }