public void Fail_New_ProjectParameter_InvalidDataType()
        {
            // Setup
            var name         = Fakes.RandomString();
            var value        = Fakes.RandomString();
            var scope        = Fakes.RandomString();
            var xmldoc       = new XmlDocument();
            var parameterXml = XmlGenerators.ProjectFileParameter(name, value, false, Fakes.RandomEnum <DataType>());

            xmldoc.LoadXml(parameterXml);

            var dataTypeNode = xmldoc.SelectSingleNode("//*[@SSIS:Name=\"DataType\"]", xmldoc.GetNameSpaceManager());

            if (dataTypeNode != null)
            {
                dataTypeNode.InnerText = "xyz";
            }

            // Execute
            var exception = Record.Exception(() => new ProjectParameter(scope, xmldoc.DocumentElement));

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidCastException>(exception);
        }
Exemplo n.º 2
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);
        }
        public void Pass_New_NoParameters()
        {
            // Setup
            var parameters = new Dictionary <string, string>();

            var name = Fakes.RandomString();

            var xml = XmlGenerators.UserConfigurationFile(name, parameters);

            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            // Execute
            var config = new UserConfiguration(name);

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(xml);
                    writer.Flush();
                    stream.Position = 0;

                    config.Initialize(stream, null);
                }
            }

            // Assert
            Assert.NotNull(config.Parameters);
            Assert.True(config.Parameters.Count == 0);
        }
Exemplo n.º 4
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\""));
        }
Exemplo n.º 5
0
        public void Pass_New_ProjectParameter_InvalidDataType()
        {
            // Setup
            var name         = Fakes.RandomString();
            var value        = Fakes.RandomString();
            var scope        = Fakes.RandomString();
            var xmldoc       = new XmlDocument();
            var parameterXml = XmlGenerators.ProjectFileParameter(name, value, false, Fakes.RandomEnum <DataType>());

            xmldoc.LoadXml(parameterXml);

            var dataTypeNode = xmldoc.SelectSingleNode("//*[@SSIS:Name=\"DataType\"]", xmldoc.GetNameSpaceManager());

            if (dataTypeNode != null)
            {
                dataTypeNode.InnerText = "xyz";
            }

            // Execute
            var parameter = new ProjectParameter(scope, xmldoc.DocumentElement);

            // Assert
            Assert.NotNull(parameter);
            Assert.Equal(null, parameter.ParameterDataType?.Name);
        }
Exemplo n.º 6
0
        public void Pass_SetValue(bool originalNull, bool setToNull, ParameterSource source)
        {
            // Setup
            var name   = Fakes.RandomString();
            var value  = Fakes.RandomString();
            var scope  = Fakes.RandomString();
            var xmldoc = new XmlDocument();
            // var parameterXml = CreateProjectParameterXml(name, false, originalNull, value, DataType.String);
            var parameterXml = XmlGenerators.ProjectFileParameter(name, value, false, DataType.String, originalNull);

            xmldoc.LoadXml(parameterXml);

            // Execute
            var parameter = new ProjectParameter(scope, xmldoc.DocumentElement);

            var newValue = setToNull ? null : Fakes.RandomString();

            parameter.SetValue(newValue, source);
            var testValueFromXml = xmldoc.SelectSingleNode("//*[@SSIS:Name=\"Value\"]", xmldoc.GetNameSpaceManager())?.InnerText;

            // Assert
            Assert.Equal(newValue, parameter.Value);
            Assert.Equal(source, parameter.Source);
            Assert.Equal(newValue, testValueFromXml);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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\""));
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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.
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        public void Fail_InvalidVersionBuild()
        {
            // Setup
            var xml    = XmlGenerators.ProjectManifestFile(ProtectionLevel.DontSaveSensitive, 1, 1, Fakes.RandomString(), 1, Fakes.RandomString(), new string[] { }, new string[] { }, new ParameterSetupData[] { });
            var path   = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);
            var versionBuildNode = xmlDoc.SelectSingleNode("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionBuild\"]", xmlDoc.GetNameSpaceManager());

            if (versionBuildNode != null)
            {
                versionBuildNode.InnerText = Fakes.RandomString();
            }
            ;

            File.WriteAllText(path, xmlDoc.OuterXml);

            // Execute
            var projectManifest = new ProjectManifest();
            var exception       = Record.Exception(() => projectManifest.Initialize(path, null));

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidXmlException>(exception);
            Assert.True(exception.Message.Contains("Build"));
        }
