예제 #1
0
        public void WmiSettingsForExceptionHandlerAreGeneratedWithCorrectPolicyAndTypeIfWmiIsEnabled()
        {
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(ReplaceHandlerData), new ReplaceHandlerDataManageabilityProvider());
            provider
                = new ConfigurationSectionManageabilityProviderWrapper(
                      new ExceptionHandlingSettingsManageabilityProvider(subProviders));

            ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1");

            section.ExceptionPolicies.Add(policy1);
            ExceptionTypeData exceptionType1 = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.None);

            policy1.ExceptionTypes.Add(exceptionType1);
            ReplaceHandlerData handler1 = new ReplaceHandlerData("handler1", "message", typeof(ArgumentNullException).AssemblyQualifiedName);

            exceptionType1.ExceptionHandlers.Add(handler1);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, false, machineKey, userKey, true, wmiSettings);

            Assert.AreEqual(3, wmiSettings.Count);
            IDictionary <String, ExceptionHandlerSetting> handlerSettings = SelectWmiSettings <ExceptionHandlerSetting>(wmiSettings);

            Assert.AreEqual(1, handlerSettings.Count);
            Assert.IsTrue(handlerSettings.ContainsKey("handler1"));
            Assert.AreEqual("message", ((ReplaceHandlerSetting)handlerSettings["handler1"]).ExceptionMessage);
            Assert.AreEqual(typeof(ArgumentNullException).AssemblyQualifiedName, ((ReplaceHandlerSetting)handlerSettings["handler1"]).ReplaceExceptionType);
            Assert.AreEqual("policy1", ((ReplaceHandlerSetting)handlerSettings["handler1"]).Policy);
            Assert.AreEqual("type1", ((ReplaceHandlerSetting)handlerSettings["handler1"]).ExceptionType);
            Assert.AreEqual(0, ((ReplaceHandlerSetting)handlerSettings["handler1"]).Order);
        }
예제 #2
0
        public void RegisteredHandlerDataProviderIsCalledWithNoOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(ReplaceHandlerData), registeredProvider);
            provider
                = new ConfigurationSectionManageabilityProviderWrapper(
                      new ExceptionHandlingSettingsManageabilityProvider(subProviders));

            ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1");

            section.ExceptionPolicies.Add(policy1);
            ExceptionTypeData exceptionType1 = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.None);

            policy1.ExceptionTypes.Add(exceptionType1);
            ExceptionHandlerData handlerData1 = new ReplaceHandlerData("handler1", "msg", typeof(ArgumentException).AssemblyQualifiedName);

            exceptionType1.ExceptionHandlers.Add(handlerData1);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, false, wmiSettings);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(handlerData1, registeredProvider.LastConfigurationObject);
            Assert.AreEqual(null, registeredProvider.machineKey);
            Assert.AreEqual(null, registeredProvider.userKey);
        }
예제 #3
0
        public void SymmetricCryptoProviderWithDisabledPolicyIsRemoved()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(SymmetricAlgorithmProviderData), registeredProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(
                new CryptographySettingsManageabilityProvider(subProviders));

            SymmetricAlgorithmProviderData symmetricCryptoProvider1Data
                = new SymmetricAlgorithmProviderData("symmetricCryptoProvider1", typeof(Object), "key", DataProtectionScope.CurrentUser);

            section.SymmetricCryptoProviders.Add(symmetricCryptoProvider1Data);
            SymmetricAlgorithmProviderData symmetricCryptoProvider2Data
                = new SymmetricAlgorithmProviderData("symmetricCryptoProvider2", typeof(Object), "key", DataProtectionScope.CurrentUser);

            section.SymmetricCryptoProviders.Add(symmetricCryptoProvider2Data);

            MockRegistryKey machineSymmetricCryptoProvidersKey = new MockRegistryKey(false);

            machineKey.AddSubKey(CryptographySettingsManageabilityProvider.SymmetricCryptoProvidersKeyName, machineSymmetricCryptoProvidersKey);
            MockRegistryKey machineSymmetricCryptoProvider2Key = new MockRegistryKey(false);

            machineSymmetricCryptoProvidersKey.AddSubKey("symmetricCryptoProvider2", machineSymmetricCryptoProvider2Key);
            machineSymmetricCryptoProvider2Key.AddBooleanValue(CryptographySettingsManageabilityProvider.PolicyValueName, false);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings);

            Assert.AreEqual(1, section.SymmetricCryptoProviders.Count);
            Assert.IsNotNull(section.SymmetricCryptoProviders.Get("symmetricCryptoProvider1"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineSymmetricCryptoProvidersKey, machineSymmetricCryptoProvider2Key));
        }
