public LocalVariableVariablesComponent(
     VariableType localVariable, 
     VariableComponentType variable, 
     IEnumerable<VariableType> variablesOfOvalDefinitions, 
     oval_system_characteristics systemCharacteristics,
     Modulo.Collect.OVAL.Variables.oval_variables externalVariables = null)
 {
     this.variablesOfDefinitions = variablesOfOvalDefinitions;
     this.variable = variable;
     this.systemCharacteristics = systemCharacteristics;
     this.localVariable = localVariable;
     this.variableEvaluator = new VariableEvaluator(variablesOfDefinitions, systemCharacteristics, externalVariables);
 }
Пример #2
0
        private IEnumerable<VariableValue> GetVariableValuesFrom(CollectRequest collectRequest, IDocumentSession session)
        {
            List<VariableValue> variableValues = new List<VariableValue>();
            VariableType[] variables = collectRequest.GetOvalVariables(session).ToArray();
            VariableEvaluator variableEvaluator = new VariableEvaluator(variables, collectRequest.GetSystemCharacteristics(session), collectRequest.GetExternalVariables());
            foreach (VariableType variable in collectRequest.GetOvalVariables(session))
            {
                IEnumerable<string> valuesOfVariable = variableEvaluator.EvaluateVariable(variable.id);
                IEnumerable<ObjectType> objectsByVariable = collectRequest.GetObjectTypesByVariableId(session, variable.id);
                variableValues.AddRange(this.CreateVariableValuesFrom(objectsByVariable, variable.id, valuesOfVariable));

                IEnumerable<StateType> statesByVariable = collectRequest.GetStateTypeByVariableId(session, variable.id);
                variableValues.AddRange(this.CreateVariableValuesFrom(statesByVariable, variable.id, valuesOfVariable));
            }
            return variableValues;
        }
Пример #3
0
        private OVAL.Definitions.variableEvaluator.VariableValue CreateVariableValuesFromStateEntity(
            string stateID,
            string stateEntityVariable,
            oval_results ovalResults)
        {
            if (string.IsNullOrEmpty(stateEntityVariable))
                return null;

            var variableEvaluator =
                new VariableEvaluator(
                    ovalResults.oval_definitions.variables.ToArray(),
                    ovalResults.results[0].oval_system_characteristics,
                    ovalResults.EvaluatedExternalVariables);

            var variableValues = variableEvaluator.EvaluateVariable(stateEntityVariable);

            return new VariableValue(stateID, stateEntityVariable, variableValues);
        }
Пример #4
0
        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");      
        }
Пример #5
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");    
        }
Пример #6
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");                       
        }
Пример #7
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");           
        }