Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void Should_be_possible_to_get_the_oval_results_document()
        {
            //arrange
            var loadOvalDocument = new OvalDocumentLoader();
            var session          = GetSession();
            var collectRequest   = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(this.SessionDefault);
            var newDefinitiondoc = new DefinitionDocument()
            {
                OriginalId = "01",
                Text       = loadOvalDocument.GetFakeOvalDefinitions("OvalResultDocumentTest.xml").GetDefinitionsXml()
            };

            session.Store(newDefinitiondoc);
            collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid;
            var id = this.SaveCollectRequest(collectRequest, session);

            var collectResult = new Result();

            collectResult.SystemCharacteristics = loadOvalDocument.GetFakeOvalSystemCharacteristics("OvalResultDocumentTest.xml").GetSystemCharacteristicsXML();

            var ovalDocumentGenerator = new OvalDefinitionDocumentGenerator();
            //act
            oval_results document = ovalDocumentGenerator.GetDocument(collectRequest, newDefinitiondoc.Text, collectResult);

            //assert
            Assert.IsNotNull(document);
            Assert.AreEqual(ResultEnumeration.@true, document.results[0].definitions[0].result);
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
        private string GetOvalDefinitionsXml(string resourceFolder, string resouceName)
        {
            var resourcePath = String.Format("{0}.{1}", resourceFolder, resouceName);

            try
            {
                var ovalDefinitionsAsStream = new OvalDocumentLoader().GetStreamFrom(resourcePath);
                if (ovalDefinitionsAsStream == null)
                {
                    Assert.Fail("A resource with name '{0}' could not be found.", resourcePath);
                }

                var ovalDefinitionsAsXml = new StreamReader(ovalDefinitionsAsStream).ReadToEnd();
                Assert.IsNotNull(ovalDefinitionsAsXml, "Could not possible to get Oval Definitions Document from stream.");
                Assert.IsTrue(ovalDefinitionsAsXml.Contains("<oval_definitions "), "The document is not an Oval Definitions file. Missing <oval_definitions> begin tag.");
                Assert.IsTrue(ovalDefinitionsAsXml.Contains("</oval_definitions>"), "The document is not an Oval Definitions file. Missing </oval_definitions> closing tag.");

                return(ovalDefinitionsAsXml);
            }
            catch (Exception ex)
            {
                Assert.Fail("An error occurred while trying to load resource '{0}': '{1}'.", resourcePath, ex.Message);
                return(null);
            }
        }
Ejemplo n.º 5
0
        public void Should_be_possible_to_evaluate_a_Set_in_the_ObjectType()
        {
            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:6000");

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

            Assert.IsNotNull(result, "the items expected is null");
            Assert.AreEqual(3, result.Result.Count(), "the quantity of items is not expected");
            Assert.AreEqual(FlagEnumeration.complete, result.ObjectFlag, "the object flag is not expected");

            string element = result.Result.Where <string>(item => item == "1").SingleOrDefault();

            Assert.IsNotNull(element, "the element expected is not exits");
            element = result.Result.Where <string>(item => item == "2").SingleOrDefault();
            Assert.IsNotNull(element, "the element expected is not exits");
            element = result.Result.Where <string>(item => item == "3").SingleOrDefault();
            Assert.IsNotNull(element, "the element expected is not exits");
        }
        public void When_it_was_not_possible_to_establish_a_connection_to_target_the_status_of_collect_result_must_be_error()
        {
            IDocumentSession fakeSession = provider.GetSession();
            var fakeRequestCollect       = this.GetCollectRequest();
            var definitions      = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            var newDefinitiondoc = new DefinitionDocument()
            {
                OriginalId = "01", Text = definitions.GetDefinitionsXml()
            };

            session.Store(newDefinitiondoc);
            fakeRequestCollect.OvalDefinitionsId = newDefinitiondoc.Oid;

            var factory          = new CollectExecutionManagerFactory(fakeRequestCollect, session);
            var executionManager =
                factory
                .CreateExecutionManagerWithCannotConnectToHostExceptionScenario(
                    this.GetResultForRegistry(fakeRequestCollect, new List <String>()),
                    this.GetResultForFamily(fakeRequestCollect, new string[] { "oval:org.mitre.oval:obj:1000" }.ToList()),
                    true);

            //fakeRequestCollect.Collects.Add(new CollectExecution(session));
            //fakeRequestCollect.Collects.Add(new CollectExecution(session));
            //fakeRequestCollect.Collects.Add(new CollectExecution(session));
            session.SaveChanges();
            executionManager.ExecuteCollect(fakeSession, fakeRequestCollect, FamilyEnumeration.windows);


            var requestCollectAfterExecution = session.Load <CollectRequest>(fakeRequestCollect.Oid);

            Assert.AreEqual(CollectStatus.Error, requestCollectAfterExecution.Result.Status);
        }
Ejemplo n.º 7
0
        public void MyTestInitialize()
        {
            OvalDocumentLoader ovalDocument = new OvalDocumentLoader();

            definitions           = ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            systemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        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");
        }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
        public void Should_be_possible_finalize_the_collectRequest_if_the_number_of_execution_exceeds_of_limits()
        {
            IDocumentSession fakeSession    = provider.GetSession();
            CollectRequest   collectRequest = this.GetCollectRequest();
            oval_definitions definitions    = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            var objList = new List <ObjectType>();

            objList.Add(new family_object()
            {
                id = "oval:org.mitre.oval:obj:1000"
            });
            objList.Add(new file_object()
            {
                id = "oval:org.mitre.oval:obj:5000"
            });
            definitions.objects = objList.ToArray();

            var newDefinitiondoc = new DefinitionDocument()
            {
                OriginalId = "01", Text = definitions.GetDefinitionsXml()
            };

            session.Store(newDefinitiondoc);
            collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid;
            CollectExecutionManagerFactory factory = new CollectExecutionManagerFactory(collectRequest, session);
            List <string>           registryObjectsThatNotProcessInFirstTime = new List <string>();
            List <string>           familyObjectsThatNotProcessInFirstTime   = new List <string>();
            CollectExecutionManager executionManager = factory.CreateExecutionManagerForTheSuccessScenario(this.GetResultForRegistry(collectRequest, registryObjectsThatNotProcessInFirstTime),
                                                                                                           this.GetResultForFamily(collectRequest, familyObjectsThatNotProcessInFirstTime));

            session.Store(collectRequest);
            var newExecution1 = new CollectExecution()
            {
                RequestId = collectRequest.Oid
            };

            session.Store(newExecution1);
            var newExecution2 = new CollectExecution()
            {
                RequestId = collectRequest.Oid
            };

            session.Store(newExecution2);
            var newExecution3 = new CollectExecution()
            {
                RequestId = collectRequest.Oid
            };

            session.Store(newExecution3);
            executionManager.ExecuteCollect(fakeSession, collectRequest, FamilyEnumeration.windows);
            session.SaveChanges();

            CollectRequest collectRequestAfterExecute = session.Load <CollectRequest>(collectRequest.Oid.ToString());

            Assert.IsNotNull(collectRequest);
            Assert.AreEqual(4, collectRequestAfterExecute.GetNumberOfExecutions(session));
            Assert.IsTrue(collectRequestAfterExecute.isClosed());
        }
Ejemplo n.º 12
0
        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;
        }