예제 #4
0
        public void SecurityCacheProviderWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(SecurityCacheProviderData), registeredProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(
                new SecuritySettingsManageabilityProvider(subProviders));

            SecurityCacheProviderData securityCacheProvider1Data = new SecurityCacheProviderData("securityCacheProvider1", typeof(Object));

            section.SecurityCacheProviders.Add(securityCacheProvider1Data);
            SecurityCacheProviderData securityCacheProvider2Data = new SecurityCacheProviderData("securityCacheProvider2", typeof(Object));

            section.SecurityCacheProviders.Add(securityCacheProvider2Data);

            MockRegistryKey machineSecurityCacheProvidersKey = new MockRegistryKey(false);

            machineKey.AddSubKey(SecuritySettingsManageabilityProvider.SecurityCacheProvidersKeyName, machineSecurityCacheProvidersKey);
            MockRegistryKey machineSecurityCacheProvider2Key = new MockRegistryKey(false);

            machineSecurityCacheProvidersKey.AddSubKey("securityCacheProvider2", machineSecurityCacheProvider2Key);
            machineSecurityCacheProvider2Key.AddBooleanValue(SecuritySettingsManageabilityProvider.PolicyValueName, false);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, false, machineKey, userKey, true, wmiSettings);

            Assert.AreEqual(2, section.SecurityCacheProviders.Count);
            Assert.IsNotNull(section.SecurityCacheProviders.Get("securityCacheProvider1"));
            Assert.IsNotNull(section.SecurityCacheProviders.Get("securityCacheProvider2"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineSecurityCacheProvidersKey, machineSecurityCacheProvider2Key));
        }
예제 #5
0
        public void RegisteredSymmetricCryptoProviderDataProviderIsCalledWithCorrectOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(SymmetricAlgorithmProviderData), registeredProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(
                new CryptographySettingsManageabilityProvider(subProviders));

            SymmetricAlgorithmProviderData symmetricCryptoProviderData = new SymmetricAlgorithmProviderData("symmetricCryptoProvider1", typeof(Object), "key", DataProtectionScope.CurrentUser);

            section.SymmetricCryptoProviders.Add(symmetricCryptoProviderData);

            MockRegistryKey machinesymmetricCryptoProvidersKey = new MockRegistryKey(false);

            machineKey.AddSubKey(CryptographySettingsManageabilityProvider.SymmetricCryptoProvidersKeyName, machinesymmetricCryptoProvidersKey);
            MockRegistryKey machinesymmetricCryptoProviderKey = new MockRegistryKey(false);

            machinesymmetricCryptoProvidersKey.AddSubKey("symmetricCryptoProvider1", machinesymmetricCryptoProviderKey);
            MockRegistryKey machineOthersymmetricCryptoProviderKey = new MockRegistryKey(false);

            machinesymmetricCryptoProvidersKey.AddSubKey("symmetricCryptoProvider2", machineOthersymmetricCryptoProviderKey);

            MockRegistryKey usersymmetricCryptoProvidersKey = new MockRegistryKey(false);

            userKey.AddSubKey(CryptographySettingsManageabilityProvider.SymmetricCryptoProvidersKeyName, usersymmetricCryptoProvidersKey);
            MockRegistryKey usersymmetricCryptoProviderKey = new MockRegistryKey(false);

            usersymmetricCryptoProvidersKey.AddSubKey("symmetricCryptoProvider1", usersymmetricCryptoProviderKey);
            MockRegistryKey userOthersymmetricCryptoProviderKey = new MockRegistryKey(false);

            usersymmetricCryptoProvidersKey.AddSubKey("symmetricCryptoProvider2", userOthersymmetricCryptoProviderKey);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(symmetricCryptoProviderData, registeredProvider.LastConfigurationObject);
            Assert.AreSame(machinesymmetricCryptoProviderKey, registeredProvider.machineKey);
            Assert.AreSame(usersymmetricCryptoProviderKey, registeredProvider.userKey);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(machinesymmetricCryptoProvidersKey, machinesymmetricCryptoProviderKey, machineOthersymmetricCryptoProviderKey,
                                               usersymmetricCryptoProvidersKey, usersymmetricCryptoProviderKey, userOthersymmetricCryptoProviderKey));
        }
