public void Should_be_possible_to_create_objectTypes_by_combination_of_entities()
        {
            oval_definitions definition = new LoadOvalDocument().GetFakeOvalDefinitions("definitionsSimple.xml");
            ObjectType objecType = ProbeHelper.GetOvalComponentByOvalID(definition, "oval:modulo:obj:7");
            IEnumerable<string> paths = new List<string>() { @"c:\temp", @"c:\windows\temp",@"c:\teste" };
            IEnumerable<string> fileNames = new List<string>() { "file.txt" };
            IEnumerable<string> trustee_names = new List<string>() { "Administrator" };

            FileEffectiveRightsObjectTypeFactory factory = new FileEffectiveRightsObjectTypeFactory();
            IEnumerable<ObjectType> objectTypes = factory.CreateObjectTypeByCombinationOfEntities((fileeffectiverights_object)objecType, paths, fileNames, trustee_names);
            Assert.AreEqual(3, objectTypes.Count());

            fileeffectiverights_object fileEffectiveRights = (fileeffectiverights_object)objectTypes.ElementAt(0);
            Assert.AreEqual(@"c:\temp", ((EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.path)).Value);
            Assert.AreEqual("file.txt", ((EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.filename)).Value);
            Assert.AreEqual("Administrator", ((EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.trustee_name)).Value);

            fileEffectiveRights = (fileeffectiverights_object)objectTypes.ElementAt(1);
            Assert.AreEqual(@"c:\windows\temp", ((EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.path)).Value);
            Assert.AreEqual("file.txt", ((EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.filename)).Value);
            Assert.AreEqual("Administrator", ((EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.trustee_name)).Value);

            fileEffectiveRights = (fileeffectiverights_object)objectTypes.ElementAt(2);
            Assert.AreEqual(@"c:\teste", ((EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.path)).Value);
            Assert.AreEqual("file.txt", ((EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.filename)).Value);
            Assert.AreEqual("Administrator", ((EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.trustee_name)).Value);
            
        }
示例#2
0
        public static oval_definitions GetFakeOvalDefinitions(string fileName)
        {
            if (!fileName.Contains(".xml"))
                fileName += ".xml";

            LoadOvalDocument ovalDocumentLoader = new LoadOvalDocument();
            return ovalDocumentLoader.GetFakeOvalDefinitions(fileName);
        }
        public void Should_be_possible_to_create_xmlfilecontent_items_for_unix_platform()
        {
            var mocks = new MockRepository();
            var pathOperator = mocks.DynamicMock<PathOperatorEvaluator>(new object[] { null, FamilyEnumeration.unix });
            pathOperator.FileProvider = mocks.DynamicMock<IFileProvider>();
            Expect.Call(pathOperator.FileProvider.FileExists(null)).IgnoreArguments().Return(true);
            Expect.Call(pathOperator.ProcessOperationsPaths(null)).IgnoreArguments().Return(new[] { "/etc/webapps" });
            Expect.Call(pathOperator.ProcessOperationFileName(null, null, false)).IgnoreArguments().Return(new[] { "server.xml" });
            mocks.ReplayAll();
            var sampleObject = new LoadOvalDocument().GetFakeOvalDefinitions("definitions_all_unix.xml").objects.Single(obj => obj.id == "oval:modulo:obj:333");
            var itemtypeGenerator = new XmlFileContentItemTypeGenerator(null) { PathOperatorEvaluator = pathOperator };

            var itemsToCollect = itemtypeGenerator.GetItemsToCollect(sampleObject, null);

            var xmlFileContentItem = (xmlfilecontent_item)itemsToCollect.Single();
            Assert.AreEqual("/etc/webapps/server.xml", xmlFileContentItem.filepath.Value);

        }
示例#4
0
 private oval_definitions getFakeDefinitions(string fileName)
 {
     LoadOvalDocument docLoader = new LoadOvalDocument();
     return docLoader.GetFakeOvalDefinitions(fileName);
 }
示例#5
0
 public static Definitions.ObjectType GetObjectFromDefinitions(string definitionsFileName, string componentID)
 {
     oval_definitions fakeDefinitions = new LoadOvalDocument().GetFakeOvalDefinitions(definitionsFileName);
     return fakeDefinitions.objects.Where(obj => obj.id.Equals(componentID)).Single();
 }
