Exemplo n.º 1
0
 public void ReadEndpointDiscoveryEnabledOnlyProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(EndpointDiscoveryEnabledOnlyProfileText))
     {
         tester.TestTryGetProfile("endpoint_discovery_enabled_only_profile", true, false);
     }
 }
Exemplo n.º 2
0
 public void ReadRegionOnlyProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(RegionOnlyProfileText))
     {
         tester.TestTryGetProfile("region_only_profile", true, false);
     }
 }
Exemplo n.º 3
0
 public void WriteRegionOnlyProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(RegionOnlyProfileText))
     {
         tester.AssertWriteProfile("region_only_profile", RegionOnlyProfileOptions, RegionOnlyProfileText);
     }
 }
Exemplo n.º 4
0
 public void ReadAssumeRoleMfaProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(AssumeRoleMfaProfileText))
     {
         tester.ReadAndAssertProfile("assume_role_mfa_profile", AssumeRoleMfaProfileOptions);
     }
 }
Exemplo n.º 5
0
 public void WriteAssumeRoleMfaProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture())
     {
         tester.AssertWriteProfile("assume_role_mfa_profile", AssumeRoleMfaProfileOptions, AssumeRoleMfaProfileText);
     }
 }
Exemplo n.º 6
0
 public void WriteSessionProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture())
     {
         tester.AssertWriteProfile("session_profile", SessionProfileOptions, SessionProfileText);
     }
 }
Exemplo n.º 7
0
 public void ReadSessionProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(SessionProfileText))
     {
         tester.ReadAndAssertProfile("session_profile", SessionProfileOptions);
     }
 }
Exemplo n.º 8
0
 public void WriteBasicProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture())
     {
         tester.AssertWriteProfile("basic_profile", BasicProfileOptions, RegionEndpoint.CACentral1, UniqueKey, BasicProfileCredentialsText);
     }
 }
Exemplo n.º 9
0
 public void ReadBasicProfileConfigInvalidGuid()
 {
     using (var tester = new SharedCredentialsFileTestFixture(null, BasicProfileConfigText.Replace(UniqueKey.ToString(), "blah")))
     {
         tester.TestTryGetProfile("basic_profile", false, false);
     }
 }
Exemplo n.º 10
0
 public void WriteEndpointDiscoveryEnabledOnlyProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture())
     {
         tester.AssertWriteProfile("endpoint_discovery_enabled_only_profile", EndpointDiscoveryEnabledOnlyProfileOptions, true, EndpointDiscoveryEnabledOnlyProfileText);
     }
 }
Exemplo n.º 11
0
        public void ReadUnsupportedProfileType()
        {
            HashSet <CredentialProfileType> originalWhitelist = null;
            var field = typeof(SharedCredentialsFile).GetField("ProfileTypeWhitelist", BindingFlags.NonPublic | BindingFlags.Static);

            try
            {
                // Instead of trying to read an unsupported profile type we remove the list of supported types and read one of those.
                // We do this because the check in the TryGetProfile method is there for future safety, and won't fail otherwise.

                //mock ProfileTypeWhitelist
                originalWhitelist = (HashSet <CredentialProfileType>)field.GetValue(null);
                field.SetValue(null, new HashSet <CredentialProfileType>());

                using (var tester = new SharedCredentialsFileTestFixture(SessionProfileText))
                {
                    tester.TestTryGetProfile("session_profile", false, false);
                }
            }
            finally
            {
                // unmock ProfileTypeWhitelist
                field.SetValue(null, originalWhitelist);
            }
        }
Exemplo n.º 12
0
 public void ReadBasicProfileConfig()
 {
     using (var tester = new SharedCredentialsFileTestFixture(null, BasicProfileConfigText))
     {
         tester.ReadAndAssertProfile("basic_profile", BasicProfileOptions, RegionEndpoint.CACentral1, UniqueKey);
     }
 }
