public void AddCollectedObject(CollectedObject collectedObject) { if (collectedObject == null) return; ((List<CollectedObject>)this.probeResult.CollectedObjects).Add(collectedObject); }
private static CollectedObject CreateFamilyCollectedObject(string ovalId, int quantidadeDeItems) { CollectedObject collectedObject = new CollectedObject(ovalId); ItemType familyItem = CreateFamilyItem("windows"); collectedObject.AddItemToSystemData(familyItem); return collectedObject; }
public void Should_be_possible_to_add_reference_for_variables_in_the_ObjectType() { List<string> variableValues = new List<string>() { "Multiprocessor Free" }; VariableValue variable = new VariableValue("oval:org.mitre.oval:obj:6000", "oval:com.hp:var:1", variableValues); IEnumerable<VariableValue> variables = new List<VariableValue>() { variable }; CollectedObject collectedObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); collectedObject.AddVariableReference(variables); Assert.IsNotNull(collectedObject.ObjectType.variable_value, "the variables was not set"); Assert.IsTrue(collectedObject.ObjectType.variable_value.Count() == 1, "the quantity of the variable_value is not expected"); Assert.AreEqual(collectedObject.ObjectType.variable_value[0].Value, "Multiprocessor Free","the value is not expected"); }
public void Should_be_possible_to_create_a_relation_between_objectType_and_systemData_through_of_referenceData() { CollectedObject collectObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); ItemType registryItem1 = new registry_item() { status = StatusEnumeration.exists, id = "1" }; ItemType registryItem2 = new registry_item() { status = StatusEnumeration.doesnotexist, id = "2" }; collectObject.AddItemToSystemData(registryItem1); collectObject.AddItemToSystemData(registryItem2); Assert.AreEqual(2, collectObject.ObjectType.reference.Count(), "the quantity of reference is not expected"); Assert.AreEqual("1", collectObject.ObjectType.reference[0].item_ref, "the first element of reference not has the id expected"); Assert.AreEqual("2", collectObject.ObjectType.reference[1].item_ref, "the second element of reference not has the id expected"); CollectedObject otherCollectedObject = new CollectedObject("oval:org.mitre.oval:obj:6001"); ItemType registryItem3 = new registry_item() { status = StatusEnumeration.exists, id = "3" }; otherCollectedObject.AddItemToSystemData(registryItem3); Assert.AreEqual(1, otherCollectedObject.ObjectType.reference.Count(), "the quantity of reference is not expected for the second collectedObject"); Assert.AreEqual("3", otherCollectedObject.ObjectType.reference[0].item_ref, "the referece id of element is not expected"); }
/// <summary> /// Executes a normal collect, using the system datasource for data collecting. /// </summary> /// <param name="ovalComponent">The oval component.</param> /// <param name="collectInfo">The collect info.</param> /// <param name="id">The id parameter is 'a sequencial number controlled by external scope.</param> /// <returns></returns> private CollectedObject ProcessCollect(Definitions.ObjectType ovalComponent, CollectInfo collectInfo, ProbeResultBuilder probeResultBuilder, ref int id) { CollectedObject collectedObject = null; var allItemsToCollect = this.TryToGetItemsToCollect(ovalComponent, collectInfo.Variables); if (allItemsToCollect.Count() > 0) { collectedObject = new CollectedObject(ovalComponent.id); foreach (var itemToCollect in allItemsToCollect) { var collectedItems = ObjectCollector.CollectDataForSystemItem(itemToCollect); foreach (var collectedItem in collectedItems) { var itemType = probeResultBuilder.GetItemType(collectedItem.ItemType); if (itemType == null) { collectedItem.ItemType.id = id.ToString(); id++; } else { collectedItem.ItemType = itemType; } collectedObject.AddItemToSystemData(collectedItem.ItemType); var variables = collectInfo.GetVariableValueForOvalComponent(collectedObject.ObjectType.id); collectedObject.AddVariableReference(variables); ExecutionLogBuilder.AddDetailInformation(collectedItem.ExecutionLog); } } collectedObject.UpdateCollectedObjectStatus(); } return collectedObject; }
public ProbeResult CreateCollectedObjectForNotSupportedObjects( IEnumerable<Definitions.ObjectType> objectNotSupported) { ProbeResultBuilder probeResultBuilder = new ProbeResultBuilder(); foreach (var objectType in objectNotSupported) { var collectedObject = new CollectedObject(objectType.id); collectedObject.SetEspecificObjectStatus(FlagEnumeration.notcollected); probeResultBuilder.AddCollectedObject(collectedObject); } return probeResultBuilder.ProbeResult; }
private static CollectedObject CreateRegistryCollectedObject(string ovalId, int quantidadeDeItems) { CollectedObject collectedObject = new CollectedObject(ovalId); ItemType currentVersion = CreateRegistryItem("HKEY_LOCAL_MACHINE", "1", "", "Microsoft\\WindowsNT\\", "CDSVersion", "Service Pack 1"); collectedObject.AddItemToSystemData(currentVersion); ItemType systemRoot = CreateRegistryItem("HKEY_LOCAL_MACHINE", "2", "", "Microsoft\\WindowsNT\\", "SystemRoot", @"c:\Windows"); collectedObject.AddItemToSystemData(systemRoot); return collectedObject; }
private static IEnumerable<CollectedObject> CreateCollectedObjectsForSpecificObjectTypes(IEnumerable<definitions.ObjectType> objectTypes, List<string> resultsForObjects) { List<CollectedObject> collectedObjects = new List<CollectedObject>(); IEnumerable<registry_object> registryObjects = objectTypes.OfType<registry_object>(); int id = 1; foreach (var registryObject in registryObjects) { CollectedObject collectedObject = new CollectedObject(registryObject.id); string existId = resultsForObjects.Where(x => x.Equals(registryObject.id)).SingleOrDefault(); if (string.IsNullOrEmpty(existId)) { ItemType registryItem = CreateRegistryItem( registryObject.GetItemValue(registry_object_ItemsChoices.hive).ToString(), id.ToString(), "", registryObject.GetItemValue(registry_object_ItemsChoices.key).ToString(), registryObject.GetItemValue(registry_object_ItemsChoices.name).ToString(), "default" ); collectedObject.AddItemToSystemData(registryItem); collectedObjects.Add(collectedObject); id++; } else { resultsForObjects.Remove(existId); } } return collectedObjects; }
private void AssertCollectedFileItems(CollectedObject collectedObject, WmiObject[] expectedFiles) { string UNEXPECTED_ITEM_ATTRIBUTE_VALUE = "Unexpected value for a file_item attribute was found: {0}"; SystemCharacteristics::ReferenceType[] objectReferences = collectedObject.ObjectType.reference.ToArray(); IList<ItemType> fileItems = (IList<ItemType>)collectedObject.SystemData; Assert.AreEqual(expectedFiles.Count(), objectReferences.Count(), "Unexpected number of item references was found."); Assert.AreEqual(objectReferences.Count(), fileItems.Count, "Unexpected number of generated items type was found."); int i = 0; foreach (var expectedFile in expectedFiles) { Dictionary<string, object> fileItemFields = expectedFile.GetValues(); Assert.IsInstanceOfType(fileItems[i], typeof(file_item), "The generated ItemType must be a instance of file_item class."); file_item fileItem = (file_item)fileItems[i]; Assert.AreEqual(objectReferences[i].item_ref, fileItem.id, "The generated ItemType ID must be equal to collected object ID."); Assert.AreEqual(StatusEnumeration.exists, fileItem.status, "A generated ItemType with unexpected OVAL Status was found."); Assert.AreEqual(fileItemFields[FILE_SIZE].ToString(), fileItem.size.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, FILE_SIZE)); Assert.AreEqual(ConvertWmiTimeToFileTime(fileItemFields[C_DATE].ToString()), fileItem.c_time.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, C_DATE)); Assert.AreEqual(ConvertWmiTimeToFileTime(fileItemFields[M_DATE].ToString()), fileItem.m_time.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, M_DATE)); Assert.AreEqual(ConvertWmiTimeToFileTime(fileItemFields[A_DATE].ToString()), fileItem.a_time.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, A_DATE)); Assert.AreEqual(fileItemFields[VERSION], fileItem.version.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, VERSION)); Assert.AreEqual(fileItemFields[FILE_TYPE], fileItem.type.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, FILE_SIZE)); Assert.AreEqual(fileItemFields[COMPANY], fileItem.company.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, COMPANY)); i++; } }
public void Should_not_possible_to_add_a_item_type_if_it_already_exists_in_the_collected_object() { oval_system_characteristics systemCharacteristics = new LoadOvalDocument().GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); CollectedObject collectedObject = new CollectedObject("oval:org.mitre.oval:obj:1000"); ItemType registryItem1 = new registry_item() { status = StatusEnumeration.exists, id = "1" }; ItemType registryItem2 = systemCharacteristics.GetSystemDataByReferenceId("2"); }
private static IEnumerable<CollectedObject> CreateCollectedObjectsForSpecificObjectTypes(IEnumerable<OVAL.Definitions.ObjectType> objectTypes, List<string> resultsForObjects) { List<CollectedObject> collectedObjects = new List<CollectedObject>(); IEnumerable<family_object> familyObjects = objectTypes.OfType<family_object>(); int id = 1; foreach (var familyObject in familyObjects) { string existId = resultsForObjects.Where(x => x.Equals(familyObject.id)).SingleOrDefault(); if (string.IsNullOrEmpty(existId)) { CollectedObject collectedObject = new CollectedObject(familyObject.id); ItemType familyItem = CreateFamilySpecificItem(id.ToString()); collectedObject.AddItemToSystemData(familyItem); collectedObjects.Add(collectedObject); id++; } else { resultsForObjects.Remove(existId); } } return collectedObjects; }
private void AssertProbeResultItem(CollectedObject collectedObject, string objectID, string[] expectedVariables, List<registry_item> expectedItems) { SystemCharacteristics::ObjectType createdObjectType = collectedObject.ObjectType; List<ItemType> createdItemsType = (List<ItemType>)collectedObject.SystemData; Assert.AreEqual(objectID, createdObjectType.id); if (expectedVariables != null) { Assert.IsNotNull(createdObjectType.variable_value, "There is no variable values for this collected object"); Assert.AreEqual(expectedVariables.Count(), createdObjectType.variable_value.Count(), "The number of variable values for this collected object is unexpected."); for (int i = 0; i < expectedVariables.Count(); i++) Assert.AreEqual(expectedVariables[i], createdObjectType.variable_value[i].Value, "An unexpected variable value was found."); } Assert.AreEqual(expectedItems.Count, createdObjectType.reference.Count()); Assert.AreEqual(expectedItems.Count, createdItemsType.Count); for (int i = 0; i < createdItemsType.Count; i++) { registry_item createdRegistryItem = (registry_item)createdItemsType[i]; Assert.AreEqual(expectedItems[i].status, createdRegistryItem.status); Assert.AreEqual(expectedItems[i].message.First().Value, createdRegistryItem.message.First().Value); Assert.AreEqual(expectedItems[i].hive.Value, createdRegistryItem.hive.Value); Assert.AreEqual(expectedItems[i].key.Value, createdRegistryItem.key.Value); Assert.AreEqual(expectedItems[i].name.Value, createdRegistryItem.name.Value); Assert.AreEqual(expectedItems[i].type.Value, createdRegistryItem.type.Value); Assert.AreEqual(expectedItems[i].value.Count(), createdRegistryItem.value.Count()); for (int j = 0; j < expectedItems[i].value.Count(); j++) Assert.AreEqual(expectedItems[i].value[j].Value, createdRegistryItem.value[j].Value); } }
public void Should_be_possible_to_create_an_objectType_with_status_not_collected() { CollectedObject collectObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); Assert.AreEqual(Modulo.Collect.OVAL.SystemCharacteristics.FlagEnumeration.notcollected,collectObject.ObjectType.flag, "the objectType not has the expected flag"); }
/// <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; } }
private void AssertCollectedFileItems(Definitions::ObjectType sourceObject, CollectedObject collectedObject, IEnumerable<CollectedItem> expectedItems) { SystemCharacteristics.ReferenceType[] objectReferences = collectedObject.ObjectType.reference.ToArray(); IList<ItemType> collectedItems = (IList<ItemType>)collectedObject.SystemData; this.assertCollectedItemsReferences(collectedObject, collectedItems); for (int i = 0; i < expectedItems.Count(); i++) { CollectedItem expectedFileItem = expectedItems.ElementAt(i); ItemType collectedItem = collectedItems[i]; this.assertCollectedItemStatus(objectReferences[i], collectedItem); this.assertFileEffectiveRightsInitialEntities(sourceObject, collectedItem); this.assertFileEffectiveRightsCollectedItems(expectedFileItem, collectedItem); } }
private void AssertCollectedItemsReferences(CollectedObject collectedObject, IList<ItemType> collectedItems) { int collectedObjectCount = collectedObject.ObjectType.reference.Count(); Assert.AreEqual(collectedItems.Count(), collectedObjectCount, "Unexpected number of item references was found."); Assert.AreEqual(collectedObjectCount, collectedItems.Count, "Unexpected number of generated items type was found."); }
public void Should_be_possible_to_update_status_of_an_objectType_to_error_based_on_in_systemData() { CollectedObject collectObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); ItemType registryItem1 = new registry_item() { status = StatusEnumeration.exists, id = "1" }; ItemType registryItem2 = new registry_item() { status = StatusEnumeration.doesnotexist, id = "2" }; ItemType registryItem3 = new registry_item() { status = StatusEnumeration.error, id = "3" }; collectObject.AddItemToSystemData(registryItem1); collectObject.AddItemToSystemData(registryItem2); collectObject.AddItemToSystemData(registryItem3); collectObject.UpdateCollectedObjectStatus(); Assert.AreEqual(FlagEnumeration.error, collectObject.ObjectType.flag); }