Exemplo n.º 13
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);
        }
        public void Fail_New_NoConfiguration()
        {
            // Setup
            var parameters = new Dictionary <string, string>();

            var name = Fakes.RandomString();

            var xml = XmlGenerators.UserConfigurationFile(Guid.NewGuid().ToString("N"), parameters);

            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            // Execute
            var       config = new UserConfiguration(name);
            Exception exception;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(xml);
                    writer.Flush();
                    stream.Position = 0;

                    exception = Record.Exception(() => config.Initialize(stream, null));
                }
            }

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidConfigurationNameException>(exception);
            Assert.Equal(name, (exception as InvalidConfigurationNameException)?.ConfigurationName);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        public void Pass_SetProtectionLevel(ProtectionLevel protectionLevel, int versionMajor, int versionMinor, string versionComments, int versionBuild, string description,
                                            string[] packages, string[] connectionManagers, ParameterSetupData[] parameters)
        {
            // Setup
            var xml = XmlGenerators.ProjectManifestFile(protectionLevel, versionMajor, versionMinor, versionComments, versionBuild, description, packages, connectionManagers,
                                                        parameters);
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);
            var projectManifest = new ProjectManifest();

            projectManifest.Initialize(path, null);

            var desiredProtectionLevel = projectManifest.ProtectionLevel;
            //== ProtectionLevel.DontSaveSensitive
            //? ProtectionLevel.DontSaveSensitive
            // : ProtectionLevel.ServerStorage;

            string savedXml;

            using (var stream = new MemoryStream())
            {
                projectManifest.Save(stream, desiredProtectionLevel, Fakes.RandomString());
                stream.Flush();
                stream.Position = 0;

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

            // Execute
            var testXmlDoc = new XmlDocument();

            testXmlDoc.LoadXml(savedXml);
            var projectProtectionLevel      = testXmlDoc.DocumentElement?.Attributes["SSIS:ProtectionLevel"]?.Value;
            var packageProtectionLevelNodes = testXmlDoc.SelectNodes("//SSIS:Properties/SSIS:Property[@SSIS:Name = \"ProtectionLevel\"]", testXmlDoc.GetNameSpaceManager());

            // Assert
            ProtectionLevel testProtectionLevel;

            Assert.True(Enum.TryParse(projectProtectionLevel, out testProtectionLevel));
            Assert.Equal(desiredProtectionLevel, testProtectionLevel);

            Assert.NotNull(packageProtectionLevelNodes);

            foreach (XmlElement packageProtectionElement in packageProtectionLevelNodes)
            {
                Assert.Equal(desiredProtectionLevel, (ProtectionLevel)int.Parse(packageProtectionElement.InnerText));
            }

            Assert.Equal(desiredProtectionLevel, projectManifest.ProtectionLevel);
        }
