Пример #1
0
        public void Should_be_possible_to_apply_NotEqual_operation_on_OvalObjectEntity()
        {
            string          definitionFileName = "fdcc_xpfirewall_oval_regex_on_value.xml";
            registry_object obj50006           = (registry_object)this.getFakeObj(definitionFileName, "oval:modulo:obj:50006");
            Dictionary <string, EntityObjectStringType> entities = OvalHelper.GetRegistryEntitiesFromObjectType(obj50006);
            EntityObjectStringType      nameEntity          = entities[registry_object_ItemsChoices.name.ToString()];
            Dictionary <string, object> operationParameters = getOperationParameters("CSDVersion", new string[] { "BuildVersion", "CSDVersion", "XPTO" });

            OvalEntityOperationBase notEqualsOperation        = OvalEntityOperationFactory.CreateOperationForOvalEntity(nameEntity.operation);
            IEnumerable <string>    resultAfterApplyOperation = notEqualsOperation.Apply(operationParameters);

            Assert.IsInstanceOfType(notEqualsOperation, typeof(NotEqualsEntityOperation), MSG_INVALID_OPERATION_TYPE);
            Assert.AreEqual(2, resultAfterApplyOperation.Count(), MSG_INVALID_OPERATION_RESULT_COUNT);
            Assert.AreEqual("BuildVersion", resultAfterApplyOperation.ElementAt(0), MSG_UNEXPECTED_FOUND_ITEM);
            Assert.AreEqual("XPTO", resultAfterApplyOperation.ElementAt(1), MSG_UNEXPECTED_FOUND_ITEM);
        }
Пример #2
0
        public void Should_be_possible_to_apply_Equals_operation_on_RegistryObjectEntities()
        {
            registry_object        registryObject = (registry_object)this.getFakeObj(DEFINITIONS_FILENAME, REGISTRY_OBJECT_ID);
            EntityObjectStringType keyEntity      = this.getRegistryObjectEntity(registryObject, registry_object_ItemsChoices.key.ToString());


            // Assert Key Entity Operation
            OvalEntityOperationBase operationForKeyEntity = OvalEntityOperationFactory.CreateOperationForOvalEntity(keyEntity.operation);

            Dictionary <string, object> keyOperationParameters = this.getOperationParameters(keyEntity.Value, new string[] { REGISTRY_KEY_NAME });
            IEnumerable <string>        derivedKeys            = operationForKeyEntity.Apply(keyOperationParameters);

            Assert.IsInstanceOfType(operationForKeyEntity, typeof(EqualsEntityOperation), MSG_INVALID_OPERATION_TYPE);
            Assert.IsNotNull(derivedKeys);
            Assert.AreEqual(1, derivedKeys.Count(), MSG_INVALID_OPERATION_RESULT_COUNT);
            Assert.AreEqual(keyEntity.Value, derivedKeys.ElementAt(0), MSG_UNEXPECTED_FOUND_ITEM);
        }
Пример #3
0
        public void Equals_operation_should_be_CaseSensitive()
        {
            #region User Object
            // <user_object id="oval:modulo:obj:5" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows">
            //     <user>lfernandes</user>
            // </user_object>
            #endregion

            user_object                 userObject = (user_object)this.getFakeObj("definitionsSimple.xml", "oval:modulo:obj:5");
            EntityObjectStringType      userEntity = (EntityObjectStringType)userObject.User;
            Dictionary <string, object> operationParameters;

            OvalEntityOperationBase equalsOperation = OvalEntityOperationFactory.CreateOperationForOvalEntity(userEntity.operation);

            operationParameters = this.getOperationParameters(userEntity.Value, new string[] { "LFernandes" });
            IEnumerable <string> operationResult = equalsOperation.Apply(operationParameters);
            Assert.IsInstanceOfType(equalsOperation, typeof(EqualsEntityOperation), MSG_INVALID_OPERATION_TYPE);
            Assert.AreEqual(0, operationResult.Count(), MSG_INVALID_OPERATION_RESULT_COUNT);
        }
