public void ListProfilesEmpty() { using (var tester = new NetSDKCredentialsFileTestFixture()) { var profiles = tester.ProfileStore.ListProfiles(); Assert.AreEqual(0, profiles.Count); } }
public void ReadUniqueKeyProperty() { using (var tester = new NetSDKCredentialsFileTestFixture(LegacyCredentialsTypeProfileText)) { var profile = tester.TestTryGetProfile("LegacyCredentialsTypeProfile", true, false); Assert.AreEqual(UniqueKey.ToString("D"), CredentialProfileUtils.GetUniqueKey(profile)); } }
public void ReadDefaultConfigurationModeNameOnlyProfile() { using (var tester = new NetSDKCredentialsFileTestFixture(DefaultConfigurationModeNameOnlyProfileText)) { var profile = tester.TestTryGetProfile("DefaultConfigurationModeNameOnlyProfile", expectProfile: true, expectValidProfile: false); Assert.AreEqual(DefaultConfigurationMode.InRegion.ToString(), profile.DefaultConfigurationModeName); } }
public void LegacyCredentialsTypeProfile() { using (var tester = new NetSDKCredentialsFileTestFixture(LegacyCredentialsTypeProfileText)) { var profile = tester.TestTryGetProfile("LegacyCredentialsTypeProfile", true, false); var credentialType = CredentialProfileUtils.GetProperty(profile, "CredentialsType"); Assert.AreEqual("the_credentials_type", credentialType); } }
public FallbackFactoryTestFixture(string sharedCredsFileContent, string awsProfileValue, Dictionary <string, string> newEnvironmentVariables = null, bool setAwsConfigsProfileValue = false) { 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); if (!setAwsConfigsProfileValue) { 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); } } originalAwsconfigAwsProfileName = AWSConfigs.AWSProfileName; originalAwsconfigAwsProfilesLocation = AWSConfigs.AWSProfilesLocation; if (setAwsConfigsProfileValue) { AWSConfigs.AWSProfileName = awsProfileValue; AWSConfigs.AWSProfilesLocation = sharedFixture.CredentialsFilePath; } try { // reset before use to ensure the new credentialProfileChains are used. FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); FallbackEndpointDiscoveryEnabledFactory.Reset(); FallbackInternalConfigurationFactory.Reset(); } catch (Exception ex) { // If any exceptions happen during the intial resets, perhaps due to invalid config // dispose right away to reset back to the initial configuration Dispose(); throw ex; } }
private static void RegisteOtherProfile(NetSDKCredentialsFileTestFixture tester) { var options = new CredentialProfileOptions { AccessKey = "ak", SecretKey = "sk" }; tester.ProfileStore.RegisterProfile(new CredentialProfile("OtherProfile", options)); }
public void CopyProfileTargetAlreadyExists() { using (var tester = new NetSDKCredentialsFileTestFixture(BasicProfileText)) { AssertExtensions.ExpectException(() => { tester.ProfileStore.CopyProfile("ProfileName1", "ProfileName1"); }, typeof(ArgumentException), "Cannot copy object. The destination object 'ProfileName1' already exists."); } }
public void CopyProfileSourceDoesNotExist() { using (var tester = new NetSDKCredentialsFileTestFixture(BasicProfileText)) { AssertExtensions.ExpectException(() => { tester.ProfileStore.CopyProfile("ProfileNameX", "ProfileName2"); }, typeof(ArgumentException), "Cannot copy object. The source object 'ProfileNameX' does not exist."); } }
public void RenameProfileTargetAlreadyExists() { using (var tester = new NetSDKCredentialsFileTestFixture(BasicProfileText)) { RegisteOtherProfile(tester); AssertExtensions.ExpectException(() => { tester.ProfileStore.RenameProfile("OtherProfile", "ProfileName1"); }, typeof(ArgumentException), "Cannot rename object. The destination object 'ProfileName1' already exists."); } }
public void ListProfilesExcludeInvalid() { using (var tester = new NetSDKCredentialsFileTestFixture(InvalidProfileText)) { tester.ProfileStore.RegisterProfile(CredentialProfileTestHelper.GetCredentialProfile( Guid.NewGuid(), "SessionProfile", CredentialProfileTestHelper.GetRandomOptions(CredentialProfileType.Session))); var profiles = tester.ProfileStore.ListProfiles(); Assert.AreEqual(1, profiles.Count); Assert.AreEqual("SessionProfile", profiles[0].Name); } }
public void ListProfileNames() { using (var tester = new NetSDKCredentialsFileTestFixture()) { tester.ProfileStore.RegisterProfile(CredentialProfileTestHelper.GetCredentialProfile(Guid.NewGuid(), "SessionProfile", CredentialProfileTestHelper.GetRandomOptions(CredentialProfileType.Session))); var profileNames = tester.ProfileStore.ListProfileNames(); Assert.AreEqual(1, profileNames.Count); Assert.IsTrue(profileNames.Contains("SessionProfile")); } }
public void RenameProfileTargetAlreadyExistsForce() { using (var tester = new NetSDKCredentialsFileTestFixture()) { Create2Profiles(tester); tester.ProfileStore.RenameProfile("profile1", "profile2", true); CredentialProfile readProfile; Assert.IsFalse(tester.ProfileStore.TryGetProfile("profile1", out readProfile)); Assert.IsTrue(tester.ProfileStore.TryGetProfile("profile2", out readProfile)); Assert.AreEqual(readProfile.Options.AccessKey, "access_key1"); Assert.AreEqual(readProfile.Options.SecretKey, "secret_key1"); } }
private void TestReservedPropertyName(string exceptionFormat, string propertyName) { AssertExtensions.ExpectException(() => { using (var tester = new NetSDKCredentialsFileTestFixture()) { var profileName = Guid.NewGuid().ToString(); var profile = CredentialProfileTestHelper.GetRandomProfile(profileName, CredentialProfileType.Basic); var properties = CredentialProfileUtils.GetProperties(profile); properties.Add(propertyName, "aargh!"); tester.ProfileStore.RegisterProfile(profile); } }, typeof(ArgumentException), string.Format(CultureInfo.InvariantCulture, exceptionFormat, propertyName)); }
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 void WriteEndpointDiscoveryEnabledOnlyProfile() { using (var tester = new NetSDKCredentialsFileTestFixture()) { var emptyOptions = new CredentialProfileOptions(); var profile = new CredentialProfile("EndpointDiscoveryEnabledOnlyProfile", emptyOptions); profile.EndpointDiscoveryEnabled = true; tester.ProfileStore.RegisterProfile(profile); var readProfile = tester.TestTryGetProfile("EndpointDiscoveryEnabledOnlyProfile", true, false); Assert.IsTrue(readProfile.EndpointDiscoveryEnabled.HasValue); Assert.IsTrue(readProfile.EndpointDiscoveryEnabled.Value); } }
public void WriteRegionOnlyProfile() { using (var tester = new NetSDKCredentialsFileTestFixture()) { var emptyOptions = new CredentialProfileOptions(); var profile = new CredentialProfile("RegionOnlyProfile", emptyOptions); profile.Region = RegionEndpoint.USGovCloudWest1; tester.ProfileStore.RegisterProfile(profile); var readProfile = tester.TestTryGetProfile("RegionOnlyProfile", true, false); Assert.AreEqual(RegionEndpoint.USGovCloudWest1, readProfile.Region); Assert.IsTrue((bool)ReflectionHelpers.Invoke(readProfile.Options, "IsEmpty")); } }
public void UpdateProfileType() { using (var tester = new NetSDKCredentialsFileTestFixture(SessionProfileText)) { var options = new CredentialProfileOptions { AccessKey = "access_key_id", SecretKey = "secret_key_id" }; var newProfile = new CredentialProfile("ProfileName1", options); tester.ProfileStore.RegisterProfile(newProfile); tester.AssertFileContents(SessionProfileTextAfterUpdate); } }
public void CopyProfileFromEqualsTo() { 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", "ProfileName1"); // make sure the original is untouched CredentialProfile profile1Reread; Assert.IsTrue(tester.ProfileStore.TryGetProfile("ProfileName1", out profile1Reread)); Assert.AreEqual(profile1, profile1Reread); } }
public void UnregisterProfile() { using (var tester = new NetSDKCredentialsFileTestFixture()) { // register tester.ProfileStore.RegisterProfile(CredentialProfileTestHelper.GetCredentialProfile(Guid.NewGuid(), CredentialProfileType.Basic.ToString(), CredentialProfileTestHelper.GetRandomOptions(CredentialProfileType.Basic))); // check that it's there tester.TestTryGetProfile(CredentialProfileType.Basic.ToString(), true, true); // unregister tester.ProfileStore.UnregisterProfile(CredentialProfileType.Basic.ToString()); // check that it's not there tester.TestTryGetProfile(CredentialProfileType.Basic.ToString(), false, false); } }
public void TestReadCompatibilityBasic() { using (var tester = new NetSDKCredentialsFileTestFixture()) { // write with old ProfileManager ProfileManager.RegisterProfile("BasicProfile", "AccessKey", "SecretKey"); // read with new NetSDKCredentialsFile CredentialProfile profile; Assert.IsTrue(tester.ProfileStore.TryGetProfile("BasicProfile", out profile)); Assert.IsNotNull(profile); Assert.AreEqual("BasicProfile", profile.Name); Assert.AreEqual("AccessKey", profile.Options.AccessKey); Assert.AreEqual("SecretKey", profile.Options.SecretKey); Assert.AreEqual(CredentialProfileType.Basic, CredentialProfileTypeDetector.DetectProfileType(profile.Options).Value); } }
public FallbackFactoryTestFixture(string sharedCredsFileContent, string awsProfileValue) { 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)); testAWSProfileValue = awsProfileValue; if (testAWSProfileValue != null) { originalAWSProfileValue = Environment.GetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE); Environment.SetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE, testAWSProfileValue); } }
public void TestWriteCompatibilityBasic() { using (var tester = new NetSDKCredentialsFileTestFixture()) { // write with new NetSDKCredentialsFile CredentialProfile profile = CredentialProfileTestHelper.GetCredentialProfile( Guid.NewGuid(), "BasicProfile", CredentialProfileTestHelper.GetRandomOptions(CredentialProfileType.Basic)); tester.ProfileStore.RegisterProfile(profile); // read with old ProfileManager AWSCredentials credentials; Assert.IsTrue(ProfileManager.TryGetAWSCredentials("BasicProfile", out credentials)); Assert.IsNotNull(credentials); var immutableCredentials = credentials.GetCredentials(); Assert.AreEqual(profile.Options.AccessKey, immutableCredentials.AccessKey); Assert.AreEqual(profile.Options.SecretKey, immutableCredentials.SecretKey); } }
public void CredentialProfileStorePropertyIsSet() { using (var tester = new NetSDKCredentialsFileTestFixture()) { var writeProfile = new CredentialProfile("test_profile", new CredentialProfileOptions { AccessKey = "access_key", SecretKey = "secret_key" }); Assert.IsNull(writeProfile.CredentialProfileStore); tester.ProfileStore.RegisterProfile(writeProfile); Assert.IsTrue(object.ReferenceEquals(tester.ProfileStore, writeProfile.CredentialProfileStore)); CredentialProfile readProfile; Assert.IsTrue(tester.ProfileStore.TryGetProfile("test_profile", out readProfile)); Assert.IsTrue(object.ReferenceEquals(tester.ProfileStore, readProfile.CredentialProfileStore)); } }
public void TestWriteCompatibilitySession() { using (var tester = new NetSDKCredentialsFileTestFixture()) { // write a type that's not supported by ProfileManager tester.ProfileStore.RegisterProfile(CredentialProfileTestHelper.GetCredentialProfile( Guid.NewGuid(), "SessionProfile", CredentialProfileTestHelper.GetRandomOptions(CredentialProfileType.Session))); // make sure profile manager can't read it as a basic profile, and that there aren't any errors. AWSCredentials credentials; Assert.IsFalse(ProfileManager.TryGetAWSCredentials("SessionProfile", out credentials)); Assert.IsNull(credentials); // make sure profile manager can't read it as a SAML profile, and that there aren't any errors. SAMLRoleProfile samlProfile; Assert.IsFalse(ProfileManager.TryGetProfile("SessionProfile", out samlProfile)); Assert.IsNull(samlProfile); } }
public void TestReadCompatibilitySAML() { using (var tester = new NetSDKCredentialsFileTestFixture()) { // write with old ProfileManager ProfileManager.RegisterSAMLEndpoint("EndpointName", new Uri("https://somesamlendpoint/"), null); ProfileManager.RegisterSAMLRoleProfile("SAMLProfile", "EndpointName", "RoleArn", "UserIdentity"); // read with new NetSDKCredentialsFile CredentialProfile profile; Assert.IsTrue(tester.ProfileStore.TryGetProfile("SAMLProfile", out profile)); Assert.IsNotNull(profile); Assert.AreEqual("SAMLProfile", profile.Name); Assert.AreEqual("EndpointName", profile.Options.EndpointName); Assert.AreEqual("RoleArn", profile.Options.RoleArn); Assert.AreEqual("UserIdentity", profile.Options.UserIdentity); Assert.AreEqual(CredentialProfileType.SAMLRoleUserIdentity, CredentialProfileTypeDetector.DetectProfileType(profile.Options).Value); } }
public void RenameProfileFromEqualsTo() { using (var tester = new NetSDKCredentialsFileTestFixture(BasicProfileText)) { // read the profile CredentialProfile before; Assert.IsTrue(tester.ProfileStore.TryGetProfile("ProfileName1", out before)); // rename it with the same name tester.ProfileStore.RenameProfile("ProfileName1", "ProfileName1"); // make sure it's still there CredentialProfile after; Assert.IsTrue(tester.ProfileStore.TryGetProfile("ProfileName1", out after)); // make sure everything is the same Assert.AreEqual(before, after); } }
private static void Create2Profiles(NetSDKCredentialsFileTestFixture tester) { var options1 = new CredentialProfileOptions { AccessKey = "access_key1", SecretKey = "secret_key1" }; CredentialProfile profile1 = new CredentialProfile("profile1", options1); var options2 = new CredentialProfileOptions { AccessKey = "access_key2", SecretKey = "secret_key2" }; CredentialProfile profile2 = new CredentialProfile("profile2", options2); tester.ProfileStore.RegisterProfile(profile1); tester.ProfileStore.RegisterProfile(profile2); }
public void TestWriteCompatibilitySAML() { using (var tester = new NetSDKCredentialsFileTestFixture()) { // write with new NetSDKCredentialsFile CredentialProfile profile = CredentialProfileTestHelper.GetCredentialProfile( Guid.NewGuid(), "SAMLProfile", CredentialProfileTestHelper.GetRandomOptions(CredentialProfileType.SAMLRoleUserIdentity)); tester.ProfileStore.RegisterProfile(profile); // TODO do this with the new SAML Endpoint Manager ProfileManager.RegisterSAMLEndpoint(profile.Options.EndpointName, new Uri("https://somesamlendpoint/"), null); // read with old ProfileManager SAMLRoleProfile samlProfile; Assert.IsTrue(ProfileManager.TryGetProfile("SAMLProfile", out samlProfile)); Assert.IsNotNull(samlProfile); Assert.AreEqual(profile.Options.EndpointName, samlProfile.EndpointSettings.Name); Assert.AreEqual(profile.Options.RoleArn, samlProfile.RoleArn); Assert.AreEqual(profile.Options.UserIdentity, samlProfile.UserIdentity); } }
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); } }
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(); }