Exemplo n.º 17
0
        public void Pass_New(ProtectionLevel protectionLevel, int versionMajor, int versionMinor, string versionComments, int versionBuild, string description, string[] packages, string[] connectionManagers, ParameterSetupData[] parameters)
        {
            // Setup
            var xml  = XmlGenerators.ProjectManifestFile(protectionLevel, versionMajor, versionMinor, versionComments, versionBuild, description, packages, connectionManagers, parameters);
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);

            // Execute
            var projectManifest = new ProjectManifest();

            projectManifest.Initialize(path, null);

            // Assert
            Assert.NotNull(projectManifest);

            foreach (var parameterSetupData in parameters)
            {
                var fullName = $"Project::{parameterSetupData.Name}";
                Assert.True(projectManifest.Parameters.ContainsKey(fullName));
                Assert.Equal(parameterSetupData.Value, projectManifest.Parameters[fullName].Value);
                Assert.Equal(parameterSetupData.Sensitive, projectManifest.Parameters[fullName].Sensitive);
                Assert.Equal(parameterSetupData.DataType.ToString("G"), projectManifest.Parameters[fullName].ParameterDataType.Name);
            }

            foreach (var package in packages)
            {
                Assert.True(projectManifest.PackageNames.Contains(package));
                foreach (var parameterSetupData in parameters)
                {
                    var fullName = $"{package}::{parameterSetupData.Name}";
                    Assert.True(projectManifest.Parameters.ContainsKey(fullName));
                    Assert.Equal(parameterSetupData.Value, projectManifest.Parameters[fullName].Value);
                    Assert.Equal(parameterSetupData.Sensitive, projectManifest.Parameters[fullName].Sensitive);
                    Assert.Equal(parameterSetupData.DataType.ToString("G"), projectManifest.Parameters[fullName].ParameterDataType.Name);
                }
            }

            foreach (var connectionManager in connectionManagers)
            {
                Assert.True(projectManifest.ConnectionManagerNames.Contains(connectionManager));
            }

            Assert.Equal(versionMajor, projectManifest.VersionMajor);
            Assert.Equal(versionMinor, projectManifest.VersionMinor);
            Assert.Equal(versionBuild, projectManifest.VersionBuild);
            Assert.Equal(versionComments, projectManifest.VersionComments);
            Assert.Equal(description, projectManifest.Description);
            Assert.Equal(protectionLevel, projectManifest.ProtectionLevel);
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        public void Fail_UserKeyProtectionLevel(ProtectionLevel protectionLevel)
        {
            // Setup
            var xml  = XmlGenerators.ProjectManifestFile(protectionLevel, 1, 1, Fakes.RandomString(), 1, Fakes.RandomString(), new string[] {}, new string[] {}, new ParameterSetupData[] {});
            var path = Path.Combine(_workingFolder, Guid.NewGuid().ToString("N"));

            File.WriteAllText(path, xml);

            // Execute
            var projectManifest = new ProjectManifest();
            var exception       = Record.Exception(() => projectManifest.Initialize(path, null));

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidProtectionLevelException>(exception);
            Assert.Equal(((InvalidProtectionLevelException)exception).ProtectionLevel, protectionLevel);
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        public void Fail_New_ProjectParameter_NoScope()
        {
            // Setup
            var name         = Fakes.RandomString();
            var value        = Fakes.RandomString();
            var xmldoc       = new XmlDocument();
            var parameterXml = XmlGenerators.ProjectFileParameter(name, value, false, Fakes.RandomEnum <DataType>());

            xmldoc.LoadXml(parameterXml);

            // Execute
            var exception = Record.Exception(() => new ProjectParameter(null, xmldoc.DocumentElement));

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Exemplo n.º 22
0
        public void Pass_New_ProjectParameter_CoverDataTypes(DataType type)
        {
            // Setup
            var name         = Fakes.RandomString();
            var value        = Fakes.RandomString();
            var scope        = Fakes.RandomString();
            var xmldoc       = new XmlDocument();
            var parameterXml = XmlGenerators.ProjectFileParameter(name, value, false, type);

            xmldoc.LoadXml(parameterXml);

            // Execute
            var parameter = new ProjectParameter(scope, xmldoc.DocumentElement);

            // Assert
            Assert.NotNull(parameter);
            Assert.Equal((int)type == 1000 ? null : type.ToString("G"), parameter.ParameterDataType?.Name, StringComparer.InvariantCultureIgnoreCase);
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        public void Pass_New_ProjectParameter_DataTypeValidation()
        {
            // Setup
            var name         = Fakes.RandomString();
            var value        = "False";
            var scope        = Fakes.RandomString();
            var xmldoc       = new XmlDocument();
            var parameterXml = XmlGenerators.ProjectFileParameter(name, value, false, DataType.Boolean);

            xmldoc.LoadXml(parameterXml);

            // Execute
            var parameter = new ProjectParameter(scope, xmldoc.DocumentElement);

            // Assert
            Assert.NotNull(parameter);
            Assert.Equal("false", parameter.Value);
        }
Exemplo n.º 25
0
        public void Fail_New_ProjectParameter_EmptyName()
        {
            // Setup
            var name         = string.Empty;
            var value        = Fakes.RandomString();
            var xmldoc       = new XmlDocument();
            var parameterXml = XmlGenerators.ProjectFileParameter(name, value, Fakes.RandomBool(), Fakes.RandomEnum <DataType>(), Fakes.RandomBool());

            xmldoc.LoadXml(parameterXml);

            // Execute
            var exception = Record.Exception(() => new ProjectParameter(Fakes.RandomString(), xmldoc.DocumentElement));

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidXmlException>(exception);
            Assert.Equal(xmldoc.DocumentElement?.OuterXml, ((InvalidXmlException)exception).NodeXml);
            Assert.NotNull(exception.Message);
        }
Exemplo n.º 26
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);
        }
        public void Pass_New()
        {
            // Setup
            var parameters = new Dictionary <string, string>
            {
                { Fakes.RandomString(), Fakes.RandomString() },
                { Fakes.RandomString(), Fakes.RandomString() }
            };

            var name = Fakes.RandomString();

            var xml = XmlGenerators.UserConfigurationFile(name, parameters);

            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            // Execute
            var config = new UserConfiguration(name);

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(xml);
                    writer.Flush();
                    stream.Position = 0;

                    config.Initialize(stream, Fakes.RandomString());
                }
            }

            // Assert
            Assert.NotNull(config.Parameters);
            foreach (var parameter in parameters)
            {
                Assert.True(config.Parameters.ContainsKey(parameter.Key));
                Assert.Equal(null, config.Parameters[parameter.Key].Value);
            }
        }
