public void Pass_New(IList <ParameterSetupData> parameters)
        {
            // Setup
            var xml  = XmlGenerators.ProjectParamsFile(parameters);
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);

            // Execute
            var projectParams = new ProjectParams();

            projectParams.Initialize(path, null);

            // Assert
            Assert.NotNull(projectParams);

            foreach (var parameterSetupData in parameters)
            {
                var fullName = $"Project::{parameterSetupData.Name}";
                Assert.True(projectParams.Parameters.ContainsKey(fullName));
                Assert.Equal(parameterSetupData.Value, projectParams.Parameters[fullName].Value);
                Assert.Equal(parameterSetupData.Sensitive, projectParams.Parameters[fullName].Sensitive);
                Assert.Equal(parameterSetupData.DataType.ToString("G"), projectParams.Parameters[fullName].ParameterDataType.Name);
            }
        }
Exemple #2
0
        public void Fail_Decrypt_BadIv()
        {
            // Setup
            var password      = Fakes.RandomString();
            var parameterData = new ParameterSetupData()
            {
                Value     = Fakes.RandomString(),
                DataType  = DataType.String,
                Name      = Fakes.RandomString(),
                Sensitive = true
            };


            var xml  = XmlGenerators.ProjectParamsFile(new List <ParameterSetupData>(new[] { parameterData }));
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);
            var projectFile = new ProjectFileImpl();

            projectFile.Initialize(path, null);


            var    newProjectFile = new ProjectFileImpl();
            string encryptedXml;

            using (var stream = new MemoryStream())
            {
                projectFile.Save(stream, ProtectionLevel.EncryptSensitiveWithPassword, password);
                stream.Position = 0;

                var sr = new StreamReader(stream);
                encryptedXml = sr.ReadToEnd();
            }

            var encryptedXmlDoc = new XmlDocument();

            encryptedXmlDoc.LoadXml(encryptedXml);
            var ivAttribute = encryptedXmlDoc.SelectSingleNode("//*[@IV or @SSIS:IV]", encryptedXmlDoc.GetNameSpaceManager()).GetAttributeNode("IV");

            if (ivAttribute != null)
            {
                ivAttribute.Value = $"*{Fakes.RandomString()}"; // Added * to break Convert.FromBase64 false success
            }
            // Execute
            Exception exception;

            using (var stream = new MemoryStream())
            {
                encryptedXmlDoc.Save(stream);
                stream.Flush();
                stream.Position = 0;

                exception = Record.Exception(() => newProjectFile.Initialize(stream, password));
            }

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidXmlException>(exception);
            Assert.True(exception.Message.Contains("\"IV\""));
        }
Exemple #3
0
        public void Fail_Save_NoPassword(ProtectionLevel protectionLevel)
        {
            // Setup
            var parameterData = new ParameterSetupData()
            {
                Value     = Fakes.RandomString(),
                DataType  = DataType.String,
                Name      = Fakes.RandomString(),
                Sensitive = true
            };


            var xml  = XmlGenerators.ProjectParamsFile(new List <ParameterSetupData>(new[] { parameterData }));
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);
            var projectFile = new ProjectFileImpl();

            projectFile.Initialize(path, null);

            // Execute
            Exception exception;

            using (var stream = new MemoryStream())
            {
                exception = Record.Exception(() => projectFile.Save(stream, protectionLevel, null));
            }

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidPaswordException>(exception);
        }
Exemple #4
0
        public void Pass_Save_ToFile_NoSensitive()
        {
            // Setup
            var parameterData = new ParameterSetupData()
            {
                Value     = Fakes.RandomString(),
                DataType  = DataType.String,
                Name      = Fakes.RandomString(),
                Sensitive = true
            };

            var xml  = XmlGenerators.ProjectParamsFile(new List <ParameterSetupData>(new[] { parameterData }));
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);
            var projectFile = new ProjectFileImpl();

            projectFile.Initialize(path, null);

            var saveToPath = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            // Execute - save with no sensitive info
            projectFile.Save(saveToPath);

            // Assert - should not have sensitive node
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(saveToPath);
            var encryptedNode = xmlDoc.SelectSingleNode("//SSIS:Property[@SSIS:Name=\"Value\"]", xmlDoc.GetNameSpaceManager());

            Assert.Null(encryptedNode);
        }