Exemplo n.º 13
0
            public FallbackFactoryTestFixture(string sharedCredsFileContent, string awsProfileValue, string enableEndpointDiscoveryValue = 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));

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

                originalAWSEnableEndpointDiscoveryValue = Environment.GetEnvironmentVariable(AWS_ENABLE_ENDPOINT_DISCOVERY_ENVIRONMENT_VARIABLE);
                Environment.SetEnvironmentVariable(AWS_ENABLE_ENDPOINT_DISCOVERY_ENVIRONMENT_VARIABLE, enableEndpointDiscoveryValue);

                // reset before use to ensure the new credentialProfileChains are used.
                FallbackCredentialsFactory.Reset();
                FallbackRegionFactory.Reset();
                FallbackEndpointDiscoveryEnabledFactory.Reset();
            }
Exemplo n.º 14
0
 public void ReadDefaultConfigProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(null, DefaultProfileText))
     {
         tester.TestTryGetProfile("default", true, true);
     }
 }
Exemplo n.º 15
0
 public void ReadProfileDoesNotExist()
 {
     using (var tester = new SharedCredentialsFileTestFixture())
     {
         tester.TestTryGetProfile("profile_does_not_exist", false, false);
     }
 }
Exemplo n.º 16
0
        public void WriteRegionCredentialsUntouched()
        {
            using (var tester = new SharedCredentialsFileTestFixture())
            {
                // write the whole profile - credentials options and region
                var basicOptions = new CredentialProfileOptions
                {
                    AccessKey = "access_key",
                    SecretKey = "secret_key"
                };
                var profile = new CredentialProfile("WriteRegionKeepOptionsProfile", basicOptions);
                profile.Region = RegionEndpoint.USGovCloudWest1;
                tester.CredentialsFile.RegisterProfile(profile);

                // now write just the region
                var emptyOptions      = new CredentialProfileOptions();
                var regionOnlyProfile = new CredentialProfile("WriteRegionKeepOptionsProfile", basicOptions);
                profile.Region = RegionEndpoint.APSouth1;
                tester.CredentialsFile.RegisterProfile(profile);

                // Make sure it has the original options and the new region
                var readProfile = tester.TestTryGetProfile("WriteRegionKeepOptionsProfile", true, true);
                Assert.AreEqual("access_key", readProfile.Options.AccessKey);
                Assert.AreEqual("secret_key", readProfile.Options.SecretKey);
                Assert.AreEqual(RegionEndpoint.APSouth1, readProfile.Region);
            }
        }
Exemplo n.º 17
0
 public void ReadInvalidProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(InvalidProfileText))
     {
         tester.TestTryGetProfile("invalid_profile", true, false);
     }
 }
Exemplo n.º 18
0
 public void DeleteProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(SessionProfileText + Environment.NewLine + BasicProfileCredentialsText))
     {
         tester.CredentialsFile.UnregisterProfile("session_profile");
         tester.AssertCredentialsFileContents(BasicProfileCredentialsText);
     }
 }
Exemplo n.º 19
0
 public void UpdateProfileWithProperties()
 {
     using (var tester = new SharedCredentialsFileTestFixture(UpdatedProfileWithPropertiesTextBefore))
     {
         tester.ReadAndAssertProfile("basic_profile", UpdatedProfileWithPropertiesOptions, UpdatedProfileWithPropertiesBefore);
         tester.AssertWriteProfile("basic_profile", UpdatedProfileWithPropertiesOptions, UpdatedProfileWithPropertiesAfter, UpdatedProfileWithPropertiesTextAfter);
     }
 }
Exemplo n.º 20
0
 public void ReadInvalidEndpointDiscoveryEnabledOnlyProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(EndpointDiscoveryEnabledOnlyProfileText_Invalid))
     {
         CredentialProfile profile1;
         Assert.IsFalse(tester.CredentialsFile.TryGetProfile("endpoint_discovery_enabled_only_profile", out profile1));
     }
 }
