public void MyTestInitialize()
 {
     OvalDocumentLoader ovalDocument = new OvalDocumentLoader();
     this.systemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_sets.xml");
     oval_definitions definitions = ovalDocument.GetFakeOvalDefinitions("definitionsWithSet.xml");
     this.states = definitions.states;
 }
        public void MyTestInitialize()
        {
            OvalDocumentLoader ovalDocument = new OvalDocumentLoader();

             this.OvalDefinitions = ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
             this.OvalSystemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
        }
 public void Should_be_possible_to_get_a_SystemData_by_the_reference()
 {
     oval_system_characteristics systemCharacteristics = new OvalDocumentLoader().GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
     ItemType itemtype = systemCharacteristics.GetSystemDataByReferenceId("8");
     Assert.IsNotNull(itemtype, "the itemType was not found");
     Assert.IsInstanceOfType(itemtype, typeof(registry_item), "the object is not type expeceted");
 }
        public void Should_be_possible_to_get_an_ObjectType_by_the_OvalId()
        {
            oval_system_characteristics systemCharacteristics = new OvalDocumentLoader().GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
            sc::ObjectType objectType = systemCharacteristics.GetCollectedObjectByID("oval:org.mitre.oval:obj:1000");

            Assert.IsNotNull(objectType, "the objectype was not found");
            Assert.AreEqual("oval:org.mitre.oval:obj:1000", objectType.id, "the objectType is not expected");
            Assert.AreEqual(1, objectType.reference.Count(), "the item_ref count is not expected");
        }
Beispiel #5
0
        public static set GetSetFromDefinitionsOfRegistryObject(string definitionsName, string idRegistryObject)
        {
            OvalDocumentLoader ovalDocument = new OvalDocumentLoader();
            oval_definitions definition = ovalDocument.GetFakeOvalDefinitions(definitionsName);

            ObjectType objectType = definition.objects.Where(x => x.id == idRegistryObject).SingleOrDefault();

            set registryObjectSet = GetSetFromRegistryObject((registry_object)objectType);
            return registryObjectSet;
        }
Beispiel #6
0
        public static set GetSetFromDefinitionsOfRegistryObject(string definitionsName, string idRegistryObject)
        {
            OvalDocumentLoader ovalDocument = new OvalDocumentLoader();
            oval_definitions   definition   = ovalDocument.GetFakeOvalDefinitions(definitionsName);

            ObjectType objectType = definition.objects.Where(x => x.id == idRegistryObject).SingleOrDefault();

            set registryObjectSet = GetSetFromRegistryObject((registry_object)objectType);

            return(registryObjectSet);
        }
Beispiel #7
0
        public void Should_be_possible_to_concat_the_values_of_components_in_the_list()
        {
            var systemCharacteristics = new OvalDocumentLoader().GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
            Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded");

            var components = this.GetLocalVariableComponentList(systemCharacteristics);
            var concat = new OvalConcatFunction(components);
            var concatValues = concat.ConcatValues();

            Assert.AreEqual(4, concatValues.Count, "the quantity of values is not expected");
            Assert.AreEqual(@"BuildLabEx\SoftwareType", concatValues.ElementAt(0), NOT_EXPECTED_VALUE_WAS_FOUND);
            Assert.AreEqual(@"BuildLabEx\SystemRoot", concatValues.ElementAt(1), NOT_EXPECTED_VALUE_WAS_FOUND);
            Assert.AreEqual(@"CSDBuildNumber\SoftwareType",concatValues.ElementAt(2), NOT_EXPECTED_VALUE_WAS_FOUND);
            Assert.AreEqual(@"CSDBuildNumber\SystemRoot", concatValues.ElementAt(3), NOT_EXPECTED_VALUE_WAS_FOUND);
        }