예제 #6
0
        public void RegisteredSecurityCacheProviderDataProviderIsCalledWithCorrectOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(CustomSecurityCacheProviderData), registeredProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(
                new SecuritySettingsManageabilityProvider(subProviders));

            CustomSecurityCacheProviderData securitycacheProviderData = new CustomSecurityCacheProviderData("securitycacheProvider1", typeof(Object));

            section.SecurityCacheProviders.Add(securitycacheProviderData);

            MockRegistryKey machinesecuritycacheProvidersKey = new MockRegistryKey(false);

            machineKey.AddSubKey(SecuritySettingsManageabilityProvider.SecurityCacheProvidersKeyName, machinesecuritycacheProvidersKey);
            MockRegistryKey machinesecuritycacheProviderKey = new MockRegistryKey(false);

            machinesecuritycacheProvidersKey.AddSubKey("securitycacheProvider1", machinesecuritycacheProviderKey);
            MockRegistryKey machineOthersecuritycacheProviderKey = new MockRegistryKey(false);

            machinesecuritycacheProvidersKey.AddSubKey("securitycacheProvider2", machineOthersecuritycacheProviderKey);

            MockRegistryKey usersecuritycacheProvidersKey = new MockRegistryKey(false);

            userKey.AddSubKey(SecuritySettingsManageabilityProvider.SecurityCacheProvidersKeyName, usersecuritycacheProvidersKey);
            MockRegistryKey usersecuritycacheProviderKey = new MockRegistryKey(false);

            usersecuritycacheProvidersKey.AddSubKey("securitycacheProvider1", usersecuritycacheProviderKey);
            MockRegistryKey userOthersecuritycacheProviderKey = new MockRegistryKey(false);

            usersecuritycacheProvidersKey.AddSubKey("securitycacheProvider2", userOthersecuritycacheProviderKey);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(securitycacheProviderData, registeredProvider.LastConfigurationObject);
            Assert.AreSame(machinesecuritycacheProviderKey, registeredProvider.machineKey);
            Assert.AreSame(usersecuritycacheProviderKey, registeredProvider.userKey);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(machinesecuritycacheProvidersKey, machinesecuritycacheProviderKey, machineOthersecuritycacheProviderKey,
                                               usersecuritycacheProvidersKey, usersecuritycacheProviderKey, userOthersecuritycacheProviderKey));
        }
예제 #7
0
        public void RegisteredCacheStorageDataProviderIsCalledWithCorrectOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(CacheStorageData), registeredProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(
                new CacheManagerSettingsManageabilityProvider(subProviders));

            CacheStorageData data = new CacheStorageData("store1", typeof(NullBackingStore));

            section.BackingStores.Add(data);

            MockRegistryKey machineStoresKey = new MockRegistryKey(false);

            machineKey.AddSubKey(CacheManagerSettingsManageabilityProvider.BackingStoresKeyName, machineStoresKey);
            MockRegistryKey machineStoreKey = new MockRegistryKey(false);

            machineStoresKey.AddSubKey("store1", machineStoreKey);
            MockRegistryKey machineOtherStoreKey = new MockRegistryKey(false);

            machineStoresKey.AddSubKey("store2", machineOtherStoreKey);

            MockRegistryKey userStoresKey = new MockRegistryKey(false);

            userKey.AddSubKey(CacheManagerSettingsManageabilityProvider.BackingStoresKeyName, userStoresKey);
            MockRegistryKey userStoreKey = new MockRegistryKey(false);

            userStoresKey.AddSubKey("store1", userStoreKey);
            MockRegistryKey userOtherStoreKey = new MockRegistryKey(false);

            userStoresKey.AddSubKey("store2", userOtherStoreKey);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(data, registeredProvider.LastConfigurationObject);
            Assert.AreEqual(machineStoreKey, registeredProvider.machineKey);
            Assert.AreEqual(userStoreKey, registeredProvider.userKey);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(machineStoresKey, machineStoreKey, machineOtherStoreKey,
                                               userStoresKey, userStoreKey, userOtherStoreKey));
        }
예제 #8
0
        public void RegisteredSymmetricCryptoProviderDataProviderIsCalledWithNoOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(SymmetricAlgorithmProviderData), registeredProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(
                new CryptographySettingsManageabilityProvider(subProviders));

            SymmetricAlgorithmProviderData symmetricCryptoProviderData = new SymmetricAlgorithmProviderData("symmetricCryptoProvider1", typeof(Object), "key", DataProtectionScope.CurrentUser);

            section.SymmetricCryptoProviders.Add(symmetricCryptoProviderData);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(symmetricCryptoProviderData, registeredProvider.LastConfigurationObject);
            Assert.AreEqual(null, registeredProvider.machineKey);
            Assert.AreEqual(null, registeredProvider.userKey);
        }