Exemplo n.º 28
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);
        }
Exemplo n.º 29
0
        public void Fail_InvalidProtectionLevelString(ProtectionLevel protectionLevel, int versionMajor, int versionMinor, string versionComments, int versionBuild, string description, string[] packages, string[] connectionManagers, ParameterSetupData[] parameters)
        {
            // Setup
            var projectManifestXmlDoc = new XmlDocument();
            var xml = XmlGenerators.ProjectManifestFile(protectionLevel, versionMajor, versionMinor, versionComments, versionBuild, description, packages, connectionManagers, parameters);

            projectManifestXmlDoc.LoadXml(xml);
            projectManifestXmlDoc.DocumentElement.Attributes["SSIS:ProtectionLevel"].Value = Fakes.RandomString();

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

            File.WriteAllText(path, projectManifestXmlDoc.OuterXml);

            // Execute
            var projectManifest = new ProjectManifest();
            var exception       = Record.Exception(() => projectManifest.Initialize(path, null));

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidXmlException>(exception);
            Assert.True(exception.Message.Contains("Invalid Protection Level"));
        }
Exemplo n.º 30
0
        public void Pass_New_ProjectParameter(bool sensitive, bool withValue, DataType type)
        {
            // Setup
            var name         = Fakes.RandomString();
            var value        = Fakes.RandomString();
            var scope        = Fakes.RandomString();
            var xmldoc       = new XmlDocument();
            var parameterXml = XmlGenerators.ProjectFileParameter(name, value, sensitive, type, withValue);

            xmldoc.LoadXml(parameterXml);

            // Execute
            var parameter = new ProjectParameter(scope, xmldoc.DocumentElement);

            // Assert
            Assert.NotNull(parameter);
            Assert.Equal(withValue ? value : null, parameter.Value);
            Assert.Equal(type.ToString("G"), parameter.ParameterDataType.Name, StringComparer.InvariantCultureIgnoreCase);
            Assert.Equal(sensitive, parameter.Sensitive);
            Assert.Equal($"{scope}::{name}", parameter.Name);
            Assert.Equal(ParameterSource.Original, parameter.Source);
        }