Beispiel #8
0
        public void Should_be_possible_to_evaluate_a_set_with_another_set_defintion()
        {
            OvalDocumentLoader ovalDocument = new OvalDocumentLoader();
            sc.oval_system_characteristics systemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_sets.xml");
            oval_definitions definitions = ovalDocument.GetFakeOvalDefinitions("definitionsWithSet.xml");
            IEnumerable<StateType> states = definitions.states;

            set registryObjectSet = SetFactory.GetSetFromDefinitionsOfRegistryObject("definitionsWithSet.xml", "oval:org.mitre.oval:obj:5000");

            SetEvaluator setEvaluator = new SetEvaluator(systemCharacteristics,states, null);
            SetResult result = setEvaluator.Evaluate(registryObjectSet);

            Assert.IsNotNull(result, "the items expected is null");
            Assert.AreEqual(1, result.Result.Count(), "the quantity of items is not expected");

            string element = result.Result.Where<string>(item => item == "3").SingleOrDefault();
            Assert.IsNotNull(element, "the element expected is not exits");
        }
        public void Should_be_evaluate_a_local_Variables_of_an_entityType()
        {
            OvalDocumentLoader ovalDocument = new OvalDocumentLoader();
            oval_definitions definitions = ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions, "the definitios is not created");

            oval_system_characteristics systemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
            Assert.IsNotNull(definitions, "the system Characteristics is not was created");

            EntityObjectStringType entityType = new EntityObjectStringType();
            entityType.var_ref = "oval:org.mitre.oval:var:4000";

            VariableEvaluator variableEvaluator = new VariableEvaluator(definitions.variables, systemCharacteristics, null);
            IEnumerable<string> values = variableEvaluator.Evaluate(entityType);
            Assert.IsNotNull(values, "the valueToMatch of variable is null");
            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");      
        }
        public void Should_not_evaluate_a_variable_if_the_entityType_not_have_a_variable_reference()
        {
            oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsSimple.xml");
            Assert.IsNotNull(definitions, "the definitios is not created");

            registry_object registryObject = (registry_object)definitions.objects[1];

            Dictionary<String, EntityObjectStringType> registryEntities = this.GetRegistryEntitiesFromName(registryObject);
            EntitySimpleBaseType keyName = registryEntities[registry_object_ItemsChoices.key.ToString()];

            VariableEvaluator variableEvaluator = new VariableEvaluator(definitions.variables,null, null);
            IEnumerable<string> values = variableEvaluator.Evaluate(keyName);
            Assert.IsNotNull(values, "the valueToMatch of variable is null");
            Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected");
            Assert.IsTrue(values.ElementAt(0) == @"Software\Microsoft\Windows NT\CurrentVersion", "the valueToMatch is not expected");    
        }
        public void Should_be_possible_evaluate_a_variable_given_variableID()
        {
            oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("oval_definitions.oval.org.mitre.oval.def.5921.xml");
            Assert.IsNotNull(definitions, "the definitios is not created");

            VariableEvaluator variableEvaluator = new VariableEvaluator(definitions.variables, null, null);
            IEnumerable<string> values = variableEvaluator.EvaluateVariable("oval:org.mitre.oval:var:932");
            Assert.IsNotNull(values, "the valueToMatch of variable is null");
            Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected");
            Assert.IsTrue(values.ElementAt(0) == "1", "the valueToMatch is not expected");                       
        }
Beispiel #12
0
 public void Should_be_possible_to_verify_if_state_type_has_references_for_variableId()
 {
     oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithSet.xml");
     StateType state = definitions.states.Where(obj => obj.id == "oval:org.mitre.oval:ste:100").SingleOrDefault();
     bool result = state.HasReferenceForVariable("oval:org.mitre.oval:var:3000");            
     Assert.AreEqual(true, result);
 }
        public void Should_be_possible_to_compare_two_unix_itemTypes()
        {
            var systemCharacteristics =
                new OvalDocumentLoader()
                    .GetFakeOvalSystemCharacteristics("system_characteristics_with_sets.xml");
            var itemType = systemCharacteristics.GetSystemDataByReferenceId("6");
            var otherItemType = systemCharacteristics.GetSystemDataByReferenceId("7");
            var itemTypeComparator = new GenericItemTypeComparator();

            var resultComparator = itemTypeComparator.IsEquals(itemType, otherItemType);

            Assert.IsFalse(resultComparator, "the item types are not equals");
            otherItemType = systemCharacteristics.GetSystemDataByReferenceId("1");
            resultComparator = itemTypeComparator.IsEquals(itemType, otherItemType);
            Assert.IsFalse(resultComparator, "the item types are not equals");
        }
