Exemplo n.º 1
0
        public static oval_results CreateFromDocuments(
            Definitions.oval_definitions definitions,
            oval_system_characteristics systemcharacteristics,
            oval_variables evaluatedExternalVariables)
        {
            oval_results newResult = new oval_results();

            newResult.generator        = DocumentHelpers.GetDefaultGenerator();
            newResult.oval_definitions = definitions;
            newResult.results          = new List <SystemType> {
                new SystemType()
            };
            newResult.results[0].oval_system_characteristics = systemcharacteristics;
            newResult.EvaluatedExternalVariables             = evaluatedExternalVariables;

            // Generate new Definition Result entries
            foreach (var definition in definitions.definitions)
            {
                if ((definition.criteria == null) || (definition.criteria.Items == null) || (definition.criteria.Items.Count() < 1))
                {
                    continue;
                }
                var newDefinitionResult = new DefinitionType(definition);
                newResult.results[0].definitions.Add(newDefinitionResult);
            }
            // Generate new Test Result entries
            foreach (var test in definitions.tests)
            {
                var newTestResult = new TestType(test);
                newResult.results[0].tests.Add(newTestResult);
            }
            return(newResult);
        }
Exemplo n.º 2
0
 public VariableEvaluator(IEnumerable <VariableType> variables, oval_system_characteristics systemCharacteristics, oval_variables externalVariables)
 {
     this.variablesOfDefinitions = variables;
     this.evaluatorFactory       = new EvaluatorFactory();
     this.systemCharacteristics  = systemCharacteristics;
     this.externalVariables      = externalVariables;
 }
Exemplo n.º 3
0
        public void Test_Load_Invalid_Variables_Document()
        {
            IEnumerable <string> errors;
            oval_variables       target = oval_variables.GetOvalVariablesFromText(samplexml2, out errors);

            Assert.IsNull(target);
            Assert.IsTrue(errors.Count() > 0);
        }
Exemplo n.º 4
0
        public void Test_Load_Variables_Document()
        {
            IEnumerable <string> errors;
            oval_variables       target = oval_variables.GetOvalVariablesFromText(samplexml1, out errors);

            Assert.IsNotNull(target);
            Assert.AreEqual(0, errors.Count());
            Assert.AreEqual(2, target.variables.Count);
        }
        private oval_variables CreateOvalVariablesFromExternalVariables(Definitions.VariablesTypeVariableExternal_variable[] externalVariables)
        {
            var newOvalVariables = new oval_variables();
            foreach (var externalVar in externalVariables)
            {
                var newVariableType = this.GetVariableType(externalVar.id, externalVar.datatype, new string[] { string.Empty });
                newOvalVariables.variables.Add(newVariableType);
            }

            return newOvalVariables;
        }
Exemplo n.º 6
0
        private oval_results Analyse(oval_variables ovalVariables)
        {
            var ovalResultsDoc =
                GetOvalResultsFromDefinitionsAndSystemCharacteristicsDocuments(
                    "definitionsWithStateWithExternalVariables.xml",
                    "system_characteristics_with_state_with_external_variables.xml",
                    ovalVariables);

            ovalResultsDoc.Analyze();

            return(ovalResultsDoc);
        }
Exemplo n.º 7
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());
        }
Exemplo n.º 8
0
        public string GetEvaluatedExternalVariables(Dictionary <String, String> externalVariablesValues, IEnumerable <Definitions.VariablesTypeVariableExternal_variable> externalVariables)
        {
            var variables = new oval_variables
            {
                generator = Collect.OVAL.Common.DocumentHelpers.GetDefaultGenerator(),
                variables = new List <VariableType>()
            };

            foreach (var item in externalVariables)
            {
                string defaultValue = externalVariablesValues.Where(n => n.Key == item.id).Select(m => m.Value).SingleOrDefault() ?? String.Empty;
                variables.variables.Add(new VariableType(item.datatype, item.id, defaultValue));
            }

            return(variables.GetXmlDocument());
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        public void Test_Create_Variables_Document()
        {
            // Arrange / Act
            oval_variables variables = new oval_variables();

            variables.variables.Add(new VariableType(SimpleDatatypeEnumeration.@string, "oval:XX:var:1", "Red", "Green"));
            variables.variables.Add(new VariableType(SimpleDatatypeEnumeration.boolean, "oval:XX:var:2", "true"));

            //XmlSerializer xmlSerializer = new XmlSerializer(typeof(oval_variables));
            //StringBuilder sb = new StringBuilder();
            //StringWriter sw = new StringWriter(sb);
            //xmlSerializer.Serialize(sw, variables);

            IEnumerable <string> schemaErrors;
            oval_variables       result = oval_variables.GetOvalVariablesFromText(variables.GetXmlDocument(), out schemaErrors);

            // Assert
            Assert.AreEqual(0, schemaErrors.Count(), string.Join(Environment.NewLine, schemaErrors.ToArray()));
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.variables.Count);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Creates the correct implementation of variable for the evaluation.
 /// </summary>
 /// <param name="variable">The oval definitions variable.</param>
 /// <returns></returns>
 public Evaluator CreateVariable(VariableType variable, oval_system_characteristics sytemCharacteristics, IEnumerable <VariableType> variablesOfDefinitions, oval_variables externalVariables)
 {
     if (variable is VariablesTypeVariableConstant_variable)
     {
         return(new ConstantVariableEvaluator((VariablesTypeVariableConstant_variable)variable));
     }
     else if (variable is VariablesTypeVariableLocal_variable)
     {
         return(new LocalVariableEvaluator((VariablesTypeVariableLocal_variable)variable, sytemCharacteristics, variablesOfDefinitions, externalVariables));
     }
     else if (variable is VariablesTypeVariableExternal_variable)
     {
         return(new ExternalVariableEvaluator((VariablesTypeVariableExternal_variable)variable, externalVariables));
     }
     return(null);
 }
Exemplo n.º 12
0
 public ExternalVariableEvaluator(VariablesTypeVariableExternal_variable variable, oval_variables external_variables)
 {
     this.variable           = variable;
     this.external_variables = external_variables;
 }