コード例 #1
0
        public static oval_results GetOvalResultsFromStream(
            Stream resultDocument, out IEnumerable <string> schemaErrors)
        {
            var _schemaErrors = new List <string>();

            var ScOverrides = oval_system_characteristics.GetExportedScOverrides();

            oval_definitions.GetExportedDefinitionsOverrides(ScOverrides);
            XmlSerializer     xmlSerializer = new XmlSerializer(typeof(oval_results), ScOverrides);
            var               resolver      = new ExtensibleXmlResourceResolver();
            XmlReaderSettings settings      = new XmlReaderSettings();

            settings.ValidationType          = ValidationType.Schema;
            settings.XmlResolver             = resolver;
            settings.ValidationFlags         = XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.AllowXmlAttributes;
            settings.ValidationEventHandler += (o, args) => { if (args.Severity == XmlSeverityType.Error)
                                                              {
                                                                  _schemaErrors.Add(args.Message);
                                                              }
            };
            XmlReader    reader = XmlReader.Create(resultDocument, settings);
            oval_results result = xmlSerializer.Deserialize(reader) as oval_results;

            reader.Close();

            if (_schemaErrors.Count > 0)
            {
                result = null;
            }

            schemaErrors = _schemaErrors;
            return(result);
        }
コード例 #2
0
        public static oval_results CreateFromDocuments(
            Definitions.oval_definitions definitions,
            oval_system_characteristics systemcharacteristics,
            oval_variables evaluatedExternalVariables)
        {
            oval_results newResult = new oval_results();

            newResult.generator        = DocumentHelpers.GetDefaultGenerator();
            newResult.oval_definitions = definitions;
            newResult.results          = new List <SystemType> {
                new SystemType()
            };
            newResult.results[0].oval_system_characteristics = systemcharacteristics;
            newResult.EvaluatedExternalVariables             = evaluatedExternalVariables;

            // Generate new Definition Result entries
            foreach (var definition in definitions.definitions)
            {
                if ((definition.criteria == null) || (definition.criteria.Items == null) || (definition.criteria.Items.Count() < 1))
                {
                    continue;
                }
                var newDefinitionResult = new DefinitionType(definition);
                newResult.results[0].definitions.Add(newDefinitionResult);
            }
            // Generate new Test Result entries
            foreach (var test in definitions.tests)
            {
                var newTestResult = new TestType(test);
                newResult.results[0].tests.Add(newTestResult);
            }
            return(newResult);
        }
コード例 #3
0
ファイル: ExtendDefinitionType.cs プロジェクト: ywcsz/modSIC
 public override ResultEnumeration Analyze(oval_results resultDocument)
 {
     var refDefinition = resultDocument.results[0].definitions.Single(x => x.definition_id == definition_ref);
     var currentResult = refDefinition.criteria.Analyze(resultDocument);
     currentResult = oval_results.NegateResult(currentResult, negate);
     result = currentResult;
     return result;
 }
コード例 #4
0
        public override ResultEnumeration Analyze(oval_results resultDocument)
        {
            var refDefinition = resultDocument.results[0].definitions.Single(x => x.definition_id == definition_ref);
            var currentResult = refDefinition.criteria.Analyze(resultDocument);

            currentResult = oval_results.NegateResult(currentResult, negate);
            result        = currentResult;
            return(result);
        }
コード例 #5
0
ファイル: CriterionType.cs プロジェクト: jonaslsl/modSIC
 public override ResultEnumeration Analyze(oval_results resultDocument)
 {
     if (!bAnalyzed)
     {
         var refTest = resultDocument.results[0].tests.Single(x => x.test_id == test_ref);
         var currentResult = refTest.Analyze(resultDocument);
         currentResult = oval_results.NegateResult(currentResult, negate);
         result = currentResult;
     }
     return result;
 }
コード例 #6
0
 public override ResultEnumeration Analyze(oval_results resultDocument)
 {
     if (!bAnalyzed)
     {
         var refTest       = resultDocument.results[0].tests.Single(x => x.test_id == test_ref);
         var currentResult = refTest.Analyze(resultDocument);
         currentResult = oval_results.NegateResult(currentResult, negate);
         result        = currentResult;
     }
     return(result);
 }