Beispiel #14
0
        public void Should_be_possible_to_verify_if_an_object_references_a_variable()
        {
            oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithConstantVariable.xml");
            Assert.AreEqual(definitions.objects.Count(), 2, "the quantity of objectypes in definitions is not expected");

            Assert.IsTrue(definitions.objects[1].HasReferenceForVariable("oval:org.mitre.oval:var:3000"), "the object is not have referece fo variable");
            Assert.IsFalse(definitions.objects[0].HasReferenceForVariable("oval:org.mitre.oval:var:3000"), "the object has referece fo variable");

        }
        public void Should_be_possible_to_get_value_of_an_LiteralComponentType()
        {
            oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions, "the definitions is null");

            LiteralComponentType literalComponent = new LiteralComponentType() { datatype = Modulo.Collect.OVAL.Common.SimpleDatatypeEnumeration.@string,
                                                                                 Value = @"\System32"};

            LocalVariableLiteralComponent literalVariable = new LocalVariableLiteralComponent(literalComponent);
            IEnumerable<string> values = literalVariable.GetValue();
            Assert.IsTrue(values.Count() > 0, "the quantity of values is not expected");
            Assert.IsTrue(values.ElementAt(0) == @"\System32", "the value is not expected");
        }
        public void Should_be_possible_to_get_value_to_variableComponent_by_the_constantVariable()
        {
            oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions);
            VariableComponentType variableComponent = new VariableComponentType() { var_ref = "oval:org.mitre.oval:var:3000" };
            VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { id = "oval:org.mitre.oval:var:5000" };

            LocalVariableVariablesComponent variableComponentEvaluator = new LocalVariableVariablesComponent(localVariable,variableComponent,definitions.variables,null);
            IEnumerable<string> values = variableComponentEvaluator.GetValue();
            Assert.IsTrue(values.Count() > 0, "the quantity of values is not expected.");
            Assert.IsTrue(values.ElementAt(0) == "Multiprocessor Free", "the value is not expected");
        }
        public void Should_not_be_possible_to_get_value_to_variableComponent_if_this_variable_refer_his_localVariable()
        {
            OvalDocumentLoader ovalDocuments = new OvalDocumentLoader();

            oval_definitions definitions = ovalDocuments.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions);
            oval_system_characteristics systemSystemCharacteristics = ovalDocuments.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
            Assert.IsNotNull(systemSystemCharacteristics);

            VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { id = "oval:org.mitre.oval:var:4000" };

            VariableComponentType variableComponent = new VariableComponentType() { var_ref = "oval:org.mitre.oval:var:4000" };
            LocalVariableVariablesComponent variableComponentEvaluator = new LocalVariableVariablesComponent(localVariable,variableComponent, definitions.variables, systemSystemCharacteristics);
            IEnumerable<string> values = variableComponentEvaluator.GetValue();
            Assert.IsTrue(values.Count() == 0);
        }
        public void Should_be_possible_to_get_value_to_variableComponent_by_the_LocalVariable()
        {
            OvalDocumentLoader ovalDocuments = new OvalDocumentLoader();

            oval_definitions definitions = ovalDocuments.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions);
            oval_system_characteristics systemSystemCharacteristics = ovalDocuments.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
            Assert.IsNotNull(systemSystemCharacteristics);
            VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { id = "oval:org.mitre.oval:var:5000" };

            VariableComponentType variableComponent = new VariableComponentType() { var_ref = "oval:org.mitre.oval:var:4000" };
            LocalVariableVariablesComponent variableComponentEvaluator = new LocalVariableVariablesComponent(localVariable,variableComponent, definitions.variables, systemSystemCharacteristics);
            IEnumerable<string> values = variableComponentEvaluator.GetValue();
            Assert.IsTrue(values.Count() > 0, "the quantity of value is not expected");
            Assert.IsTrue(values.ElementAt(0) == @"Software\Microsoft\Windows NT\CurrentVersion", "the value is not expected");
        }
Beispiel #19
0
 private oval_results GetOvalResultsSample()
 {
     var ovalDocLoader = new OvalDocumentLoader();
     var fakeDefinitions = ovalDocLoader.GetFakeOvalDefinitions("definitionsWithExternalVariables.xml");
     var fakeSystemCharacteristics = ovalDocLoader.GetFakeOvalSystemCharacteristics("system_characteristics_with_variables.xml");
     
     return oval_results.CreateFromDocuments(fakeDefinitions, fakeSystemCharacteristics, null);
 }