예제 #9
0
        public void RegisteredSecurityCacheProviderDataProviderIsCalledWithNoOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(CustomSecurityCacheProviderData), registeredProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(
                new SecuritySettingsManageabilityProvider(subProviders));

            CustomSecurityCacheProviderData securitycacheProviderData = new CustomSecurityCacheProviderData("securitycacheProvider1", typeof(Object));

            section.SecurityCacheProviders.Add(securitycacheProviderData);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(securitycacheProviderData, registeredProvider.LastConfigurationObject);
            Assert.AreEqual(null, registeredProvider.machineKey);
            Assert.AreEqual(null, registeredProvider.userKey);
        }
예제 #10
0
 public void ProviderThrowsWithConfigurationObjectOfWrongType()
 {
     provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(new TestsConfigurationSection(), true, machineKey, userKey, true, wmiSettings);
 }
예제 #11
0
        public void RegisteredHandlerDataProviderIsCalledWithCorrectOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(ReplaceHandlerData), registeredProvider);
            provider
                = new ConfigurationSectionManageabilityProviderWrapper(
                      new ExceptionHandlingSettingsManageabilityProvider(subProviders));

            ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1");

            section.ExceptionPolicies.Add(policy1);
            ExceptionTypeData exceptionType1 = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.None);

            policy1.ExceptionTypes.Add(exceptionType1);
            ExceptionHandlerData handlerData1 = new ReplaceHandlerData("handler1", "msg", typeof(ArgumentException).AssemblyQualifiedName);

            exceptionType1.ExceptionHandlers.Add(handlerData1);

            MockRegistryKey machinePoliciesKey = new MockRegistryKey(false);

            machineKey.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PoliciesKeyName, machinePoliciesKey);
            MockRegistryKey machinePolicy1Key = new MockRegistryKey(false);

            machinePoliciesKey.AddSubKey("policy1", machinePolicy1Key);
            MockRegistryKey machinePolicy1TypesKey = new MockRegistryKey(false);

            machinePolicy1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypesPropertyName, machinePolicy1TypesKey);
            MockRegistryKey machinePolicy1Type1Key = new MockRegistryKey(false);

            machinePolicy1TypesKey.AddSubKey("type1", machinePolicy1Type1Key);
            MockRegistryKey machineHandlersKey = new MockRegistryKey(false);

            machinePolicy1Type1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypeHandlersPropertyName, machineHandlersKey);
            machinePolicy1Type1Key.AddEnumValue(ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None);
            MockRegistryKey machineHandlerKey = new MockRegistryKey(false);

            machineHandlersKey.AddSubKey("handler1", machineHandlerKey);

            MockRegistryKey userPoliciesKey = new MockRegistryKey(false);

            userKey.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PoliciesKeyName, userPoliciesKey);
            MockRegistryKey userPolicy1Key = new MockRegistryKey(false);

            userPoliciesKey.AddSubKey("policy1", userPolicy1Key);
            MockRegistryKey userPolicy1TypesKey = new MockRegistryKey(false);

            userPolicy1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypesPropertyName, userPolicy1TypesKey);
            MockRegistryKey userPolicy1Type1Key = new MockRegistryKey(false);

            userPolicy1TypesKey.AddSubKey("type1", userPolicy1Type1Key);
            MockRegistryKey userHandlersKey = new MockRegistryKey(false);

            userPolicy1Type1Key.AddSubKey(ExceptionHandlingSettingsManageabilityProvider.PolicyTypeHandlersPropertyName, userHandlersKey);
            userPolicy1Type1Key.AddEnumValue(ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName, PostHandlingAction.None);
            MockRegistryKey userHandlerKey = new MockRegistryKey(false);

            userHandlersKey.AddSubKey("handler1", userHandlerKey);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, false, wmiSettings);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(handlerData1, registeredProvider.LastConfigurationObject);
            Assert.AreSame(machineHandlerKey, registeredProvider.machineKey);
            Assert.AreSame(userHandlerKey, registeredProvider.userKey);

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machinePoliciesKey,
                                                         machinePolicy1Key, machinePolicy1TypesKey, machinePolicy1Type1Key, machineHandlersKey, machineHandlerKey,
                                                         userPolicy1Key, userPolicy1TypesKey, userPolicy1Type1Key, userHandlersKey, userHandlerKey));
        }