예제 #1
0
        public void Should_be_possible_to_generate_FileItems_from_FileObject_with_FilePathEntity_defined_with_reference_to_variable()
        {
            #region Oval File Object
            //  <file_object id="oval:modulo:obj:50010" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows">
            //      <filepath var_ref="oval:modulo:var:50010"></filepath>
            //  </file_object>
            //  <constant_variable id="oval:modulo:var:50010" datatype="string" version="1" comment="...">
            //      <value>c:\windows\system32\vgadriver.dll</value>
            //  </constant_variable>
            #endregion

            // Arrange
            string fakeVariableValue = @"c:\windows\system32\vgadriver.dll";
            var    fileObj50010      = (file_object)WindowsTestHelper.GetObjectFromDefinitions(DEFINITIONS_REGEX_ON_VALUE, OBJ_50010_ID);
            var    vars = VariableHelper.CreateVariableWithOneValue(OBJ_50010_ID, "oval:modulo:var:50010", fakeVariableValue);
            var    fileItemsGenerator = new FileItemTypeGenerator()
            {
                SystemDataSource = WindowsTestHelper.GetDataSourceFakewithoutRegex()
            };

            // Act
            IList <ItemType> itemsToCollect = fileItemsGenerator.GetItemsToCollect(fileObj50010, vars).ToList();

            // Assert
            Assert.IsNotNull(itemsToCollect, "The generated items cannot be null.");
            Assert.AreEqual(1, itemsToCollect.Count, "The number of generated items is not expected.");
            this.AssertGeneratedFileItem(itemsToCollect[0], fakeVariableValue, null, null);
        }
        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");
        }
        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);
        }
예제 #4
0
        public void Should_be_possible_to_generate_FileItems_from_FileObject_with_FilePathEntity_defined()
        {
            #region Oval File Object
            //  <file_object id="oval:modulo:obj:50008" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows">
            //      <filepath>c:\windows\foo.exe</filepath>
            //  </file_object>
            #endregion

            // Arrange
            file_object fileObj50008       = (file_object)WindowsTestHelper.GetObjectFromDefinitions(DEFINITIONS_REGEX_ON_VALUE, OBJ_50008_ID);
            var         fileItemsGenerator = new FileItemTypeGenerator()
            {
                SystemDataSource = WindowsTestHelper.GetDataSourceFakewithoutRegex()
            };


            // Act
            IList <ItemType> itemsToCollect = fileItemsGenerator.GetItemsToCollect(fileObj50008, null).ToList();
            Assert.IsNotNull(itemsToCollect, "The generated items cannot be null.");
            Assert.AreEqual(1, itemsToCollect.Count, "The number of generated items is not expected.");
            this.AssertGeneratedFileItem(itemsToCollect[0], @"c:\windows\foo.exe", null, null);
        }