public void Fail_Decrypt_NoIv() { // Setup var password = Fakes.RandomString(); var value = Fakes.RandomString(); var value1 = Fakes.RandomString(); var xml = XmlGenerators.PackageFile(value, 2, value1); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); var package = new Package(); package.Initialize(path, null); var newPackage = new Package(); string encryptedXml; using (var stream = new MemoryStream()) { package.Save(stream, ProtectionLevel.EncryptSensitiveWithPassword, password); stream.Position = 0; var sr = new StreamReader(stream); encryptedXml = sr.ReadToEnd(); } var encryptedXmlDoc = new XmlDocument(); encryptedXmlDoc.LoadXml(encryptedXml); var xmlNodeList = encryptedXmlDoc.SelectNodes("//*[@IV or @SSIS:IV]", encryptedXmlDoc.GetNameSpaceManager()); if (xmlNodeList != null) { foreach (XmlNode node in xmlNodeList) { var ivAttribute = node.GetAttributeNode("IV"); if (ivAttribute != null) { ivAttribute.Value = string.Empty; } } } // Execute Exception exception; using (var stream = new MemoryStream()) { encryptedXmlDoc.Save(stream); stream.Flush(); stream.Position = 0; exception = Record.Exception(() => newPackage.Initialize(stream, password)); } // Assert Assert.NotNull(exception); Assert.IsType <InvalidXmlException>(exception); Assert.True(exception.Message.Contains("\"IV\"")); }
public void Fail_Decrypt_BadPassword() { // Setup var password = Fakes.RandomString(); var value = Fakes.RandomString(); var value1 = Fakes.RandomString(); var xml = XmlGenerators.PackageFile(value, 2, value1); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); var package = new Package(); package.Initialize(path, null); // Execute var newPackage = new Package(); Exception exception; using (var stream = new MemoryStream()) { package.Save(stream, ProtectionLevel.EncryptSensitiveWithPassword, password); stream.Position = 0; exception = Record.Exception(() => newPackage.Initialize(stream, Fakes.RandomString())); } // Assert Assert.NotNull(exception); Assert.IsType <InvalidPaswordException>(exception); }
public void Pass_Decrypt() { // Setup var password = Fakes.RandomString(); var value = Fakes.RandomString(); var value1 = Fakes.RandomString(); var xml = XmlGenerators.PackageFile(value, 2, value1); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); var package = new Package(); package.Initialize(path, null); // Execute var newPackage = new Package(); using (var stream = new MemoryStream()) { package.Save(stream, ProtectionLevel.EncryptSensitiveWithPassword, password); stream.Position = 0; newPackage.Initialize(stream, password); } // Assert - if there is no exception - we are good. }
public void Pass_Encrypt() { // Setup var password = Fakes.RandomString(); var xml = XmlGenerators.PackageFile(Fakes.RandomString(), 2, Fakes.RandomString()); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); // Execute var package = new Package(); package.Initialize(path, null); string encryptedXml; using (var stream = new MemoryStream()) { package.Save(stream, ProtectionLevel.EncryptSensitiveWithPassword, password); stream.Position = 0; var sr = new StreamReader(stream); encryptedXml = sr.ReadToEnd(); } var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(encryptedXml); // Assert Assert.True(xmlDoc.SelectNodes("//*[name(.)=\"EncryptedData\"]")?.Count == 2); }
public void Fail_InvalidProtectionLevel() { // Setup var xml = XmlGenerators.PackageFile(Fakes.RandomString(), 1000, Fakes.RandomString()); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); // Execute var package = new Package(); var exception = Record.Exception(() => package.Initialize(path, null)); // Assert Assert.NotNull(exception); Assert.IsType <InvalidXmlException>(exception); }
public void Pass_Get_ProtectionLevel() { // Setup var xml = XmlGenerators.PackageFile(Fakes.RandomString(), 2, Fakes.RandomString()); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); // Execute var package = new Package(); package.Initialize(path, null); // Assert Assert.NotNull(package); Assert.Equal((ProtectionLevel)2, package.ProtectionLevel); }
public void NoProtectionLevel_DefaultDontSaveSensitive() { // Setup var xml = XmlGenerators.PackageFile(Fakes.RandomString(), 1000, Fakes.RandomString()); xml = xml.Replace("DTS:ProtectionLevel=\"1000\"", ""); var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N")); File.WriteAllText(path, xml); // Execute var package = new Package(); var exception = Record.Exception(() => package.Initialize(path, null)); // Assert Assert.Null(exception); Assert.Equal(ProtectionLevel.DontSaveSensitive, package.ProtectionLevel); }
internal void CreateDtprojFiles(string projectName, string configurationName) { var packages = new[] { $"p_{Fakes.RandomString()}.dtsx", $"p_{Fakes.RandomString()}.dtsx" }; var connections = new[] { $"c_{Fakes.RandomString()}.conmgr", $"c_{Fakes.RandomString()}.conmgr" }; var paramName = Fakes.RandomString(); var projectParamsXml = XmlGenerators.ProjectParamsFile(new List <ParameterSetupData>() { { new ParameterSetupData { Value = Fakes.RandomString(), Name = paramName, DataType = DataType.String, Sensitive = false } } }); var projectManifestXml = XmlGenerators.ProjectManifestFile(ProtectionLevel.DontSaveSensitive, 1, 2, Fakes.RandomString(), 3, "Descr", packages, connections, new[] { new ParameterSetupData() { Value = Fakes.RandomString(), DataType = DataType.String, Name = Fakes.RandomString(), Sensitive = false }, }); var configurationXml = XmlGenerators.ConfigurationFile(configurationName, new Dictionary <string, string>() { { $"Project::{paramName}", Fakes.RandomString() } }); var configurationsXmlDoc = new XmlDocument(); configurationsXmlDoc.LoadXml(configurationXml); var userConfigurationXml = XmlGenerators.UserConfigurationFile(configurationName, new Dictionary <string, string>() { { $"Project::{paramName}", Fakes.RandomString() } }); var dtprojXml = $@"<?xml version=""1.0"" encoding=""utf-8""?> <Project xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <DeploymentModel>Project</DeploymentModel> <DeploymentModelSpecificContent> <Manifest> {projectManifestXml} </Manifest> </DeploymentModelSpecificContent> <Configurations> {configurationsXmlDoc.SelectSingleNode("//Configuration", configurationsXmlDoc.GetNameSpaceManager())?.OuterXml} </Configurations> </Project>"; var dtproj = projectName; File.WriteAllText(Path.Combine(_workingFolder, dtproj), dtprojXml); File.WriteAllText(Path.Combine(_workingFolder, "Project.params"), projectParamsXml); File.WriteAllText($"{Path.Combine(_workingFolder, dtproj)}.user", userConfigurationXml); foreach (var package in packages) { var packageXml = XmlGenerators.PackageFile(Fakes.RandomString(), (int)ProtectionLevel.EncryptSensitiveWithPassword, Fakes.RandomString()); File.WriteAllText($"{Path.Combine(_workingFolder, package)}", packageXml); } foreach (var connection in connections) { var projectConnectionsXml = XmlGenerators.ProjectConnectionsFile(); File.WriteAllText($"{Path.Combine(_workingFolder, connection)}", projectConnectionsXml); } }