Beispiel #20
0
        private oval_results GetOvalResultsFromDefinitionsAndSystemCharacteristicsDocuments(
            string definitionsResourceName, 
            string systemCharacteristicsResourceName,
            oval_variables evaluatedExternalVariables)
        {
            try
            {
                var ovalDocumentLoader = new OvalDocumentLoader();
                var definitions = ovalDocumentLoader.GetFakeOvalDefinitions(definitionsResourceName);
                var systemCharacteristics = ovalDocumentLoader.GetFakeOvalSystemCharacteristics(systemCharacteristicsResourceName);

                return oval_results.CreateFromDocuments(definitions, systemCharacteristics, evaluatedExternalVariables);
            }
            catch (Exception ex)
            {
                Assert.Fail(String.Format(CREATE_OVAL_RESULTS_DOC_ERROR_MSG, ex.Message));
                return null;
            }
        }
 public void MyTestInitialize()
 {
     this.ovalDocument = new OvalDocumentLoader();
 }
        public void Should_be_possible_to_get_value_of_local_variable()
        {
            VariablesTypeVariableLocal_variable variable = CreateALocalVariable();
            oval_system_characteristics systemCharacteristics = new OvalDocumentLoader().GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");

            LocalVariableEvaluator localVariableEvaluator = new LocalVariableEvaluator(variable, systemCharacteristics,null);
            IEnumerable<string> values = localVariableEvaluator.GetValue();
            Assert.IsTrue(values.Count() > 0, "the quantity of values is not expected.");
            Assert.IsTrue(values.ElementAt(0) == @"Software\Microsoft\Windows NT\CurrentVersion", "the value is not expected");
        }
Beispiel #23
0
        public void Shoud_be_possible_to_get_EntityBaseTypes_from_an_ObjectType()
        {

            oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsSimple.xml");
            Assert.AreEqual(definitions.objects.Count(), 2, "the quantity of objectypes in definitions is not expected");

            IEnumerable<EntitySimpleBaseType> entitiesFromRegistryObject = definitions.objects[1].GetEntityBaseTypes();
            Assert.AreEqual(entitiesFromRegistryObject.Count(), 3, "the quantity of entityTypes for registry_Object is not expected");
            Assert.AreEqual(entitiesFromRegistryObject.ElementAt(0).Value, "HKEY_LOCAL_MACHINE");
        }
        public void Should_be_possible_to_evaluate_a_constant_variables_of_an_entitytype()
        {
            oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("oval_definitions.oval.org.mitre.oval.def.5921.xml");
            Assert.IsNotNull(definitions, "the definitios is not created");

            EntityObjectStringType entityType = new EntityObjectStringType();
            entityType.var_ref = "oval:org.mitre.oval:var:932";

            VariableEvaluator variableEvaluator = new VariableEvaluator(definitions.variables, null, null);
            IEnumerable<string> values = variableEvaluator.Evaluate(entityType);
            Assert.IsNotNull(values, "the valueToMatch of variable is null");
            Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected");
            Assert.IsTrue(values.ElementAt(0) == "1", "the valueToMatch is not expected");           
        }
        public void Should_be_possible_to_compare_two_itemTypes()
        {
            oval_system_characteristics systemCharacteristics = new OvalDocumentLoader().GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");

            ItemType itemType = systemCharacteristics.GetSystemDataByReferenceId("3");
            ItemType otherItemType = systemCharacteristics.GetSystemDataByReferenceId("3");

            GenericItemTypeComparator itemTypeComparator = new GenericItemTypeComparator();
            bool resultComparator = itemTypeComparator.IsEquals(itemType, otherItemType);

            Assert.IsTrue(resultComparator, "the item types are not equals");

            otherItemType = systemCharacteristics.GetSystemDataByReferenceId("1");
            resultComparator = itemTypeComparator.IsEquals(itemType, otherItemType);
            Assert.IsFalse(resultComparator, "the item types are not equals");
        }
Beispiel #26
0
        public void Should_be_possible_to_handle_with_state_referencing_a_variable_with_multiple_values()
        {
            var ovalDefinitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitions_all_linux_with_state_referencing_variable_with_multi_values.xml");
            var ovalSystemCharacteristics = new OvalDocumentLoader().GetFakeOvalSystemCharacteristics("system_characteristics_with_state_referencing_variable_with_multi_values.xml");
            var ovalResults = oval_results.CreateFromDocuments(ovalDefinitions, ovalSystemCharacteristics, null);

            ovalResults.Analyze();

            var firstDefinition = ovalResults.results.First().definitions.First();
            Assert.AreEqual(ResultEnumeration.unknown, firstDefinition.result);

        }