Пример #4
0
        public void Should_be_possible_to_apply_CaseInsensitiveNotEqual_operation_on_OvalObjectEntity()
        {
            #region User Object
            //  <user_object id="oval:modulo:obj:6" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows">
            //      <user operation="case insensitive not equal">lfernandes</user>
            //  </user_object>
            #endregion

            user_object                 userObject      = (user_object)ProbeHelper.GetDefinitionObjectTypeByID("definitionsSimple.xml", "oval:modulo:obj:6");
            EntityObjectStringType      userEntity      = (EntityObjectStringType)userObject.User;
            Dictionary <string, object> operationParams = getOperationParameters(userEntity.Value, new string[] { "lfernandes", @"XPTO", @"lucaf", "LFERNANDES", "lFeRnAnDeS" });


            OvalEntityOperationBase operation = OvalEntityOperationFactory.CreateOperationForOvalEntity(userEntity.operation);
            Assert.IsInstanceOfType(operation, typeof(CaseInsensitiveNotEqualsOperation), MSG_INVALID_OPERATION_TYPE);


            IEnumerable <string> operationResult = operation.Apply(operationParams);
            Assert.AreEqual(2, operationResult.Count(), MSG_INVALID_OPERATION_RESULT_COUNT);
            Assert.AreEqual("XPTO", operationResult.ElementAt(0), MSG_UNEXPECTED_FOUND_ITEM);
            Assert.AreEqual("lucaf", operationResult.ElementAt(1), MSG_UNEXPECTED_FOUND_ITEM);
        }
Пример #5
0
        public void Should_be_possible_to_apply_CaseInsensitiveEqual_operation_on_OvalObjectEntity()
        {
            #region User Object
            // <user_object id="oval:modulo:obj:4" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows">
            //     <user operation="case insensitive equals">lfernandes</user>
            // </user_object>
            #endregion

            user_object                 userObject = (user_object)this.getFakeObj("definitionsSimple.xml", "oval:modulo:obj:4");
            EntityObjectStringType      userEntity = (EntityObjectStringType)userObject.User;
            Dictionary <string, object> operationParameters;

            OvalEntityOperationBase caseInsensitiveEqualsOperation = OvalEntityOperationFactory.CreateOperationForOvalEntity(userEntity.operation);

            operationParameters = this.getOperationParameters(userEntity.Value, new string[] { "LFernandes", "LFERNANDES", userEntity.Value, "XPTO" });
            IEnumerable <string> operationResult = caseInsensitiveEqualsOperation.Apply(operationParameters);
            Assert.IsInstanceOfType(caseInsensitiveEqualsOperation, typeof(CaseInsentiveEqualsOperation), MSG_INVALID_OPERATION_TYPE);
            Assert.AreEqual(3, operationResult.Count(), MSG_INVALID_OPERATION_RESULT_COUNT);
            Assert.AreEqual("LFernandes", operationResult.ElementAt(0), MSG_UNEXPECTED_FOUND_ITEM);
            Assert.AreEqual("LFERNANDES", operationResult.ElementAt(1), MSG_UNEXPECTED_FOUND_ITEM);
            Assert.AreEqual(userEntity.Value, operationResult.ElementAt(2), MSG_UNEXPECTED_FOUND_ITEM);
        }
Пример #6
0
        public void NotEqual_operation_should_be_CaseSensitive()
        {
            #region Registry Object
            // <registry_object id="oval:modulo:obj:50006" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows">
            //   <hive>HKEY_LOCAL_MACHINE</hive>
            //   <key>SOFTWARE\Microsoft\Windows\CurrentVersion</key>
            //   <name operation="not equal">CSDVersion</name>
            // </registry_object>
            #endregion

            registry_object registryObject = (registry_object)this.getFakeObj(DEFINITIONS_FILENAME, "oval:modulo:obj:50006");
            Dictionary <string, EntityObjectStringType> registryEntities = OvalHelper.GetRegistryEntitiesFromObjectType(registryObject);
            EntityObjectStringType nameEntity = registryEntities[registry_object_ItemsChoices.name.ToString()];

            OvalEntityOperationBase NotEqualOperation = OvalEntityOperationFactory.CreateOperationForOvalEntity(nameEntity.operation);

            Dictionary <string, object> operationParameters = this.getOperationParameters(nameEntity.Value, new string[] { "CSDversion", "CSDVersion", "csdVersion" });
            IEnumerable <string>        operationResult     = NotEqualOperation.Apply(operationParameters);
            Assert.IsInstanceOfType(NotEqualOperation, typeof(NotEqualsEntityOperation), MSG_INVALID_OPERATION_TYPE);
            Assert.AreEqual(2, operationResult.Count(), MSG_INVALID_OPERATION_RESULT_COUNT);
            Assert.AreNotEqual(nameEntity.Value, operationResult.ElementAt(0), MSG_UNEXPECTED_FOUND_ITEM);
            Assert.AreNotEqual(nameEntity.Value, operationResult.ElementAt(1), MSG_UNEXPECTED_FOUND_ITEM);
        }
Пример #7
0
        public IEnumerable <String> ApplyOperationForEntity(OperationEnumeration entityOperation, Dictionary <string, object> operationParameters)
        {
            OvalEntityOperationBase operation = OvalEntityOperationFactory.CreateOperationForOvalEntity(entityOperation);

            return(operation.Apply(operationParameters));
        }