Example #1
0
        public void Should_be_possible_to_evaluate_a_set_with_another_set_defintion()
        {
            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:5000");

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

            Assert.IsNotNull(result, "the items expected is null");
            Assert.AreEqual(1, result.Result.Count(), "the quantity of items is not expected");

            string element = result.Result.Where<string>(item => item == "3").SingleOrDefault();
            Assert.IsNotNull(element, "the element expected is not exits");
        }
Example #2
0
        /// <summary>
        /// This method executes the process of  a setElement in the ObjectType.
        /// For the objectType that has a setElement the process is a some different. 
        /// Actually, the setElement uses the objectType already was  collected. 
        /// In this process the setElement process uses a systemCharacteristics for the get a reference for the objectType 
        /// collected and makes the references are used in the new CollectedObject of the process.
        /// </summary>
        /// <param name="ovalObject">The Oval Object.</param>
        /// <param name="collectInfo">The collect info.</param>
        /// <returns></returns>
        private CollectedObject ProcessSet(Definitions.ObjectType ovalObject, CollectInfo collectInfo)
        {
            CollectedObject collectedObject = null;
            try
            {
                var setElement = this.GetSetElement(ovalObject);
                var setEvaluator = new SetEvaluator(collectInfo.SystemCharacteristics, collectInfo.States, collectInfo.Variables);
                var resultOfSet = setEvaluator.Evaluate(setElement);
                var objectReferences = resultOfSet.Result;

                if (objectReferences.Count() > 0)
                {
                    collectedObject = new CollectedObject(ovalObject.id);
                    foreach (string reference in objectReferences)
                    {
                        var itemType = collectInfo.SystemCharacteristics.GetSystemDataByReferenceId(reference);
                        collectedObject.AddItemToSystemData(itemType);
                    }

                    collectedObject.SetEspecificObjectStatus(resultOfSet.ObjectFlag);
                }

                return collectedObject;
            }
            catch (Exception ex)
            {
                collectedObject = new CollectedObject(ovalObject.id);
                collectedObject.SetEspecificObjectStatus(FlagEnumeration.error);
                collectedObject.ObjectType.message = MessageType.FromErrorString(String.Format("An error occurred while set processing: '{0}'", ex.Message));
                return collectedObject;
            }
        }