Example #1
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");
        }
Example #2
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;
 }
Example #3
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;
 }
        public void MyTestInitialize()
        {
            OvalDocumentLoader ovalDocument = new OvalDocumentLoader();

             this.OvalDefinitions = ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
             this.OvalSystemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
        }
Example #5
0
 public SetEvaluator(oval_system_characteristics systemCharacteristics, IEnumerable<StateType> states, VariablesEvaluated variables)
 {
     this.systemCharacteristics = systemCharacteristics;
     this.ovalDefinitionStates = states;
     this.variables = variables;
     this.filterEvaluator = new FilterEvaluator(this.systemCharacteristics, this.ovalDefinitionStates, this.variables);
 }
 public ConcatFunctionComponent(ConcatFunctionType concatFunctionType, IEnumerable<VariableType> variablesOfDefinitions, oval_system_characteristics systemCharacteristics)
 {
     this.variablesOfDefinitions = variablesOfDefinitions;
     this.systemCharacteristics = systemCharacteristics;
     this.concatFunctionType = concatFunctionType;
     this.concatFunction = new OvalConcatFunction(base.components);
 }
Example #7
0
        public static oval_system_characteristics GetOvalSystemCharacteristicsFromStream(Stream scDocument, out IEnumerable <string> schemaErrors)
        {
            var _schemaErrors = new List <string>();

            PrepareSerializer();

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ValidationType          = ValidationType.Schema;
            settings.XmlResolver             = xmlResolver;
            settings.ValidationFlags         = XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.AllowXmlAttributes;
            settings.ValidationEventHandler += (o, args) => { if (args.Severity == XmlSeverityType.Error)
                                                              {
                                                                  _schemaErrors.Add(args.Message);
                                                              }
            };
            XmlReader reader = XmlReader.Create(scDocument, settings);
            oval_system_characteristics result = xmlSerializer.Deserialize(reader) as oval_system_characteristics;

            reader.Close();

            if (_schemaErrors.Count > 0)
            {
                result = null;
            }

            schemaErrors = _schemaErrors;
            return(result);
        }
 public SystemCharacteristicsBuilder()
 {
     systemCharacteristics = new oval_system_characteristics();
     sequence = 1;
     newObjectTypes = new List<ObjectType>();
     newItemTypes = new List<ItemType>();
     addedItemsId = new List<String>();
 }
 /// <summary>
 /// Creates the system characteristics given the probeResult.
 /// </summary>
 /// <param name="probeResult">result of the probe execution.</param>
 /// <returns></returns>
 public oval_system_characteristics CreateSystemCharacteristics(ProbeResult probeResult)
 {
     oval_system_characteristics systemCharacteristics = new oval_system_characteristics();
     systemCharacteristics.collected_objects = this.GetCollectedObjects(probeResult);
     systemCharacteristics.system_data = this.GetSystemType(probeResult);
     systemCharacteristics.generator = this.GetGenerator();
     systemCharacteristics.system_info = this.GetSystemInfo(probeResult);            
     return systemCharacteristics;
 }
 public LocalVariableComponentsFactory(
     oval_system_characteristics systemCharacteristics,
     IEnumerable<VariableType> variablesOfDefinitions,
     Modulo.Collect.OVAL.Variables.oval_variables externalVariables = null)
 {
     this.variablesOfDefinitions = variablesOfDefinitions;
     this.systemCharacteristics = systemCharacteristics;
     this.ExternalVariables = externalVariables;
 }
Example #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;
 }
Example #12
0
 public LocalVariableEvaluator(
     VariablesTypeVariableLocal_variable variable, 
     oval_system_characteristics systemCharacteristics, 
     IEnumerable<VariableType> variablesOfDefinitions,
     Modulo.Collect.OVAL.Variables.oval_variables externalVariables = null)
 {
     this.variable = variable;
     this.systemCharacteristics = systemCharacteristics;
     this.localVariableComponentFactory = new LocalVariableComponentsFactory(systemCharacteristics, variablesOfDefinitions, externalVariables);
     this.variablesOfDefinitions = variablesOfDefinitions;
 }
Example #13
0
        public static CollectInfo CreateFakeCollectInfo(
            IEnumerable<Definitions.ObjectType> objects, 
            VariablesEvaluated variables = null, 
            oval_system_characteristics systemCharacteristics = null)
        {
            CollectInfo collectInfo = new CollectInfo();
            collectInfo.Variables = (variables == null) ? new VariablesEvaluated(new List<VariableValue>()) : variables;
            collectInfo.ObjectTypes = objects;
            collectInfo.SystemCharacteristics = systemCharacteristics;

            return collectInfo;
        }
 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);
 }
Example #15
0
        private List<LocalVariableComponent> GetLocalVariableComponentList(oval_system_characteristics systemCharacteristics)
        {
            var components = new List<LocalVariableComponent>();
            var literalComponent = new LiteralComponentType() { Value = @"\" };
            var objectComponent1 = new ObjectComponentType() { object_ref = "oval:org.mitre.oval:obj:5000", item_field = "name" };
            var objectComponent2 = new ObjectComponentType() { object_ref = "oval:org.mitre.oval:obj:6000", item_field = "name" };

            var objectComponentEvaluator1 = new  LocalVariableObjectComponent(objectComponent1, systemCharacteristics);
            var literalComponentEvaluator = new LocalVariableLiteralComponent(literalComponent);
            var objectComponentEvaluator2 = new  LocalVariableObjectComponent(objectComponent2, systemCharacteristics);

            components.Add(objectComponentEvaluator1);
            components.Add(literalComponentEvaluator);
            components.Add(objectComponentEvaluator2);

            return components;
        }
 public LocalVariableObjectComponentTest()
 {
     this.FakeSystemCharacteristics = new OvalDocumentLoader().GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
 }
Example #17
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;
        }
 public LocalVariableObjectComponent(ObjectComponentType objectComponent, oval_system_characteristics systemCharacteristics)
 {
     this.ObjectComponent = objectComponent;
     this.SystemCharacteristics = systemCharacteristics;
 }
Example #19
0
 public CountFunctionComponent(CountFunctionType countFunctionType, 
     IEnumerable<VariableType> variablesOfDefinitions, oval_system_characteristics systemCharacteristics)
 {
     this._countFunctionType = countFunctionType;
 }
        private bool IsSequenceOfItemTypeExpected(oval_system_characteristics systemCharacteristics)
        {
            int max = systemCharacteristics.system_data.Max<ItemType>(x => int.Parse(x.id));
            int min = systemCharacteristics.system_data.Min<ItemType>(x => int.Parse(x.id));

            int total =  systemCharacteristics.system_data.Count() - 1;

            return ((max - min) == total);
        }
 public UniqueFunctionComponent(UniqueFunctionType uniqueFunctionType, 
     IEnumerable<VariableType> variablesOfDefinitions, oval_system_characteristics systemCharacteristics)
 {
     this._uniqueFunctionType = uniqueFunctionType;
 }
Example #22
0
        private IEnumerable<sc.ObjectType> GetObjectTypesForTest(string[] idsOfObjectTypes, oval_system_characteristics systemCharacteristics)
        {
            List<sc.ObjectType> objectTypes = new List<sc.ObjectType>();
            foreach(var id in idsOfObjectTypes)
            {
                objectTypes.Add( systemCharacteristics.GetCollectedObjectByID(id) );
            }

            return objectTypes;
        }