private void NullEncryptorTests(string instanceName) { MockStorageEncryptionProvider.Encrypted = false; MockStorageEncryptionProvider.Decrypted = false; CacheManagerSettings settings = (CacheManagerSettings)TestConfigurationSource.GenerateConfiguration().GetSection(CacheManagerSettings.SectionName); CacheStorageData cacheStorageData = settings.BackingStores.Get(settings.CacheManagers.Get(instanceName).CacheStorage); StorageEncryptionProviderData encryptionProviderData = settings.EncryptionProviders.Get(cacheStorageData.StorageEncryption); IStorageEncryptionProvider provider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>(encryptionProviderData.Name, TestConfigurationSource.GenerateConfiguration()); Assert.IsNotNull(provider); byte[] input = new byte[] { 0, 1, 2, 3, 4, 5 }; byte[] encrypted = provider.Encrypt(input); Assert.IsTrue(MockStorageEncryptionProvider.Encrypted, "static encrypted"); Assert.IsTrue(CompareBytes(input, encrypted), "no encryption performed"); byte[] decrypted = provider.Decrypt(encrypted); Assert.IsTrue(MockStorageEncryptionProvider.Decrypted, "static decrypted"); Assert.IsTrue(CompareBytes(encrypted, decrypted), "no decryption performed"); Assert.IsTrue(CompareBytes(input, decrypted), "no decryption performed2"); }
/// <summary> /// <para>Gets the <see cref="Type"/> of the <see cref="IStorageEncryptionProvider"/> for the factory to create for a <see cref="CacheManager"/>.</para> /// </summary> /// <param name="cacheManagerName"> /// <para>The name of the cache manager to create the <see cref="IStorageEncryptionProvider"/>.</para> /// </param> /// <returns> /// <para>The <see cref="Type"/> of the <see cref="IStorageEncryptionProvider"/> to create.</para> /// </returns> protected override Type GetConfigurationType(string cacheManagerName) { CachingConfigurationView view = (CachingConfigurationView)CreateConfigurationView(); StorageEncryptionProviderData data = view.GetStorageEncryptionProviderData(cacheManagerName); return(GetType(data.TypeName)); }
public void ManageabilityProviderGeneratesProperAdmContent() { DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource(); configurationSource.Add(CacheManagerSettings.SectionName, section); IsolatedStorageCacheStorageData storage1, storage2; CacheManagerData manager1, manager2; StorageEncryptionProviderData encryption1; section.BackingStores.Add(storage1 = new IsolatedStorageCacheStorageData("storage1", "encryption1", "partition1")); section.CacheManagers.Add(manager1 = new CacheManagerData("manager1", 100, 200, 300, "storage1")); section.EncryptionProviders.Add(encryption1 = new StorageEncryptionProviderData("encryption1", typeof(object))); section.BackingStores.Add(storage2 = new IsolatedStorageCacheStorageData("storage2", "", "partition2")); section.CacheManagers.Add(manager2 = new CacheManagerData("manager2", 100, 200, 300, "storage2")); MockConfigurationElementManageabilityProvider subProvider = new MockConfigurationElementManageabilityProvider(); Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary <Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(IsolatedStorageCacheStorageData), subProvider); subProviders.Add(typeof(StorageEncryptionProviderData), subProvider); provider = new ConfigurationSectionManageabilityProviderWrapper(new CacheManagerSettingsManageabilityProvider(subProviders)); MockAdmContentBuilder contentBuilder = new MockAdmContentBuilder(); provider.InvokeAddAdministrativeTemplateDirectives(contentBuilder, section, configurationSource, "TestApp"); Assert.AreEqual(3, subProvider.configurationObjects.Count); Assert.AreSame(storage1, subProvider.configurationObjects[0]); Assert.AreSame(encryption1, subProvider.configurationObjects[1]); Assert.AreSame(storage2, subProvider.configurationObjects[2]); MockAdmContent content = contentBuilder.GetMockContent(); IEnumerator <AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator(); Assert.IsTrue(categoriesEnumerator.MoveNext()); Assert.AreEqual(Resources.CachingSectionCategoryName, categoriesEnumerator.Current.Name); IEnumerator <AdmCategory> subCategoriesEnumerator = categoriesEnumerator.Current.Categories.GetEnumerator(); Assert.IsTrue(subCategoriesEnumerator.MoveNext()); Assert.AreEqual(Resources.CacheManagersCategoryName, subCategoriesEnumerator.Current.Name); IEnumerator <AdmPolicy> cacheManagerPoliciesEnumerator = subCategoriesEnumerator.Current.Policies.GetEnumerator(); Assert.IsTrue(cacheManagerPoliciesEnumerator.MoveNext()); Assert.AreEqual(String.Format(Resources.CacheManagerPolicyNameTemplate, manager1.Name), cacheManagerPoliciesEnumerator.Current.Name); Assert.IsTrue(cacheManagerPoliciesEnumerator.MoveNext()); Assert.AreEqual(String.Format(Resources.CacheManagerPolicyNameTemplate, manager2.Name), cacheManagerPoliciesEnumerator.Current.Name); Assert.IsFalse(cacheManagerPoliciesEnumerator.MoveNext()); Assert.IsFalse(subCategoriesEnumerator.MoveNext()); IEnumerator <AdmPolicy> sectionPoliciesEnumerator = categoriesEnumerator.Current.Policies.GetEnumerator(); Assert.IsTrue(sectionPoliciesEnumerator.MoveNext()); Assert.AreEqual(Resources.CacheManagerSettingsPolicyName, sectionPoliciesEnumerator.Current.Name); Assert.IsFalse(sectionPoliciesEnumerator.MoveNext()); Assert.IsFalse(categoriesEnumerator.MoveNext()); }
private StorageEncryptionProviderData GetStorageEncryptionData() { StorageEncryptionProviderData storageEncryptionData = null; if (Nodes.Count == 1) { storageEncryptionData = ((StorageEncryptionNode)Nodes[0]).StorageEncryptionProviderData; } return(storageEncryptionData); }
public void RegisteredEncryptionProviderDataProviderIsCalledWithCorrectOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary <Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(StorageEncryptionProviderData), registeredProvider); provider = new ConfigurationSectionManageabilityProviderWrapper( new CacheManagerSettingsManageabilityProvider(subProviders)); StorageEncryptionProviderData data = new StorageEncryptionProviderData("encryptionprovider1", typeof(Object)); section.EncryptionProviders.Add(data); MockRegistryKey machineEncryptionProvidersKey = new MockRegistryKey(false); machineKey.AddSubKey(CacheManagerSettingsManageabilityProvider.EncryptionProvidersKeyName, machineEncryptionProvidersKey); MockRegistryKey machineEncryptionProviderKey = new MockRegistryKey(false); machineEncryptionProvidersKey.AddSubKey("encryptionprovider1", machineEncryptionProviderKey); MockRegistryKey machineOtherEncryptionProviderKey = new MockRegistryKey(false); machineEncryptionProvidersKey.AddSubKey("encryptionprovider2", machineOtherEncryptionProviderKey); MockRegistryKey userEncryptionProvidersKey = new MockRegistryKey(false); userKey.AddSubKey(CacheManagerSettingsManageabilityProvider.EncryptionProvidersKeyName, userEncryptionProvidersKey); MockRegistryKey userEncryptionProviderKey = new MockRegistryKey(false); userEncryptionProvidersKey.AddSubKey("encryptionprovider1", userEncryptionProviderKey); MockRegistryKey userOtherEncryptionProviderKey = new MockRegistryKey(false); userEncryptionProvidersKey.AddSubKey("encryptionprovider2", userOtherEncryptionProviderKey); provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings); Assert.IsTrue(registeredProvider.called); Assert.AreSame(data, registeredProvider.LastConfigurationObject); Assert.AreEqual(machineEncryptionProviderKey, registeredProvider.machineKey); Assert.AreEqual(userEncryptionProviderKey, registeredProvider.userKey); Assert.IsTrue( MockRegistryKey.CheckAllClosed(machineEncryptionProvidersKey, machineEncryptionProviderKey, machineOtherEncryptionProviderKey, userEncryptionProvidersKey, userEncryptionProviderKey, userOtherEncryptionProviderKey)); }
public void RegisteredEncryptionProviderDataProviderIsCalledWithNoOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary <Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(StorageEncryptionProviderData), registeredProvider); provider = new CacheManagerSettingsManageabilityProvider(subProviders); StorageEncryptionProviderData data = new StorageEncryptionProviderData("encryptionprovider1", typeof(Object)); section.EncryptionProviders.Add(data); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(data, registeredProvider.LastConfigurationObject); Assert.AreEqual(null, registeredProvider.machineKey); Assert.AreEqual(null, registeredProvider.userKey); }
public void ThenReturnsNewlyConfiguredInstanceAfterReconfigureOfStorageEncryptionProvider() { MockStorageEncryptionProvider.Instantiated = false; storageEncryptionProviderData = new MockStorageEncryptionProviderData("Storage Encryption"); cacheSettings.EncryptionProviders.Add(storageEncryptionProviderData); IsolatedStorageCacheStorageData isolatedStoreData = new IsolatedStorageCacheStorageData(); isolatedStoreData.Name = "Isolated Storage"; isolatedStoreData.PartitionName = "entlib"; isolatedStoreData.StorageEncryption = storageEncryptionProviderData.Name; cacheSettings.BackingStores.Add(isolatedStoreData); cacheManagerData.CacheStorage = isolatedStoreData.Name; configurationSource.DoSourceChanged(new string[] { CacheManagerSettings.SectionName }); CacheManagerFactory factory = new CacheManagerFactory(serviceLcoator); ICacheManager cacheManager = factory.Create(cacheSettings.DefaultCacheManager); Assert.IsTrue(MockStorageEncryptionProvider.Instantiated); }
private void CreateEncryptionNode(ConfigurationNode storageNode, string storageEncryption) { if (string.IsNullOrEmpty(storageEncryption)) { return; } StorageEncryptionProviderData encryptionProviderData = cacheManagerSettings.EncryptionProviders.Get(storageEncryption); if (null == encryptionProviderData) { LogError(storageNode, string.Format(CultureInfo.CurrentUICulture, Resources.ExceptionNoEncrypitonProviderDefined, storageEncryption)); return; } ConfigurationNode encyrptionNode = NodeCreationService.CreateNodeByDataType(encryptionProviderData.GetType(), new object[] { encryptionProviderData }); if (null == encyrptionNode) { LogNodeMapError(storageNode, encryptionProviderData.GetType()); return; } storageNode.AddNode(encyrptionNode); }
/// <summary> /// Creates node with sepecifed display name and configuration data. /// </summary> /// <param name="data">The configuration data.</param> protected StorageEncryptionNode(StorageEncryptionProviderData data) : base() { this.data = data; }
/// <summary> /// Adds a <see cref="StorageEncryptionProviderData"/> to the <see cref="CacheManagerSettings"/> as well as adds a reference to the <see cref="IBackingStore"/> instance currently being configured. /// </summary> /// <param name="storageEncyption">The <see cref="StorageEncryptionProviderData"/> that should be added to configuration.</param> protected void AddEncryptionProviderToCachingConfigurationAndBackingStore(StorageEncryptionProviderData storageEncyption) { contextExtension.CachingSettings.EncryptionProviders.Add(storageEncyption); contextExtension.CacheStorage.StorageEncryption = storageEncyption.Name; }
/// <devdoc> /// ADM templates for caching are different from the other blocks' templates to match the configuration console's /// user experience. Instead of having separate categories with policies for cache managers, backing stores and /// encryption providers, the policy for a cache manager includes the parts for its backing store and eventual /// encryption provider. /// </devdoc> void AddAdministrativeTemplateDirectivesForCacheManagers(AdmContentBuilder contentBuilder, CacheManagerSettings configurationSection, IConfigurationSource configurationSource, String sectionKey) { String cacheManagersKey = sectionKey + @"\" + CacheManagersKeyName; String backingStoresKey = sectionKey + @"\" + BackingStoresKeyName; String encryptionProvidersKey = sectionKey + @"\" + EncryptionProvidersKeyName; contentBuilder.StartCategory(Resources.CacheManagersCategoryName); { foreach (CacheManagerDataBase cacheManagerDataBase in configurationSection.CacheManagers) { if (cacheManagerDataBase is CustomCacheManagerData) { customManageabilityProvider.AddAdministrativeTemplateDirectives(contentBuilder, cacheManagerDataBase, configurationSource, cacheManagersKey); } else { String cacheManagerPolicyKey = cacheManagersKey + @"\" + cacheManagerDataBase.Name; contentBuilder.StartPolicy(String.Format(CultureInfo.InvariantCulture, Resources.CacheManagerPolicyNameTemplate, cacheManagerDataBase.Name), cacheManagerPolicyKey); { if (cacheManagerDataBase is CacheManagerData) { CacheManagerData cacheManagerData = (CacheManagerData)cacheManagerDataBase; contentBuilder.AddNumericPart(Resources.CacheManagerExpirationPollFrequencyInSecondsPartName, CacheManagerExpirationPollFrequencyInSecondsPropertyName, cacheManagerData.ExpirationPollFrequencyInSeconds); contentBuilder.AddNumericPart(Resources.CacheManagerMaximumElementsInCacheBeforeScavengingPartName, CacheManagerMaximumElementsInCacheBeforeScavengingPropertyName, cacheManagerData.MaximumElementsInCacheBeforeScavenging); contentBuilder.AddNumericPart(Resources.CacheManagerNumberToRemoveWhenScavengingPartName, CacheManagerNumberToRemoveWhenScavengingPropertyName, cacheManagerData.NumberToRemoveWhenScavenging); // append the cache manager's backing store parts contentBuilder.AddTextPart(Resources.BackingStoreSettingsPartName); CacheStorageData backingStoreData = configurationSection.BackingStores.Get(cacheManagerData.CacheStorage); ConfigurationElementManageabilityProvider backingStoreDataManageablityProvider = GetSubProvider(backingStoreData.GetType()); AddAdministrativeTemplateDirectivesForElement(contentBuilder, backingStoreData, backingStoreDataManageablityProvider, configurationSource, backingStoresKey); // append the backing store's encryption provider parts if (!String.IsNullOrEmpty(backingStoreData.StorageEncryption)) { contentBuilder.AddTextPart(Resources.StorageEncryptionProviderSettingsPartName); StorageEncryptionProviderData encryptionProviderData = configurationSection.EncryptionProviders.Get(backingStoreData.StorageEncryption); ConfigurationElementManageabilityProvider encryptionProviderDataManageabilityProvider = GetSubProvider(encryptionProviderData.GetType()); AddAdministrativeTemplateDirectivesForElement(contentBuilder, encryptionProviderData, encryptionProviderDataManageabilityProvider, configurationSource, encryptionProvidersKey); } } } contentBuilder.EndPolicy(); } } } contentBuilder.EndCategory(); }
public void ManageabilityProviderGeneratesProperAdmContent() { DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource(); configurationSource.Add(CacheManagerSettings.SectionName, section); IsolatedStorageCacheStorageData storage1, storage2; CacheManagerData manager1, manager2; StorageEncryptionProviderData encryption1; section.BackingStores.Add(storage1 = new IsolatedStorageCacheStorageData("storage1", "encryption1", "partition1")); section.CacheManagers.Add(manager1 = new CacheManagerData("manager1", 100, 200, 300, "storage1")); section.EncryptionProviders.Add(encryption1 = new StorageEncryptionProviderData("encryption1", typeof(object))); section.BackingStores.Add(storage2 = new IsolatedStorageCacheStorageData("storage2", "", "partition2")); section.CacheManagers.Add(manager2 = new CacheManagerData("manager2", 100, 200, 300, "storage2")); MockConfigurationElementManageabilityProvider subProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(IsolatedStorageCacheStorageData), subProvider); subProviders.Add(typeof(StorageEncryptionProviderData), subProvider); provider = new CacheManagerSettingsManageabilityProvider(subProviders); MockAdmContentBuilder contentBuilder = new MockAdmContentBuilder(); provider.AddAdministrativeTemplateDirectives(contentBuilder, section, configurationSource, "TestApp"); Assert.AreEqual(3, subProvider.configurationObjects.Count); Assert.AreSame(storage1, subProvider.configurationObjects[0]); Assert.AreSame(encryption1, subProvider.configurationObjects[1]); Assert.AreSame(storage2, subProvider.configurationObjects[2]); MockAdmContent content = contentBuilder.GetMockContent(); IEnumerator<AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator(); Assert.IsTrue(categoriesEnumerator.MoveNext()); IEnumerator<AdmCategory> subCategoriesEnumerator = categoriesEnumerator.Current.Categories.GetEnumerator(); Assert.IsTrue(subCategoriesEnumerator.MoveNext()); IEnumerator<AdmPolicy> cacheManagerPoliciesEnumerator = subCategoriesEnumerator.Current.Policies.GetEnumerator(); Assert.IsTrue(cacheManagerPoliciesEnumerator.MoveNext()); Assert.IsTrue(cacheManagerPoliciesEnumerator.MoveNext()); Assert.IsFalse(cacheManagerPoliciesEnumerator.MoveNext()); Assert.IsFalse(subCategoriesEnumerator.MoveNext()); IEnumerator<AdmPolicy> sectionPoliciesEnumerator = categoriesEnumerator.Current.Policies.GetEnumerator(); Assert.IsTrue(sectionPoliciesEnumerator.MoveNext()); Assert.IsFalse(sectionPoliciesEnumerator.MoveNext()); Assert.IsFalse(categoriesEnumerator.MoveNext()); }
public void RegisteredEncryptionProviderDataProviderIsCalledWithCorrectOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(StorageEncryptionProviderData), registeredProvider); provider = new CacheManagerSettingsManageabilityProvider(subProviders); StorageEncryptionProviderData data = new StorageEncryptionProviderData("encryptionprovider1", typeof(Object)); section.EncryptionProviders.Add(data); MockRegistryKey machineEncryptionProvidersKey = new MockRegistryKey(false); machineKey.AddSubKey(CacheManagerSettingsManageabilityProvider.EncryptionProvidersKeyName, machineEncryptionProvidersKey); MockRegistryKey machineEncryptionProviderKey = new MockRegistryKey(false); machineEncryptionProvidersKey.AddSubKey("encryptionprovider1", machineEncryptionProviderKey); MockRegistryKey machineOtherEncryptionProviderKey = new MockRegistryKey(false); machineEncryptionProvidersKey.AddSubKey("encryptionprovider2", machineOtherEncryptionProviderKey); MockRegistryKey userEncryptionProvidersKey = new MockRegistryKey(false); userKey.AddSubKey(CacheManagerSettingsManageabilityProvider.EncryptionProvidersKeyName, userEncryptionProvidersKey); MockRegistryKey userEncryptionProviderKey = new MockRegistryKey(false); userEncryptionProvidersKey.AddSubKey("encryptionprovider1", userEncryptionProviderKey); MockRegistryKey userOtherEncryptionProviderKey = new MockRegistryKey(false); userEncryptionProvidersKey.AddSubKey("encryptionprovider2", userOtherEncryptionProviderKey); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(data, registeredProvider.LastConfigurationObject); Assert.AreEqual(machineEncryptionProviderKey, registeredProvider.machineKey); Assert.AreEqual(userEncryptionProviderKey, registeredProvider.userKey); Assert.IsTrue( MockRegistryKey.CheckAllClosed(machineEncryptionProvidersKey, machineEncryptionProviderKey, machineOtherEncryptionProviderKey, userEncryptionProvidersKey, userEncryptionProviderKey, userOtherEncryptionProviderKey)); }
public void RegisteredEncryptionProviderDataProviderIsCalledWithNoOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(StorageEncryptionProviderData), registeredProvider); provider = new CacheManagerSettingsManageabilityProvider(subProviders); StorageEncryptionProviderData data = new StorageEncryptionProviderData("encryptionprovider1", typeof(Object)); section.EncryptionProviders.Add(data); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(data, registeredProvider.LastConfigurationObject); Assert.AreEqual(null, registeredProvider.machineKey); Assert.AreEqual(null, registeredProvider.userKey); }