Ejemplo n.º 1
0
        public void Should_be_possible_to_get_same_values_for_unique_list()
        {                      

            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder.
                CreateTheLocalVariable().
                    WithUnique().
                        AddLiteralComponent(@"banana").
                        AddLiteralComponent(@"apple").
                    SetInLocalVariable().
                Build();

            oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions, "the definitions was loaded");

            oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
            Assert.IsNotNull(systemCharacteristics,"the systemCharacteristics was not loaded");

            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics,definitions.variables);

            var uniqueFunctionComponent = factory.GetLocalVariableComponent(localVariable);
            Assert.IsInstanceOfType(uniqueFunctionComponent, typeof(UniqueFunctionComponent));
            IEnumerable<string> values = uniqueFunctionComponent.GetValue();
            Assert.AreEqual(2, values.Count());
            Assert.AreEqual("banana", values.ElementAt(0));
            Assert.AreEqual("apple", values.ElementAt(1));
        }
Ejemplo n.º 2
0
 public LocalVariableEvaluator(
     VariablesTypeVariableLocal_variable variable, 
     oval_system_characteristics systemCharacteristics, 
     IEnumerable<VariableType> variablesOfDefinitions,
     Modulo.Collect.OVAL.Variables.oval_variables externalVariables = null)
 {
     this.variable = variable;
     this.systemCharacteristics = systemCharacteristics;
     this.localVariableComponentFactory = new LocalVariableComponentsFactory(systemCharacteristics, variablesOfDefinitions, externalVariables);
     this.variablesOfDefinitions = variablesOfDefinitions;
 }
Ejemplo n.º 3
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");                        
        }
Ejemplo n.º 4
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");

         }
Ejemplo n.º 5
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");
         }
Ejemplo n.º 6
0
        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");
        }
Ejemplo n.º 7
0
 private IEnumerable<string> EvaluateVariable(VariablesTypeVariableLocal_variable localVariable)
 {
     LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(OvalSystemCharacteristics, OvalDefinitions.variables);
     LocalVariableComponent localVariableComponent = factory.GetLocalVariableComponent(localVariable);
     IEnumerable<string> values = localVariableComponent.GetValue();
     return values;
 }
Ejemplo n.º 8
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_throws_exception_when_the_value_type_is_not_correct_in_multiply_operation()
        {
            Assert.IsNotNull(definitions, "the definitions was loaded");
            Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded");

            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder
                .CreateTheLocalVariable()
                    .WithArithmetic()
                        .WithArithmeticOperation(ArithmeticEnumeration.multiply)
                        .AddLiteralComponent("A", SimpleDatatypeEnumeration.@string)
                        .AddLiteralComponent("B", SimpleDatatypeEnumeration.@string)
                    .SetInLocalVariable()
                .Build();

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

            try
            {
                IEnumerable<string> values = component.GetValue();
            }
            catch (Exception exc)
            {
                Assert.IsInstanceOfType(exc, typeof(FormatException), "the exception is not corret in multiply operator");
            }
        }
        public void Should_be_possible_to_instantiate_a_ConstantVariableComponent()
        {
            VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { Item = new ObjectComponentType() };

            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(null, null);
            LocalVariableComponent variableComponent = factory.GetLocalVariableComponent(localVariable);

            Assert.IsInstanceOfType(variableComponent, typeof(LocalVariableObjectComponent),"the variable component is not expected");
        }
        public void Should_be_possible_to_instantiate_a_CountFunctionComponent()
        {
            var function = new CountFunctionType() { Items = new object[] { new ObjectComponentType(), new ObjectComponentType() } };
            var localVariable = new VariablesTypeVariableLocal_variable() { Item = function };

            var factory = new LocalVariableComponentsFactory(null, null);
            var variableComponent = factory.GetLocalVariableComponent(localVariable);

            Assert.IsInstanceOfType(variableComponent, typeof(CountFunctionComponent));
            Assert.IsTrue(((CountFunctionComponent)variableComponent).QuantityOfComponents() == 2, "the quantity of component is not expected");
        }
        public void Should_be_possible_to_instantiate_an_SubstringFunctionComponent()
        {
            var function = new SubstringFunctionType() { Item = new LiteralComponentType() } ;
            var localVariable = new VariablesTypeVariableLocal_variable() { Item = function };

            var factory = new LocalVariableComponentsFactory(null, null);
            var variableComponent = factory.GetLocalVariableComponent(localVariable);

            Assert.IsInstanceOfType(variableComponent, typeof(SubStringFunctionComponent));
            Assert.IsTrue(((SubStringFunctionComponent)variableComponent).QuantityOfComponents() == 1, "the quantity of component is not expected");
        }
        public void Should_be_possible_to_calculate_the_difference_between_dates_with_objectComponent_with_multiples_values()
        {
            VariablesTypeVariableLocal_variable localVariable =
                LocalVariableBuilder
                    .CreateTheLocalVariable()
                        .WithTimeDifference()
                            .WithFirstFormat(DateTimeFormatEnumeration.day_month_year)
                            .WithSecondFormat(DateTimeFormatEnumeration.day_month_year)
                            .AddObjectComponent("value", "oval:org.mitre.oval:obj:10001")
                            .AddObjectComponent("value", "oval:org.mitre.oval:obj:10002")
                            .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, 11, 25, 0, 0, 0);
            TimeSpan firstElement = secondDate - firstDate;
            secondDate = new DateTime(2009, 12, 25, 0, 0, 0);
            TimeSpan secondElement = secondDate - firstDate;

            Assert.IsTrue(values.Count() > 0, "the quantity is not expected");
            Assert.AreEqual(values.ElementAt(0), firstElement.TotalSeconds.ToString(), "the difference is not expected"); // in seconds
            Assert.AreEqual(values.ElementAt(1), secondElement.TotalSeconds.ToString(), "the difference is not expected"); // in seconds
        }
        public void Should_be_possible_to_calculate_the_difference_between_dates_with_literal_Component_with_seconds_since_epoch()
        {
            VariablesTypeVariableLocal_variable localVariable =
                LocalVariableBuilder
                    .CreateTheLocalVariable()
                        .WithTimeDifference()
                            .WithFirstFormat(DateTimeFormatEnumeration.year_month_day)
                            .WithSecondFormat(DateTimeFormatEnumeration.seconds_since_epoch)
                            .AddLiteralComponent("2009-09-03 17:43:12")
                            .AddLiteralComponent("1251996192")
                            .SetInLocalVariable()
                    .Build();

            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable);
            IEnumerable<string> values = component.GetValue();
            
            TimeDifferenceFormatter formatter = new TimeDifferenceFormatter();
            DateTime dateFromSeconds = formatter.GetDateInFormat("1251996192", DateTimeFormatEnumeration.seconds_since_epoch);
            DateTime firstDate = new DateTime(2009, 09, 03, 17, 43, 12);
            TimeSpan difference = dateFromSeconds - firstDate;


            Assert.IsTrue(values.Count() > 0, "the quantity is not expected");
            Assert.IsTrue(values.ElementAt(0) == difference.TotalSeconds.ToString()); // in seconds

        }
        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
        }
