Пример #1
0
 public static VariablesEvaluated CreateVariableWithMultiplesValue(string objID, string varID, string[] varValues)
 {
     var objectID = objID.Contains(":") ? objID : string.Format("oval:modulo:obj:{0}", objID);
     var variableID = varID.Contains(":") ? varID : string.Format("oval:modulo:var:{0}", varID);
     
     var variableValues = new VariableValue(objectID, variableID, new List<string>(varValues));
     return new VariablesEvaluated(new List<VariableValue>() { variableValues });
 }
Пример #2
0
 private IEnumerable<VariableValue> CreateVariableValuesFrom(IEnumerable<StateType> statesByVariable, string variableId, IEnumerable<string> valuesOfVariable)
 {
     List<VariableValue> variableValues = new List<VariableValue>();
     foreach (StateType state in statesByVariable)
     {
         VariableValue variableValue = new VariableValue(state.id, variableId, valuesOfVariable);
         variableValues.Add(variableValue);
     }
     return variableValues;
 }
Пример #3
0
 private IEnumerable<VariableValue> CreateVariableValuesFrom(IEnumerable<ObjectType> objectsByVariable, string variableId, IEnumerable<string> valuesOfVariable)
 {
     List<VariableValue> variableValues = new List<VariableValue>();
     foreach (ObjectType objectType in objectsByVariable)
     {
         VariableValue variableValue = new VariableValue(objectType.id, variableId, valuesOfVariable);
         variableValues.Add(variableValue);
     }
     return variableValues;
 }
Пример #4
0
        public void Should_not_possible_to_evaluate_variables_that_has_multiples_values()
        {
            List<string> values = new List<string>() { "1.0","1.1","1.2" };
            VariableValue variable = new VariableValue("oval:org.mitre.oval:obj:3000", "oval:org.mitre.oval:var:3000", values);
            VariablesEvaluated variables = new VariablesEvaluated(new List<VariableValue>() { variable });
            ItemType itemType = this.systemCharacteristics.GetSystemDataByReferenceId("3");
            StateType state = this.states.Where(obj => obj.id == "oval:org.mitre.oval:ste:100").SingleOrDefault();
            StateTypeComparator comparator = new StateTypeComparator(state, itemType, variables);
            comparator.IsEquals();

        }
Пример #5
0
        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");
        }
Пример #6
0
        public void Should_be_possible_to_get_a_variable_by_ovalComponentId()
        {
            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 };
            VariablesEvaluated variablesEvaluated = new VariablesEvaluated(variables);

            IEnumerable<VariableValue> variablesExpected = variablesEvaluated.GetVariableValueForOvalComponent("oval:org.mitre.oval:obj:6000");
            Assert.IsNotNull(variablesExpected, "the variable was not found");
            variablesExpected = variablesEvaluated.GetVariableValueForOvalComponent("oval:org.mitre.oval:obj:6005");
            Assert.IsTrue(variablesExpected.Count() == 0, "the variable is not expected");
        }
        public void Should_be_possible_to_generate_itemTypes_from_objectTypes()
        {
            var ovalObject = WindowsTestHelper.GetObjectFromDefinitions(DEFINITIONS_WITH_LOCAL_VARIABLE, OBJ_MITRE_3000_ID);
            var fakeDataSource = WindowsTestHelper.GetDataSourceFakewithoutRegex();
            var wmiDataProvider = new WmiDataProviderExpectFactory().GetFakeWmiDataProviderForTestInvokeMethodEnumKeyWithReturnSuccess();
            var fakeRegistryKeyPath = new List<string>() { @"Software\Microsoft\Windows NT\CurrentVersion" };
            var variable = new VariableValue(ovalObject.id, VAR_MITRE_3000_ID, fakeRegistryKeyPath);
            var variables = new VariablesEvaluated(new List<VariableValue>() { variable });


            RegistryItemTypeGenerator itemGenerator = new RegistryItemTypeGenerator() { SystemDataSource = fakeDataSource, WmiDataProvider = wmiDataProvider };
            IEnumerable<ItemType> itemsToCollect = itemGenerator.GetItemsToCollect(ovalObject, variables);


            Assert.AreEqual(1, itemsToCollect.Count(), "the quantity of items is not expected");
            this.AssertGeneratedRegistryItem(itemsToCollect.ElementAt(0), "HKEY_LOCAL_MACHINE", @"Software\Microsoft\Windows NT\CurrentVersion", "CurrentVersion");
        }