示例#6
0
        public void When_an_error_occurs_while_creating_items_to_collect_the_created_items_must_have_error_status()
        {
            var definitions = new LoadOvalDocument().GetFakeOvalDefinitions("definitionsWithConstantVariable.xml");
            var objects = definitions.objects.OfType<variable_object>().ToArray();
            var variables = this.CreateVariable("oval:modulo:obj:4000", "oval:modulo:var:1002", new string[] { "c:\\temp" });
            var fakeException = new Exception("Timeout");
            var collectInfo = ProbeHelper.CreateFakeCollectInfo(objects, variables, null);
            collectInfo.Variables = variables;
            var variableProber = this.CreateMockedVariableProber(fakeException);

            var result = variableProber.Execute(FakeContext, FakeTargetInfo, collectInfo);

            // Asserting Collected Objects
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.CollectedObjects);
            Assert.AreEqual(1, result.CollectedObjects.Count());

            // Asserting System Data
            var systemData = result.CollectedObjects.Single().SystemData;
            Assert.IsNotNull(systemData);
            Assert.AreEqual(1, systemData.Count);
            
            // Assert Colelcted Item
            var collectedItem = systemData.Single();
            Assert.IsInstanceOfType(collectedItem, typeof(variable_item));
            Assert.AreEqual(StatusEnumeration.error, collectedItem.status);
            Assert.IsNotNull(collectedItem.message);
            Assert.IsTrue(collectedItem.message.First().Value.Contains(fakeException.Message));
        }
示例#7
0
        public void Should_be_possible_execute_a_variable_collect()
        {
            var definitions = new LoadOvalDocument().GetFakeOvalDefinitions("definitionsWithConstantVariable.xml");
            var objects = definitions.objects.OfType<variable_object>().ToArray();
            var variables = this.CreateVariable("oval:modulo:obj:4000", "oval:modulo:var:1002", new string[] { "c:\\temp" });
            var collectInfo = ProbeHelper.CreateFakeCollectInfo(objects, variables, null);
            collectInfo.Variables = variables;

            var collectedObjects = new VariableProber().Execute(FakeContext, FakeTargetInfo, collectInfo).CollectedObjects;

            Assert.AreEqual(1,collectedObjects.Count());
            Assert.AreEqual(1, collectedObjects.Single().SystemData.Count);
            var collectedItem = (variable_item)collectedObjects.Single().SystemData.First();
            Assert.AreEqual(StatusEnumeration.exists, collectedItem.status);
            Assert.AreEqual("c:\\temp", collectedItem.value[0].Value);
        }
示例#8
0
        public void Should_be_possible_to_execute_a_registry_collect_with_Set_element()
        {
            var fakeDefinitions = ProbeHelper.GetFakeOvalDefinitions("definitionsWithSet.xml");
            var fakeObjects = fakeDefinitions.objects.OfType<registry_object>().ToArray();
            oval_system_characteristics fakeSystemCharacteristics = new LoadOvalDocument().GetFakeOvalSystemCharacteristics("system_characteristics_with_sets.xml");
            CollectInfo fakeCollectedInfo = ProbeHelper.CreateFakeCollectInfo(fakeObjects, null, fakeSystemCharacteristics);
            registry_item fakeRegistryItem = this.GetFakeRegistryItem(@"Software\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", eValueTypes.STRING, "6.0");
            RegistryProber registryProber = this.GetMockedRegistryProber(fakeRegistryItem);

            IEnumerable<CollectedObject> result = registryProber.Execute(fakeContext, fakeTarget, fakeCollectedInfo).CollectedObjects;

            Assert.IsNotNull(result, "the result is not expected");
            CollectedObject collectedObject = result.Where<CollectedObject>(obj => obj.ObjectType.id == "oval:org.mitre.oval:obj:6000").SingleOrDefault();
            Assert.IsNotNull(collectedObject, "the element was not found");
            Assert.AreEqual(collectedObject.ObjectType.reference.Count(),3, "the quantity of object referenced is not expected");
        }
示例#9
0
 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");
 }