public static CredentialProfile GetCredentialProfile(Guid?uniqueKey, string profileName, CredentialProfileOptions options,
                                                             Dictionary <string, string> properties, RegionEndpoint region)
        {
            var profile = new CredentialProfile(profileName, options)
            {
                Region = region
            };

            CredentialProfileUtils.SetUniqueKey(profile, uniqueKey);
            ReflectionHelpers.Invoke(profile, "Properties", properties);
            return(profile);
        }
 public void NameSetSAMLRoleUserIdentityProfile()
 {
     using (var fixture = new NetSDKCredentialsFileTestFixture())
     {
         var profile = new CredentialProfile(SAMLRoleUserIdentityProfileName, SAMLRoleUserIdentityProfileOptions);
         CredentialProfileUtils.SetUniqueKey(profile, Guid.NewGuid());
         fixture.ProfileStore.RegisterProfile(profile);
         SetConfigValues(null, null, SAMLRoleUserIdentityProfileName, null);
         AssertExtensions.ExpectException(() =>
         {
             new AppConfigAWSCredentials().GetCredentials();
         }, typeof(InvalidOperationException), new Regex("is a SAML role profile that specifies a user identity"));
     }
 }
 public static CredentialProfile GetCredentialProfile(Guid? uniqueKey, string profileName, CredentialProfileOptions options,
     Dictionary<string, string> properties, RegionEndpoint region, bool? endpointDiscoveryEnabled, RequestRetryMode? retryMode, int? maxAttempts)
 {
     var profile = new CredentialProfile(profileName, options)
     {
         Region = region,
         EndpointDiscoveryEnabled = endpointDiscoveryEnabled,
         RetryMode = retryMode,
         MaxAttempts = maxAttempts
     };
     CredentialProfileUtils.SetUniqueKey(profile, uniqueKey);            
     ReflectionHelpers.Invoke(profile, "Properties", properties);
     return profile;
 }
Exemplo n.º 4
0
        public void CopyProfile()
        {
            using (var tester = new NetSDKCredentialsFileTestFixture(BasicProfileText))
            {
                // read the profile
                CredentialProfile profile1;
                Assert.IsTrue(tester.ProfileStore.TryGetProfile("ProfileName1", out profile1));

                // copy it
                tester.ProfileStore.CopyProfile("ProfileName1", "ProfileName2");

                // make sure the original is untouched
                CredentialProfile profile1Reread;
                Assert.IsTrue(tester.ProfileStore.TryGetProfile("ProfileName1", out profile1Reread));
                Assert.AreEqual(profile1, profile1Reread);

                // make sure the copy exists
                CredentialProfile profile2;
                Assert.IsTrue(tester.ProfileStore.TryGetProfile("ProfileName2", out profile2));

                // make sure the name and unique key of the copy are different from the original
                Assert.AreNotEqual(profile1.Name, profile2.Name);
                Assert.AreNotEqual(CredentialProfileUtils.GetUniqueKey(profile1), CredentialProfileUtils.GetUniqueKey(profile2));

                // make sure everything else on the copy is the same as the original
                CredentialProfileUtils.SetUniqueKey(profile2, new Guid(CredentialProfileUtils.GetUniqueKey(profile1)));
                ReflectionHelpers.Invoke(profile2, "Name", profile1.Name);
                Assert.AreEqual(profile1, profile2);

                //make sure the additional key came along
                var someOtherValue1 = CredentialProfileUtils.GetProperty(profile1, SomeOtherKey);
                var someOtherValue2 = CredentialProfileUtils.GetProperty(profile2, SomeOtherKey);
                Assert.AreEqual(SomeOtherValue, someOtherValue1);
                Assert.AreEqual(someOtherValue1, someOtherValue2);
            }
        }
Exemplo n.º 5
0
        public void CopyProfile(bool addUniqueKey, bool addAnotherSection, bool useSameName)
        {
            var profileText = BasicProfileTextForCopyAndRename;
            var fromName    = "basic_profile";
            var toName      = fromName + (useSameName ? "" : "2");

            if (addUniqueKey)
            {
                profileText += "toolkit_artifact_guid=" + UniqueKey + Environment.NewLine;
            }

            var anotherSection = addAnotherSection ? "[another_section]" + Environment.NewLine + "propertyx=valuex" + Environment.NewLine : "";

            using (var tester = new SharedCredentialsFileTestFixture(profileText + anotherSection))
            {
                // read the profile
                CredentialProfile profile1;
                Assert.IsTrue(tester.CredentialsFile.TryGetProfile(fromName, out profile1));

                // copy it
                tester.CredentialsFile.CopyProfile(fromName, toName);

                // make sure the original is untouched
                CredentialProfile profile1Reread;
                Assert.IsTrue(tester.CredentialsFile.TryGetProfile(fromName, out profile1Reread));
                Assert.AreEqual(profile1, profile1Reread);

                // make sure the copy exists
                CredentialProfile profile2;
                Assert.IsTrue(tester.CredentialsFile.TryGetProfile(toName, out profile2));

                if (useSameName)
                {
                    Assert.AreEqual(profile1.Name, profile2.Name);
                }
                else
                {
                    Assert.AreNotEqual(profile1.Name, profile2.Name);
                }


                if (addUniqueKey)
                {
                    if (useSameName)
                    {
                        Assert.AreEqual(UniqueKey.ToString("D"), CredentialProfileUtils.GetUniqueKey(profile1));
                        Assert.AreEqual(CredentialProfileUtils.GetUniqueKey(profile1), CredentialProfileUtils.GetUniqueKey(profile2));
                    }
                    else
                    {
                        Assert.AreEqual(UniqueKey.ToString("D"), CredentialProfileUtils.GetUniqueKey(profile1));
                        Assert.AreNotEqual(CredentialProfileUtils.GetUniqueKey(profile1), CredentialProfileUtils.GetUniqueKey(profile2));
                    }
                }
                else
                {
                    Assert.IsNull(CredentialProfileUtils.GetUniqueKey(profile1));
                    Assert.IsNull(CredentialProfileUtils.GetUniqueKey(profile2));
                }

                var contentsAfter = profileText;

                if (!useSameName)
                {
                    // make sure the comments and everything got copied
                    contentsAfter = (contentsAfter + anotherSection).TrimEnd() + Environment.NewLine;
                    if (addUniqueKey)
                    {
                        contentsAfter += profileText.Replace(fromName, toName)
                                         .Replace(CredentialProfileUtils.GetUniqueKey(profile1).ToString(), CredentialProfileUtils.GetUniqueKey(profile2).ToString()).TrimEnd();
                    }
                    else
                    {
                        contentsAfter += profileText.Replace(fromName, toName);
                    }
                }

                tester.AssertCredentialsFileContents(contentsAfter);

                // make sure everything else on the copy is the same as the original
                string profile1Guid = CredentialProfileUtils.GetUniqueKey(profile1);
                CredentialProfileUtils.SetUniqueKey(profile2, profile1Guid == null ? (Guid?)null : new Guid(profile1Guid));
                ReflectionHelpers.Invoke(profile2, "Name", profile1.Name);
                Assert.AreEqual(profile1, profile2);

                //make sure the additional key came along
                var value1 = CredentialProfileUtils.GetProperty(profile1, "property");
                var value2 = CredentialProfileUtils.GetProperty(profile2, "property");
                Assert.AreEqual("value", value1);
                Assert.AreEqual(value1, value2);
            }
        }