コード例 #7
0
ファイル: TestType_Test.cs プロジェクト: jonaslsl/modSIC
        public void Analyze_Of_A_Test_With_No_Object_Id_Should_Return_Unknown()
        {
            var results = new oval_results();
            results.oval_definitions = new oval_definitions();
            var fakeTest = MockRepository.GenerateMock<Modulo.Collect.OVAL.Definitions.TestType>();
            fakeTest.Expect(x => x.HasObjectReference).Return(false).Repeat.Any();
            results.oval_definitions.tests = new [] { fakeTest };

            var target = new Modulo.Collect.OVAL.Results.TestType();
            target.test_id = results.oval_definitions.tests[0].id;
            
            ResultEnumeration result = target.Analyze(results);
            Assert.AreEqual(ResultEnumeration.unknown, result);
        }
コード例 #8
0
ファイル: CriteriaType.cs プロジェクト: yonglehou/modSIC
 public override ResultEnumeration Analyze(oval_results resultDocument)
 {
     if (!bAnalyzed)
     {
         List <ResultEnumeration> results = new List <ResultEnumeration>();
         foreach (var criteria in Items.Cast <CriteriaBase>())
         {
             results.Add(criteria.Analyze(resultDocument));
         }
         var currentResult = oval_results.CombineResultsByOperator(results, this.@operator);
         currentResult = oval_results.NegateResult(currentResult, negate);
         bAnalyzed     = true;
         result        = currentResult;
     }
     return(result);
 }
コード例 #9
0
ファイル: CriteriaType.cs プロジェクト: ywcsz/modSIC
 public override ResultEnumeration Analyze(oval_results resultDocument)
 {
     if (!bAnalyzed)
     {
         List<ResultEnumeration> results = new List<ResultEnumeration>();
         foreach (var criteria in Items.Cast<CriteriaBase>())
         {
             results.Add(criteria.Analyze(resultDocument));
         }
         var currentResult = oval_results.CombineResultsByOperator(results, this.@operator);
         currentResult = oval_results.NegateResult(currentResult, negate);
         bAnalyzed = true;
         result = currentResult;
     }
     return result;
 }
コード例 #10
0
ファイル: CriterionType.cs プロジェクト: yonglehou/modSIC
 public override ResultEnumeration Analyze(oval_results resultDocument)
 {
     if (!bAnalyzed)
     {
         var refTest = resultDocument.results[0].tests.SingleOrDefault(x => x.test_id == test_ref);
         if (refTest != null)
         {
             var currentResult = refTest.Analyze(resultDocument);
             currentResult = oval_results.NegateResult(currentResult, negate);
             result        = currentResult;
         }
         else
         {
             return(ResultEnumeration.notevaluated);
         }
     }
     return(result);
 }
コード例 #11
0
ファイル: CriterionType.cs プロジェクト: modulogrc/modSIC
 public override ResultEnumeration Analyze(oval_results resultDocument)
 {
     if (!bAnalyzed)
     {
         var refTest = resultDocument.results[0].tests.SingleOrDefault(x => x.test_id == test_ref);
         if (refTest != null)
         {
             var currentResult = refTest.Analyze(resultDocument);
             currentResult = oval_results.NegateResult(currentResult, negate);
             result = currentResult;
         }
         else
         {
             return ResultEnumeration.notevaluated;
         }
     }
     return result;
 }
コード例 #12
0
ファイル: TestType.cs プロジェクト: yonglehou/modSIC
        private OVAL.Definitions.variableEvaluator.VariablesEvaluated CreateEvalutedVariablesFromStateType(
            StateType state, oval_results ovalResults)
        {
            var allStateEntities = GetAllStateEntities(state);
            var variableValues   = new List <OVAL.Definitions.variableEvaluator.VariableValue>();

            foreach (var stateEntity in allStateEntities)
            {
                var newVariableValue = CreateVariableValuesFromStateEntity(state.id, stateEntity, ovalResults);
                if (newVariableValue != null)
                {
                    variableValues.Add(newVariableValue);
                }
            }

            return
                (new OVAL.Definitions.variableEvaluator.VariablesEvaluated(
                     variableValues));
        }
コード例 #13
0
ファイル: TestType.cs プロジェクト: yonglehou/modSIC
        private OVAL.Definitions.variableEvaluator.VariableValue CreateVariableValuesFromStateEntity(
            string stateID,
            string stateEntityVariable,
            oval_results ovalResults)
        {
            if (string.IsNullOrEmpty(stateEntityVariable))
            {
                return(null);
            }

            var variableEvaluator =
                new VariableEvaluator(
                    ovalResults.oval_definitions.variables.ToArray(),
                    ovalResults.results[0].oval_system_characteristics,
                    ovalResults.EvaluatedExternalVariables);

            var variableValues = variableEvaluator.EvaluateVariable(stateEntityVariable);

            return(new VariableValue(stateID, stateEntityVariable, variableValues));
        }
