Ejemplo n.º 1
0
        public void TestAllProfileTypes()
        {
            foreach (CredentialProfileType type in Enum.GetValues(typeof(CredentialProfileType)))
            {
                using (var tester = new NetSDKCredentialsFileTestFixture())
                {
                    var profileName     = type.ToString() + Guid.NewGuid().ToString();
                    var originalProfile = CredentialProfileTestHelper.GetRandomProfile(profileName, type);
                    Assert.IsTrue(originalProfile.CanCreateAWSCredentials);
                    Assert.IsNotNull(CredentialProfileUtils.GetUniqueKey(originalProfile));

                    tester.ProfileStore.RegisterProfile(originalProfile);

                    var readProfile = tester.TestTryGetProfile(profileName, true, true);
                    Assert.AreEqual(originalProfile, readProfile);

                    //Making sure that the endpoint_discovery_enabled field is set to the default
                    Assert.IsNull(readProfile.EndpointDiscoveryEnabled);

                    // make sure the ProfileType is written, even though it's ignored
                    var expectedType = type.ToString();
                    if (type == CredentialProfileType.Basic)
                    {
                        expectedType = AWSCredentialsProfileType;
                    }
                    else if (type == CredentialProfileType.SAMLRole ||
                             type == CredentialProfileType.SAMLRoleUserIdentity)
                    {
                        expectedType = SAMLRoleProfileType;
                    }
                    tester.AssertJsonProperty(profileName, SettingsConstants.ProfileTypeField, expectedType);
                }
            }
        }
Ejemplo n.º 2
0
        public void AssertWriteProfile(
            string profileName,
            CredentialProfileOptions profileOptions,
            Dictionary <string, string> properties,
            RegionEndpoint region,
            Guid?uniqueKey,
            bool?endpointDiscoveryEnabled,
            RequestRetryMode?retryMode,
            int?maxAttempts,
            string expectedFileContents)
        {
            CredentialsFile.RegisterProfile(
                CredentialProfileTestHelper.GetCredentialProfile(
                    uniqueKey: uniqueKey,
                    profileName: profileName,
                    options: profileOptions,
                    properties: properties,
                    defaultConfigurationModeName: null,
                    region: region,
                    endpointDiscoveryEnabled: endpointDiscoveryEnabled,
                    retryMode: retryMode,
                    maxAttempts: maxAttempts));

            AssertCredentialsFileContents(expectedFileContents);
        }
Ejemplo n.º 3
0
        public CredentialProfile ReadAndAssertProfile(string profileName, CredentialProfileOptions expectedProfileOptions,
                                                      Dictionary <string, string> expectedProperties, RegionEndpoint expectedRegion, Guid?expectedUniqueKey)
        {
            var expectedProfile = CredentialProfileTestHelper.GetCredentialProfile(expectedUniqueKey, profileName, expectedProfileOptions,
                                                                                   expectedProperties, expectedRegion);
            var actualProfile = TestTryGetProfile(profileName, true, expectedProfile.CanCreateAWSCredentials);

            Assert.AreEqual(expectedProfile, actualProfile);
            return(actualProfile);
        }
Ejemplo n.º 4
0
        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"));
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
        public void AssertWriteProfileMaxAttempts(string profileName, CredentialProfileOptions profileOptions, int maxAttempts, string expectedFileContents)
        {
            CredentialsFile.RegisterProfile(
                CredentialProfileTestHelper.GetCredentialProfile(
                    uniqueKey: null,
                    profileName: profileName,
                    options: profileOptions,
                    properties: null,
                    defaultConfigurationModeName: null,
                    region: null,
                    endpointDiscoveryEnabled: null,
                    retryMode: null,
                    maxAttempts: maxAttempts));

            AssertCredentialsFileContents(expectedFileContents);
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
        public void AssertWriteProfile(
            string profileName,
            CredentialProfileOptions profileOptions,
            Dictionary <string, string> properties,
            RegionEndpoint region,
            string expectedFileContents)
        {
            CredentialsFile.RegisterProfile(
                CredentialProfileTestHelper.GetCredentialProfile(
                    uniqueKey: null,
                    profileName: profileName,
                    options: profileOptions,
                    properties: properties,
                    defaultConfigurationModeName: null,
                    region: region,
                    endpointDiscoveryEnabled: null,
                    retryMode: null,
                    maxAttempts: null));

            AssertWriteProfile(profileName, profileOptions, properties, null, null, expectedFileContents);
        }
Ejemplo n.º 13
0
        public CredentialProfile ReadAndAssertProfile(
            string profileName,
            CredentialProfileOptions expectedProfileOptions,
            Dictionary <string, string> expectedProperties,
            RegionEndpoint expectedRegion,
            Guid?expectedUniqueKey)
        {
            var expectedProfile =
                CredentialProfileTestHelper.GetCredentialProfile(
                    uniqueKey: expectedUniqueKey,
                    profileName: profileName,
                    options: expectedProfileOptions,
                    properties: expectedProperties,
                    defaultConfigurationModeName: null,
                    region: expectedRegion,
                    endpointDiscoveryEnabled: null,
                    retryMode: null,
                    maxAttempts: null);

            var actualProfile = TestTryGetProfile(profileName, true, expectedProfile.CanCreateAWSCredentials);

            Assert.AreEqual(expectedProfile, actualProfile);
            return(actualProfile);
        }
 public void AssertWriteProfile(string profileName, CredentialProfileOptions profileOptions,
                                Dictionary <string, string> properties, RegionEndpoint region, string expectedFileContents)
 {
     CredentialsFile.RegisterProfile(CredentialProfileTestHelper.GetCredentialProfile(null, profileName, profileOptions, properties, region, null, null, null));
     AssertWriteProfile(profileName, profileOptions, properties, null, null, expectedFileContents);
 }
 public void AssertWriteProfileRetryMode(string profileName, CredentialProfileOptions profileOptions, RequestRetryMode retryMode, string expectedFileContents)
 {
     CredentialsFile.RegisterProfile(CredentialProfileTestHelper.GetCredentialProfile(null, profileName, profileOptions, null, null, null, retryMode, null));
     AssertCredentialsFileContents(expectedFileContents);
 }
 public void AssertWriteProfileMaxAttempts(string profileName, CredentialProfileOptions profileOptions, int maxAttempts, string expectedFileContents)
 {
     CredentialsFile.RegisterProfile(CredentialProfileTestHelper.GetCredentialProfile(null, profileName, profileOptions, null, null, null, null, maxAttempts));
     AssertCredentialsFileContents(expectedFileContents);
 }
Ejemplo n.º 17
0
 public void AssertWriteProfile(string profileName, CredentialProfileOptions profileOptions,
                                Dictionary <string, string> properties, RegionEndpoint region, Guid?uniqueKey, string expectedFileContents)
 {
     CredentialsFile.RegisterProfile(CredentialProfileTestHelper.GetCredentialProfile(uniqueKey, profileName, profileOptions, properties, region));
     AssertCredentialsFileContents(expectedFileContents);
 }