Ejemplo n.º 13
0
        public TargetPlatformDiscovererTests()
        {
            var ovalDocLoader = new OvalDocumentLoader();

            this.WindowsOvalDefinitionsSample     = ovalDocLoader.GetFakeOvalDefinitions("fdcc_xpfirewall_oval.xml");
            this.UnixOvalDefinitionsSample        = ovalDocLoader.GetFakeOvalDefinitions("RM7-scap-sol10-oval.xml");
            this.IndependentOvalDefinitionsSample = ovalDocLoader.GetFakeOvalDefinitions("definitions_all_independent.xml");
            this.CiscoIosOvalDefinitionsSample    = ovalDocLoader.GetFakeOvalDefinitions("modulo-ios122-oval.xml");
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 15
0
        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");
        }
Ejemplo n.º 16
0
        public void Should_be_possible_to_validate_a_valid_OvalDefinitions()
        {
            var validOvalDefinitionsXml = new OvalDocumentLoader().GetFakeOvalDefinitions("oval.org.mitre.oval.def.5368.xml").GetDefinitionsXml();

            var ovalDefinitionsValidator = new OvalDefinitionsValidator(validOvalDefinitionsXml);

            Assert.IsNotNull(ovalDefinitionsValidator.Schema, "The Oval Definitions validation result cannot be null.");
            Assert.IsTrue(ovalDefinitionsValidator.Schema.IsValid, "The Oval Definitions Schema validation result must be TRUE.");
        }
Ejemplo n.º 17
0
        public void Should_be_possible_to_validate_an_OvalDefinitions_with_valid_schematron()
        {
            var validOvalDefinitionsXml = new OvalDocumentLoader().GetFakeOvalDefinitions("oval.org.mitre.oval.def.5368.xml").GetDefinitionsXml();
            var validator = new OvalDefinitionsValidator(validOvalDefinitionsXml);

            ValidationResultShouldBeValidFor(validator.Schema);

            var schematronValidationResult = validator.ValidateSchematron();

            ValidationResultShouldBeValidFor(schematronValidationResult);
        }
Ejemplo n.º 18
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");
        }
Ejemplo n.º 19
0
        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");
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        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");
        }
Ejemplo n.º 22
0
        private string CreateOvalVariablesWithFakeValues()
        {
            var ovalDefinitions   = new OvalDocumentLoader().GetFakeOvalDefinitions(FDCC_XPFIREWALL);
            var externalVariables = ovalDefinitions.variables.OfType <VariablesTypeVariableExternal_variable>();

            var externalVariablesWithFakeValue = new oval_variables();

            foreach (var declaredExternalVariable in externalVariables)
            {
                var newFakeVariable = CreateVariableType(declaredExternalVariable);
                externalVariablesWithFakeValue.variables.Add(newFakeVariable);
            }

            return(externalVariablesWithFakeValue.GetXmlDocument());
        }
        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");
        }
        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");
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
        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_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");
        }
Ejemplo n.º 28
0
        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");
        }
Ejemplo n.º 29
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);
            }
        }
Ejemplo n.º 30
0
        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");
        }