Exemple #5
0
        public void Fail_Decrypt_NoPassword()
        {
            // Setup
            var password      = Fakes.RandomString();
            var parameterData = new ParameterSetupData()
            {
                Value     = Fakes.RandomString(),
                DataType  = DataType.String,
                Name      = Fakes.RandomString(),
                Sensitive = true
            };

            var xml  = XmlGenerators.ProjectParamsFile(new List <ParameterSetupData>(new[] { parameterData }));
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);
            var projectFile = new ProjectFileImpl();

            projectFile.Initialize(path, null);


            var    newProjectFile = new ProjectFileImpl();
            string encryptedXml;

            using (var stream = new MemoryStream())
            {
                projectFile.Save(stream, ProtectionLevel.EncryptSensitiveWithPassword, password);
                stream.Position = 0;

                var sr = new StreamReader(stream);
                encryptedXml = sr.ReadToEnd();
            }

            var encryptedXmlDoc = new XmlDocument();

            encryptedXmlDoc.LoadXml(encryptedXml);

            // Execute
            Exception exception;

            using (var stream = new MemoryStream())
            {
                encryptedXmlDoc.Save(stream);
                stream.Flush();
                stream.Position = 0;

                exception = Record.Exception(() => newProjectFile.Initialize(stream, string.Empty));
            }

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidPaswordException>(exception);
        }
Exemple #6
0
        public void Pass_Save_ToStream_NoSensitive()
        {
            // Setup
            // Use ProjectParams xml in this test
            var parameterData = new ParameterSetupData()
            {
                Value     = Fakes.RandomString(),
                DataType  = DataType.String,
                Name      = Fakes.RandomString(),
                Sensitive = true
            };

            var xml  = XmlGenerators.ProjectParamsFile(new List <ParameterSetupData>(new[] { parameterData }));
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);
            var projectFile = new ProjectFileImpl();

            projectFile.Initialize(path, null);

            // Execute
            string encryptedXml;

            using (var stream = new MemoryStream())
            {
                // Save with DontSaveSensitive
                projectFile.Save(stream);
                stream.Position = 0;
                var sr = new StreamReader(stream);
                encryptedXml = sr.ReadToEnd();
            }


            // Assert -- sensitive node should be gone
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(encryptedXml);
            var encryptedNode = xmlDoc.SelectSingleNode("//SSIS:Property[@SSIS:Name=\"Value\"]", xmlDoc.GetNameSpaceManager());

            Assert.Null(encryptedNode);
        }
Exemple #7
0
        public void Pass_Encrypt()
        {
            // Setup
            var password      = Fakes.RandomString();
            var parameterData = new ParameterSetupData()
            {
                Value     = Fakes.RandomString(),
                DataType  = DataType.String,
                Name      = Fakes.RandomString(),
                Sensitive = true
            };


            var xml  = XmlGenerators.ProjectParamsFile(new List <ParameterSetupData>(new[] { parameterData }));
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);
            var projectFile = new ProjectFileImpl();

            projectFile.Initialize(path, null);

            // Execute
            string encryptedXml;

            using (var stream = new MemoryStream())
            {
                projectFile.Save(stream, ProtectionLevel.EncryptSensitiveWithPassword, password);
                stream.Position = 0;
                var sr = new StreamReader(stream);
                encryptedXml = sr.ReadToEnd();
            }
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(encryptedXml);
            var encryptedNode = xmlDoc.SelectSingleNode("//SSIS:Property[@SSIS:Name=\"Value\"]", xmlDoc.GetNameSpaceManager());

            // Assert - should have encrypted node and Salt attribute
            Assert.True(encryptedNode?.Attributes?["Salt", XmlHelpers.Schemas.SSIS]?.Value != null);
        }
Exemple #8
0
        public void Pass_Decrypt_FromFile(ProtectionLevel protectionLevel)
        {
            // Setup
            var password      = Fakes.RandomString();
            var parameterData = new ParameterSetupData()
            {
                Value     = Fakes.RandomString(),
                DataType  = DataType.String,
                Name      = Fakes.RandomString(),
                Sensitive = true
            };


            var xml  = XmlGenerators.ProjectParamsFile(new List <ParameterSetupData>(new[] { parameterData }));
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);
            var projectFile = new ProjectFileImpl();

            projectFile.Initialize(path, null);


            var saveToPath = Path.Combine(_workingFolder, Guid.NewGuid().ToString("D"));

            projectFile.Save(saveToPath, protectionLevel, password);

            // Execute
            var newProjectFile = new ProjectFileImpl();

            newProjectFile.Initialize(saveToPath, password);

            // Assert
            var decryptedNodeValue =
                newProjectFile.FileXmlDocumentPublic.SelectSingleNode("//SSIS:Property[@SSIS:Name=\"Value\"]", newProjectFile.FileXmlDocumentPublic.GetNameSpaceManager())?.InnerText;

            Assert.Equal(parameterData.Value, decryptedNodeValue);
        }
        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);
            }
        }