Exemplo n.º 21
0
 public void ListProfilesExcludeInvalidDuplicateProperty()
 {
     using (var tester = new SharedCredentialsFileTestFixture(SessionProfileText + Environment.NewLine + "aws_session_token=session_aws_session_token"))
     {
         var profiles = tester.CredentialsFile.ListProfiles();
         Assert.AreEqual(0, profiles.Count);
     }
 }
Exemplo n.º 22
0
 public void ListProfilesEmpty()
 {
     using (var tester = new SharedCredentialsFileTestFixture())
     {
         var profiles = tester.CredentialsFile.ListProfiles();
         Assert.AreEqual(0, profiles.Count);
     }
 }
Exemplo n.º 23
0
 public void UpdateProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(SessionProfileText))
     {
         tester.ReadAndAssertProfile("session_profile", SessionProfileOptions);
         tester.AssertWriteProfile("session_profile", SessionProfileOptionsUpdated, SessionProfileTextUpdated);
     }
 }
Exemplo n.º 24
0
 public void ReadBasicProfileCredentialsTakesPrecedence()
 {
     using (var tester = new SharedCredentialsFileTestFixture(
                BasicProfileTextCredentialsPrecedence, BasicProfileTextConfigPrecedence))
     {
         tester.ReadAndAssertProfile("basic_profile", BasicProfilePrecedenceOptions);
     }
 }
Exemplo n.º 25
0
 public void ReadBasicProfileSplit()
 {
     using (var tester = new SharedCredentialsFileTestFixture(
                BasicProfileTextCredentialsPartial, BasicProfileTextConfigPartial))
     {
         tester.ReadAndAssertProfile("basic_profile", BasicProfileOptions);
     }
 }
Exemplo n.º 26
0
 public void ListProfilesExcludeInvalidNoCredentials()
 {
     using (var tester = new SharedCredentialsFileTestFixture(SessionProfileText + Environment.NewLine + InvalidProfileText))
     {
         var profiles = tester.CredentialsFile.ListProfiles();
         Assert.AreEqual(1, profiles.Count);
         Assert.AreEqual("session_profile", profiles[0].Name);
     }
 }
Exemplo n.º 27
0
 public void ListProfiles()
 {
     using (var tester = new SharedCredentialsFileTestFixture(SessionProfileText))
     {
         var profiles = tester.CredentialsFile.ListProfiles();
         Assert.AreEqual(1, profiles.Count);
         Assert.AreEqual("session_profile", profiles[0].Name);
     }
 }
Exemplo n.º 28
0
 public void ListProfileNames()
 {
     using (var tester = new SharedCredentialsFileTestFixture(SessionProfileText))
     {
         var profileNames = tester.CredentialsFile.ListProfileNames();
         Assert.AreEqual(1, profileNames.Count);
         Assert.IsTrue(profileNames.Contains("session_profile"));
     }
 }
Exemplo n.º 29
0
        public void ReadBasicProfileAllConfigExtraSpacesAndTabInName()
        {
            var basicProfileInConfigWithWhitespace = BasicProfileConfigText.Replace("profile basic_profile", "profile \t basic_profile");

            using (var tester = new SharedCredentialsFileTestFixture(null, basicProfileInConfigWithWhitespace))
            {
                tester.ReadAndAssertProfile("basic_profile", BasicProfileOptions, RegionEndpoint.CACentral1, UniqueKey);
            }
        }
Exemplo n.º 30
0
 public void ReadBasicProfileAllConfigForgotProfileKeyword()
 {
     using (var tester = new SharedCredentialsFileTestFixture(null, BasicProfileCredentialsText))
     {
         CredentialProfile profile = null;
         Assert.IsFalse(tester.CredentialsFile.TryGetProfile("basic_profile", out profile));
         Assert.IsNull(profile);
     }
 }