public void Should_not_add_the_character_in_the_start_of_expression_if_the_expression_start_with_him()
        {
            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder
                                                                .CreateTheLocalVariable()
                                                                .WithBegin()
                                                                .WithCharacter(@"\Software")
                                                                .AddLiteralComponent(@"\Software\Microsoft\Windows NT\CurrentVersion")
                                                                .SetInLocalVariable()
                                                                .Build();

            LocalVariableComponentsFactory factory   = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         component = factory.GetLocalVariableComponent(localVariable);

            IEnumerable <string> values = component.GetValue();

            Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected");
            Assert.IsTrue(values.ElementAt(0) == @"\Software\Microsoft\Windows NT\CurrentVersion", "the value is not expected");
        }
        private List <string> ExecuteSubstringFunction()
        {
            LocalVariableComponent variable       = base.components.First();
            IEnumerable <string>   variableValues = variable.GetValue();

            List <string> resultsOfExpression = new List <string>();

            foreach (string value in variableValues)
            {
                int start = this.component.substring_start;

                string resultOfExpression = value.Substring(start - 1, this.calculateSubstringLength(value));

                resultsOfExpression.Add(resultOfExpression);
            }

            return(resultsOfExpression);
        }
Example #3
0
        private IEnumerable <string> ApplyEndFunction()
        {
            List <string>          values             = new List <string>();
            LocalVariableComponent component          = this.components.First();
            IEnumerable <string>   valuesOfComponents = component.GetValue();

            foreach (string value in valuesOfComponents)
            {
                if (!value.EndsWith(endFunctionType.character))
                {
                    values.Add(value + endFunctionType.character);
                }
                else
                {
                    values.Add(value);
                }
            }
            return(values);
        }
Example #4
0
        public void Should_be_possible_to_get_value_of_escaperegex_function_with_ObjectComponent()
        {
            Assert.IsNotNull(definitions, "the definitions was loaded");
            Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded");

            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder
                                                                .CreateTheLocalVariable()
                                                                .WithEscapeRegex()
                                                                .AddObjectComponent("oval:org.mitre.oval:obj:3000", "key")
                                                                .SetInLocalVariable()
                                                                .Build();

            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         localVariableComponent = factory.GetLocalVariableComponent(localVariable);
            IEnumerable <string>           values = localVariableComponent.GetValue();

            Assert.IsTrue((values.Count() == 1), "the quantity is not expected");
            Assert.IsTrue(values.ElementAt(0).Equals(@"Software\\Microsoft\\Windows\ NT\\CurrentVersion"), "the value is not expected");
        }