Ejemplo n.º 16
0
        public void Should_be_possible_to_get_value_of_arithmeticFunction_with_add_operation()
        {
            VariablesTypeVariableLocal_variable localVariableInt = LocalVariableBuilder
                .CreateTheLocalVariable()
                    .WithArithmetic()
                        .WithArithmeticOperation(ArithmeticEnumeration.add)
                        .AddLiteralComponent(10.ToString(), SimpleDatatypeEnumeration.@int)
                        .AddLiteralComponent(10.ToString(), SimpleDatatypeEnumeration.@int)
                    .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(localVariableInt);
            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) == 20.ToString() , "the value is not expected");

            VariablesTypeVariableLocal_variable localVariableFloat = LocalVariableBuilder
                .CreateTheLocalVariable()
                    .WithArithmetic()
                        .WithArithmeticOperation(ArithmeticEnumeration.add)
                        .AddLiteralComponent(10.1.ToString(), SimpleDatatypeEnumeration.@float)
                        .AddLiteralComponent(10.1.ToString(), SimpleDatatypeEnumeration.@float)
                    .SetInLocalVariable()
                .Build();

            component = factory.GetLocalVariableComponent(localVariableFloat);
            Assert.IsInstanceOfType(component, typeof(ArithmeticFunctionComponent));
            values = component.GetValue();
            Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected");
            Assert.IsTrue(values.ElementAt(0) == 20.2f.ToString(), "the value is not expected");
        }
Ejemplo n.º 17
0
        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");
        }
Ejemplo n.º 18
0
        public void Should_be_possible_add_the_character_in_the_end_of_expression_if_the_expression_not_start_with_him()
        {
            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder
                .CreateTheLocalVariable()
                    .WithEnd()
                        .WithCharacter(";")
                        .AddLiteralComponent("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) == "CurrentVersion;", "the quantity of values is not expected");
        }
Ejemplo n.º 19
0
        public void Should_be_possible_to_get_value_of_concatFunction_with_two_values_of_return()
        {
            VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder.
                CreateTheLocalVariable().
                    WithConcat().
                        AddObjectComponent("oval:org.mitre.oval:obj:5000", "name").
                        AddLiteralComponent(@"\").
                    SetInLocalVariable().
                Build();

            oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions, "the definitions was loaded");

            oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
            Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded");

            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);

            LocalVariableComponent concatFunctionComponent = factory.GetLocalVariableComponent(localVariable);
            Assert.IsInstanceOfType(concatFunctionComponent, typeof(ConcatFunctionComponent));
            IEnumerable<string> values = concatFunctionComponent.GetValue();
            Assert.IsTrue(values.Count() == 2, "the quantity is not expected");
            Assert.IsTrue(values.ElementAt(0) == @"BuildLabEx\", "the value is not expected");
            Assert.IsTrue(values.ElementAt(1) == @"CSDBuildNumber\", "the value is not expected");
        }
Ejemplo n.º 20
0
        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");
        }
Ejemplo n.º 21
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");            
        }
Ejemplo n.º 22
0
        public void Should_not_be_possible_to_apply_a_beginFunction_with_multiples_components_defined_in_evaluators()
        {
            
            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);
            //add new component evaluator in beginFunctonComponent
            ((LocalVariableFunctionComponent)component).AddComponent(new ArithmeticFunctionComponent(null));

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