Пример #8
0
        public void Should_be_possible_to_generate_itemTypes_from_objectTypes_with_variables_and_regex()
        {
            string hiveHKLM = eHiveNames.HKEY_LOCAL_MACHINE.ToString();
            string startKey = "SOFTWARE\\Microsoft\\Windows";
            var ovalObject = WindowsTestHelper.GetObjectFromDefinitions("definitionsWithLocalVariable.xml", "oval:modulo:obj:5000");

            var fakeDataSource = WindowsTestHelper.GetDataSourceFakeWithRegex(startKey, 1);
            WmiDataProvider wmiDataProvider = new WmiDataProvider();// new WmiDataProviderFactory().GetFakeWmiDataProviderForTestInvokeMethodEnumKeyWithReturnSuccess();

            VariableValue variable = new VariableValue(ovalObject.id, "oval:org.mitre.oval:var:3000", new List<string>() { "CurrentType" });
            VariablesEvaluated variables = new VariablesEvaluated(new List<VariableValue>() { variable });

            var itemGenerator = new RegistryItemTypeGenerator() { SystemDataSource = fakeDataSource, WmiDataProvider = wmiDataProvider };
            var itemsToCollect = itemGenerator.GetItemsToCollect(ovalObject, variables).Cast<registry_item>();

            Assert.AreEqual(2, itemsToCollect.Count());
            this.AssertGeneratedRegistryItem(itemsToCollect.ElementAt(0), hiveHKLM, "SOFTWARE\\Microsoft\\Windows\\CurrentBuild", "CurrentType");
            this.AssertGeneratedRegistryItem(itemsToCollect.ElementAt(1), hiveHKLM, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "CurrentType");
        }
Пример #9
0
        public void Should_be_possible_to_generate_itemTypes_from_objectTypes_with_variables()
        {
            string hiveHKLM = eHiveNames.HKEY_LOCAL_MACHINE.ToString();
            string key = @"Software\Microsoft\Windows NT\CurrentVersion";
            string name = "CurrentType";
            var ovalObject = WindowsTestHelper.GetObjectFromDefinitions("definitionsWithLocalVariable.xml", "oval:org.mitre.oval:obj:4000");
            BaseObjectCollector fakeDataSource = WindowsTestHelper.GetDataSourceFakewithoutRegex();
            WmiDataProvider wmiDataProvider = new WmiDataProviderExpectFactory().GetFakeWmiDataProviderForTestInvokeMethodEnumKeyWithReturnSuccess();

            VariableValue variable = new VariableValue(ovalObject.id, "oval:org.mitre.oval:var:4000", new List<string>() { key });
            VariablesEvaluated variables = new VariablesEvaluated(new List<VariableValue>() { variable });

            var itemGenerator = new RegistryItemTypeGenerator() { SystemDataSource = fakeDataSource, WmiDataProvider = wmiDataProvider };
            var itemsToCollect = itemGenerator.GetItemsToCollect(ovalObject, variables);

            Assert.IsTrue(itemsToCollect.Count() == 1, "the quantity of items is not expected");
            this.AssertGeneratedRegistryItem(itemsToCollect.ElementAt(0), hiveHKLM, key, name);
        }
Пример #10
0
 private static IEnumerable<VariableValue> CreateVariableReference()
 {
     List<string> values = new List<string>() { "Microsoft\\WindowsNT\\" };
     VariableValue variableValue = new VariableValue(ID_REGISTRY_OBJECT, "oval:com.hp:var:4", values);
     List<VariableValue> variables = new List<VariableValue>();
     variables.Add(variableValue);
     return variables;
 }
Пример #11
0
        public void Should_be_possible_to_process_a_variable_given_EntityBaseType()
        {
            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 };
            VariablesEvaluated variablesEvaluated = new VariablesEvaluated(variables);

            VariableEntityEvaluator variableEntityEvaluator = new VariableEntityEvaluator(variablesEvaluated);
            EntityObjectStringType entity = new EntityObjectStringType();
            entity.var_ref = "oval:com.hp:var:1";

            IEnumerable<string> values = variableEntityEvaluator.EvaluateVariableForEntity(entity);
            Assert.IsTrue(values.Count() > 0 , "the quantity of entities is not expected");
            Assert.AreEqual(values.ElementAt(0), variableValues.ElementAt(0), "the value is not expected");        
        }
Пример #12
0
        public void Should_be_possible_to_create_VariableValueType_by_the_VariableValue()
        {
            List<String> valuesOfVariable = new List<string>() {"Multiprocessor Free"};
            VariableValue variableValue = new VariableValue("oval:org.mitre.oval:obj:6000","oval:com.hp:var:1", valuesOfVariable);
            IEnumerable<VariableValueType> variableValueTypes = variableValue.ToOvalVariableType();

            Assert.IsNotNull(variableValueTypes, "the VariableValueType was not created");
            Assert.IsTrue(variableValueTypes.Count() > 0, "the quantity is not expected");
            Assert.AreEqual(variableValueTypes.ElementAt(0).variable_id,"oval:com.hp:var:1", "the variable id is not expected");
            Assert.AreEqual(variableValueTypes.ElementAt(0).Value, valuesOfVariable.ElementAt(0), "the valueis not expected");
        }