コード例 #14
0
ファイル: TestType.cs プロジェクト: yonglehou/modSIC
        public ResultEnumeration GetCheckStateResult(oval_results results, Definitions.TestType originalTest)
        {
            ResultEnumeration stateResult = ResultEnumeration.error;
            var itemsResults = new List <ResultEnumeration>();

            var testStates = ((originalTest.GetType().GetProperty("state")
                               .GetValue(originalTest, null) as StateRefType[]) ?? new StateRefType[] {}).Select(x => results.oval_definitions.states.SingleOrDefault(y => y.id == x.state_ref));

            foreach (var testedItem in tested_item)
            {
                var stateResults             = new List <ResultEnumeration>();
                var collectedItem            = results.results[0].oval_system_characteristics.system_data.SingleOrDefault(x => x.id == testedItem.item_id);
                ResultEnumeration itemResult = ResultEnumeration.notevaluated;

                if (collectedItem == null)
                {
                    itemResult = ResultEnumeration.notevaluated;
                }
                else
                {
                    foreach (var state in testStates)
                    {
                        var evaluatedVariables = CreateEvalutedVariablesFromStateType(state, results);
                        var tempResult         = ExecuteStateComparator(collectedItem, state, evaluatedVariables);
                        stateResults.Add(tempResult);
                    }

                    itemResult = oval_results.CombineResultsByOperator(stateResults, state_operator);
                }

                testedItem.result = itemResult;
                itemsResults.Add(itemResult);
            }
            stateResult = oval_results.CombineResultsByCheck(itemsResults, check);

            return(stateResult);
        }
コード例 #15
0
ファイル: TestType.cs プロジェクト: ywcsz/modSIC
        public ResultEnumeration GetCheckStateResult(oval_results results, Definitions.TestType originalTest)
        {
            ResultEnumeration stateResult = ResultEnumeration.error;
            var itemsResults = new List<ResultEnumeration>();

            var testStates = ((originalTest.GetType().GetProperty("state")
                .GetValue(originalTest,null) as StateRefType[]) ?? new StateRefType[]{}).Select(x => results.oval_definitions.states.SingleOrDefault(y => y.id == x.state_ref));
            foreach(var testedItem in tested_item)
            {
                var stateResults = new List<ResultEnumeration>();
                var collectedItem = results.results[0].oval_system_characteristics.system_data.SingleOrDefault(x => x.id == testedItem.item_id);
                ResultEnumeration itemResult = ResultEnumeration.notevaluated;

                if (collectedItem == null)
                    itemResult = ResultEnumeration.notevaluated;
                else
                {
                    foreach (var state in testStates)
                    {
                        var evaluatedVariables = CreateEvalutedVariablesFromStateType(state, results);
                        var tempResult = ExecuteStateComparator(collectedItem, state, evaluatedVariables);
                        stateResults.Add(tempResult);
                    }

                    itemResult = oval_results.CombineResultsByOperator(stateResults, state_operator);
                }

                testedItem.result = itemResult;
                itemsResults.Add(itemResult);
            }
            stateResult = oval_results.CombineResultsByCheck(itemsResults, check);

            return stateResult;
        }
