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); }
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); }
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; }
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); }
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; }
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); }
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); }
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); }
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; }
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); }
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; }
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)); }
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)); }
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); }
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; }
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); }
public ResultEnumeration Analyze(oval_results oval_results) { result = criteria.Analyze(oval_results); return result; }
public ResultEnumeration Analyze(oval_results oval_results) { result = criteria.Analyze(oval_results); return(result); }
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; }
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); }
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); }
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()); }
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; }
private Results.DefinitionType GetResultDefinitionByID(oval_results ovalResults, string definitionID) { return ovalResults .results.First() .definitions .Where(def => def.definition_id.Equals(definitionID)).Single(); }
public abstract ResultEnumeration Analyze(oval_results resultDocument);