예제 #1
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");
        }
예제 #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));
        }