コード例 #16
0
ファイル: TestType.cs プロジェクト: yonglehou/modSIC
        public ResultEnumeration Analyze(oval_results results)
        {
            if (!bAnalyzed)
            {
                var refTest = results.oval_definitions.tests.Single(x => x.id == test_id);
                if (!refTest.HasObjectReference)
                {
                    return(ResultEnumeration.unknown);
                }
                var           fi        = refTest.GetType().GetProperty("object");
                ObjectRefType objRef    = fi.GetValue(refTest, null) as ObjectRefType;
                var           sc        = results.results[0].oval_system_characteristics;
                var           colObject = sc.collected_objects.SingleOrDefault(x => x.id == objRef.object_ref);
                if (colObject == null)
                {
                    result = ResultEnumeration.notevaluated;
                }
                else
                {
                    // Copy all Referenced Items to result
                    if (colObject.reference != null)
                    {
                        foreach (var itemKey in colObject.reference)
                        {
                            var item = sc.system_data.Single(x => x.id == itemKey.item_ref);

                            var newMessageType    = item.message == null ? new MessageType[] { } :  item.message;
                            var newTestedItemType = new TestedItemType()
                            {
                                item_id = item.id,
                                message = newMessageType.ToList(),
                                status  = item.status,
                                result  = ResultEnumeration.notevaluated
                            };

                            tested_item.Add(newTestedItemType);
                        }
                    }
                    // Copy all Referenced Items to result
                    if (colObject.variable_value != null)
                    {
                        foreach (var varKey in colObject.variable_value)
                        {
                            tested_variable.Add(new TestedVariableType()
                            {
                                variable_id = varKey.variable_id, Value = varKey.Value
                            });
                        }
                    }

                    switch (colObject.flag)
                    {
                    case SystemCharacteristics.FlagEnumeration.error:
                        result = ResultEnumeration.error;
                        break;

                    case SystemCharacteristics.FlagEnumeration.notapplicable:
                        result = ResultEnumeration.notapplicable;
                        break;

                    case SystemCharacteristics.FlagEnumeration.notcollected:
                        result = ResultEnumeration.unknown;
                        break;

                    case SystemCharacteristics.FlagEnumeration.doesnotexist:
                        if ((check_existence == ExistenceEnumeration.none_exist) || (check_existence == ExistenceEnumeration.any_exist))
                        {
                            result = ResultEnumeration.@true;
                        }
                        else
                        {
                            result = ResultEnumeration.@false;
                        }
                        break;

                    case FlagEnumeration.complete:
                        ResultEnumeration completeResult = GetCheckExistenceResult();

                        if (completeResult == ResultEnumeration.@true)
                        {
                            if (IsThereReferenceStateForTest(refTest))
                            {
                                completeResult = GetCheckStateResult(results, refTest);
                            }
                        }

                        result = completeResult;

                        break;
                    }
                }
                bAnalyzed = true;
            }
            return(result);
        }
コード例 #17
0
ファイル: DefinitionType.cs プロジェクト: jonaslsl/modSIC
 public ResultEnumeration Analyze(oval_results oval_results)
 {
     result = criteria.Analyze(oval_results);
     return result;
 }
コード例 #18
0
ファイル: DefinitionType.cs プロジェクト: yonglehou/modSIC
 public ResultEnumeration Analyze(oval_results oval_results)
 {
     result = criteria.Analyze(oval_results);
     return(result);
 }
コード例 #19
0
ファイル: TestType.cs プロジェクト: ywcsz/modSIC
        public ResultEnumeration Analyze(oval_results results)
        {
            if (!bAnalyzed)
            {
                var refTest = results.oval_definitions.tests.Single(x => x.id == test_id);
                if (!refTest.HasObjectReference)
                {
                    return ResultEnumeration.unknown;
                }
                var fi = refTest.GetType().GetProperty("object");
                ObjectRefType objRef = fi.GetValue(refTest,null) as ObjectRefType;
                var sc = results.results[0].oval_system_characteristics;
                var colObject = sc.collected_objects.SingleOrDefault(x => x.id == objRef.object_ref);
                if (colObject == null)
                {
                    result = ResultEnumeration.notevaluated;
                }
                else
                {
                    // Copy all Referenced Items to result
                    if (colObject.reference != null)
                    {
                        foreach (var itemKey in colObject.reference)
                        {
                            var item = sc.system_data.Single(x => x.id == itemKey.item_ref);

                            var newMessageType = item.message == null ? new MessageType[] { } :  item.message;
                            var newTestedItemType = new TestedItemType()
                            {
                                item_id = item.id,
                                message = newMessageType.ToList(),
                                status = item.status,
                                result = ResultEnumeration.notevaluated
                            };

                            tested_item.Add(newTestedItemType);
                        }
                    }
                    // Copy all Referenced Items to result
                    if (colObject.variable_value != null)
                    {
                        foreach (var varKey in colObject.variable_value)
                        {
                            tested_variable.Add(new TestedVariableType() { variable_id = varKey.variable_id, Value = varKey.Value });
                        }
                    }

                    switch (colObject.flag)
                    {
                        case SystemCharacteristics.FlagEnumeration.error:
                            result = ResultEnumeration.error;
                            break;
                        case SystemCharacteristics.FlagEnumeration.notapplicable:
                            result = ResultEnumeration.notapplicable;
                            break;
                        case SystemCharacteristics.FlagEnumeration.notcollected:
                            result = ResultEnumeration.unknown;
                            break;
                        case SystemCharacteristics.FlagEnumeration.doesnotexist:
                            if ((check_existence == ExistenceEnumeration.none_exist) || (check_existence == ExistenceEnumeration.any_exist))
                                result = ResultEnumeration.@true;
                            else
                                result = ResultEnumeration.@false;
                            break;
                        case FlagEnumeration.complete:
                            ResultEnumeration completeResult = GetCheckExistenceResult();

                            if (completeResult == ResultEnumeration.@true)
                                if (IsThereReferenceStateForTest(refTest))
                                    completeResult = GetCheckStateResult(results, refTest);

                            result = completeResult;

                            break;
                    }
                }
                bAnalyzed = true;
            }
            return result;
        }