Example #5
0
        public void Should_be_possible_to_get_value_of_escaperegex_function_with_LiteralComponent()
        {
            Assert.IsNotNull(definitions, "the definitions was loaded");
            Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded");

            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder
                                                                .CreateTheLocalVariable()
                                                                .WithEscapeRegex()
                                                                .AddLiteralComponent(@"C:\Windows")
                                                                .SetInLocalVariable()
                                                                .Build();

            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         localVariableComponent = factory.GetLocalVariableComponent(localVariable);
            IEnumerable <string>           values = localVariableComponent.GetValue();

            Assert.IsTrue((values.Count() == 1), "the quantity is not expected");
            Assert.IsTrue(values.ElementAt(0).Equals(@"C:\\Windows"), "the value is not expected");
        }
        public void Should_be_possible_to_apply_a_beginFunction_with_ObjectComponent_with_multiple_values_defined()
        {
            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder
                                                                .CreateTheLocalVariable()
                                                                .WithBegin()
                                                                .WithCharacter(@"Software\")
                                                                .AddObjectComponent("oval:org.mitre.oval:obj:5000", "name")
                                                                .SetInLocalVariable()
                                                                .Build();

            LocalVariableComponentsFactory factory   = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         component = factory.GetLocalVariableComponent(localVariable);

            IEnumerable <string> values = component.GetValue();

            Assert.IsTrue(values.Count() == 2, "the quantity of values is not expected");
            Assert.IsTrue(values.ElementAt(0) == @"Software\BuildLabEx", "the value is not expected");
            Assert.IsTrue(values.ElementAt(1) == @"Software\CSDBuildNumber", "the value is not expected");
        }
Example #7
0
        public void Should_be_possible_to_get_value_of_splitFunction_with_ObjectComponent()
        {
            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder.
                                                                CreateTheLocalVariable().
                                                                WithSplit().
                                                                WithDelimeter(".").
                                                                AddObjectComponent("oval:org.mitre.oval:obj:8000", "value").
                                                                SetInLocalVariable().
                                                                Build();

            Assert.IsNotNull(definitions, "the definitions was loaded");
            Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded");
            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         localVariableComponent = factory.GetLocalVariableComponent(localVariable);
            IEnumerable <string>           values = localVariableComponent.GetValue();

            Assert.IsTrue((values.Count() == 2), "the quantity is not expected");
            Assert.IsTrue(values.ElementAt(0).ToString() == "4", "the value of first element is not expected");
            Assert.IsTrue(values.ElementAt(1).ToString() == "0", "the value of second element is not expected");
        }
        public void Should_be_possible_to_calculate_the_difference_between_dates_with_literal_component_with_differents_formats()
        {
            VariablesTypeVariableLocal_variable localVariable =
                LocalVariableBuilder
                .CreateTheLocalVariable()
                .WithTimeDifference()
                .WithFirstFormat(DateTimeFormatEnumeration.day_month_year)
                .WithSecondFormat(DateTimeFormatEnumeration.month_day_year)
                .AddLiteralComponent("25/09/2009 00:00:00")
                .AddLiteralComponent("09/25/2009 00:00:10")
                .SetInLocalVariable()
                .Build();


            LocalVariableComponentsFactory factory   = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         component = factory.GetLocalVariableComponent(localVariable);
            IEnumerable <string>           values    = component.GetValue();

            Assert.IsTrue(values.Count() > 0, "the quantity is not expected");
            Assert.IsTrue(values.ElementAt(0) == "10"); // in seconds
        }
Example #9
0
        public void Should_be_possible_to_get_value_of_regexcapture_function_with_ObjectComponent()
        {
            Assert.IsNotNull(definitions, "the definitions was loaded");
            Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded");

            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder.
                                                                CreateTheLocalVariable().
                                                                WithRegexCapture().
                                                                WithPattern("(B.{4})").
                                                                AddObjectComponent("oval:org.mitre.oval:obj:5000", "name").
                                                                SetInLocalVariable().
                                                                Build();

            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         localVariableComponent = factory.GetLocalVariableComponent(localVariable);
            IEnumerable <string>           values = localVariableComponent.GetValue();

            Assert.IsTrue((values.Count() == 2), "the quantity is not expected");
            Assert.IsTrue(values.ElementAt(0).Equals("Build"), "the value of first element is not expected");
            Assert.IsTrue(values.ElementAt(1).Equals("Build"), "the value of second element is not expected");
        }
        public void Should_be_possible_to_get_value_of_arithmeticFunction_with_multiply_objectComponent_operation()
        {
            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder
                                                                .CreateTheLocalVariable()
                                                                .WithArithmetic()
                                                                .WithArithmeticOperation(ArithmeticEnumeration.multiply)
                                                                .AddObjectComponent("oval:org.mitre.oval:obj:3000", "value")
                                                                .AddObjectComponent("oval:org.mitre.oval:obj:8000", "value")
                                                                .SetInLocalVariable()
                                                                .Build();

            Assert.IsNotNull(definitions, "the definitions was loaded");
            Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded");

            LocalVariableComponentsFactory factory   = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         component = factory.GetLocalVariableComponent(localVariable);

            Assert.IsInstanceOfType(component, typeof(ArithmeticFunctionComponent));
            IEnumerable <string> values = component.GetValue();

            Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected");
            Assert.IsTrue(values.ElementAt(0) == 24.ToString(), "the value is not expected");
        }
        public void Should_be_possible_to_calculate_the_difference_between_dates_with_objectComponent()
        {
            VariablesTypeVariableLocal_variable localVariable =
                LocalVariableBuilder
                .CreateTheLocalVariable()
                .WithTimeDifference()
                .WithFirstFormat(DateTimeFormatEnumeration.day_month_year)
                .WithSecondFormat(DateTimeFormatEnumeration.day_month_year)
                .AddObjectComponent("value", "oval:org.mitre.oval:obj:10000")
                .AddObjectComponent("value", "oval:org.mitre.oval:obj:10001")
                .SetInLocalVariable()
                .Build();

            LocalVariableComponentsFactory factory   = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         component = factory.GetLocalVariableComponent(localVariable);
            IEnumerable <string>           values    = component.GetValue();
            DateTime firstDate  = new DateTime(2009, 10, 25, 0, 0, 0);
            DateTime secondDate = new DateTime(2009, 09, 25, 0, 0, 0);
            TimeSpan difference = firstDate - secondDate;

            Assert.IsTrue(values.Count() > 0, "the quantity is not expected");
            Assert.AreEqual(values.ElementAt(0), difference.TotalSeconds.ToString(), "the difference is not expected"); // in seconds
        }
Example #12
0
        public void Shoud_be_possible_to_get_value_of_splitFunction_with_ObjectComponent_with_two_values()
        {
            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder.
                                                                CreateTheLocalVariable().
                                                                WithSplit().
                                                                WithDelimeter(".").
                                                                AddObjectComponent("oval:org.mitre.oval:obj:5000", "value").
                                                                SetInLocalVariable().
                                                                Build();

            Assert.IsNotNull(definitions, "the definitions was loaded");
            Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded");
            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent         localVariableComponent = factory.GetLocalVariableComponent(localVariable);
            IEnumerable <string>           values = localVariableComponent.GetValue();

            Assert.IsTrue((values.Count() == 6), "the quantity is not expected");
            Assert.IsTrue(values.ElementAt(0).ToString() == "6001", "the value of first element is not expected");
            Assert.IsTrue(values.ElementAt(1).ToString() == "18000", "the value of second element is not expected");
            Assert.IsTrue(values.ElementAt(2).ToString() == "x86fre", "the value of third element is not expected");
            Assert.IsTrue(values.ElementAt(3).ToString() == "longhorn_rtm", "the value of fourth element is not expected");
            Assert.IsTrue(values.ElementAt(4).ToString() == "080118-1840", "the value of fifth element is not expected");
            Assert.IsTrue(values.ElementAt(5).ToString() == "1616", "the value of sixth element is not expected");
        }
Example #13
0
        public override IEnumerable <string> GetValue()
        {
            LocalVariableComponent localVariableComponent = this.localVariableComponentFactory.GetLocalVariableComponent(variable);

            return(localVariableComponent.GetValue());
        }