コード例 #20
0
ファイル: TestType.cs プロジェクト: ywcsz/modSIC
        private OVAL.Definitions.variableEvaluator.VariablesEvaluated CreateEvalutedVariablesFromStateType(
            StateType state, oval_results ovalResults)
        {
            var allStateEntities = GetAllStateEntities(state);
            var variableValues = new List<OVAL.Definitions.variableEvaluator.VariableValue>();

            foreach (var stateEntity in allStateEntities)
            {
                var newVariableValue = CreateVariableValuesFromStateEntity(state.id, stateEntity, ovalResults);
                if (newVariableValue != null)
                    variableValues.Add(newVariableValue);
            }

            return
                new OVAL.Definitions.variableEvaluator.VariablesEvaluated(
                    variableValues);
        }
コード例 #21
0
ファイル: TestType.cs プロジェクト: ywcsz/modSIC
        private OVAL.Definitions.variableEvaluator.VariableValue CreateVariableValuesFromStateEntity(
            string stateID,
            string stateEntityVariable,
            oval_results ovalResults)
        {
            if (string.IsNullOrEmpty(stateEntityVariable))
                return null;

            var variableEvaluator =
                new VariableEvaluator(
                    ovalResults.oval_definitions.variables.ToArray(),
                    ovalResults.results[0].oval_system_characteristics,
                    ovalResults.EvaluatedExternalVariables);

            var variableValues = variableEvaluator.EvaluateVariable(stateEntityVariable);

            return new VariableValue(stateID, stateEntityVariable, variableValues);
        }
コード例 #22
0
ファイル: oval_results_Test.cs プロジェクト: ywcsz/modSIC
 private void DoBasicResultAssert(oval_results ovalResults)
 {
     Assert.AreEqual(0, ovalResults.results[0].definitions.Where(d => d.result == ResultEnumeration.unknown).Count());
     Assert.AreEqual(0, ovalResults.results[0].tests.Where(t => t.result == ResultEnumeration.unknown).Count());
 }
コード例 #23
0
ファイル: oval_results.cs プロジェクト: jonaslsl/modSIC
        public static oval_results CreateFromDocuments(
            Definitions.oval_definitions definitions, 
            oval_system_characteristics systemcharacteristics,
            oval_variables evaluatedExternalVariables)
        {
            oval_results newResult = new oval_results();
            newResult.generator = DocumentHelpers.GetDefaultGenerator();
            newResult.oval_definitions = definitions;
            newResult.results =  new List<SystemType> { new SystemType() };
            newResult.results[0].oval_system_characteristics = systemcharacteristics;
            newResult.EvaluatedExternalVariables = evaluatedExternalVariables;

            // Generate new Definition Result entries
            foreach (var definition in definitions.definitions)
            {
                if ((definition.criteria == null) || (definition.criteria.Items == null) || (definition.criteria.Items.Count() < 1))
                    continue;
                var newDefinitionResult = new DefinitionType(definition);
                newResult.results[0].definitions.Add(newDefinitionResult);
            }
            // Generate new Test Result entries
            foreach (var test in definitions.tests)
            {
                var newTestResult = new TestType(test);
                newResult.results[0].tests.Add(newTestResult);
            }
            return newResult;
        }
コード例 #24
0
ファイル: oval_results_Test.cs プロジェクト: ywcsz/modSIC
 private Results.DefinitionType GetResultDefinitionByID(oval_results ovalResults, string definitionID)
 {
     return
         ovalResults
             .results.First()
                 .definitions
                     .Where(def => def.definition_id.Equals(definitionID)).Single();
 }
コード例 #25
0
ファイル: CriteriaBase.cs プロジェクト: jonaslsl/modSIC
 public abstract ResultEnumeration Analyze(oval_results resultDocument);
コード例 #26
0
 public abstract ResultEnumeration Analyze(oval_results resultDocument);