public void Should_not_be_possible_to_get_value_to_variableComponent_if_this_variable_refer_his_localVariable() { OvalDocumentLoader ovalDocuments = new OvalDocumentLoader(); oval_definitions definitions = ovalDocuments.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions); oval_system_characteristics systemSystemCharacteristics = ovalDocuments.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemSystemCharacteristics); VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { id = "oval:org.mitre.oval:var:4000" }; VariableComponentType variableComponent = new VariableComponentType() { var_ref = "oval:org.mitre.oval:var:4000" }; LocalVariableVariablesComponent variableComponentEvaluator = new LocalVariableVariablesComponent(localVariable, variableComponent, definitions.variables, systemSystemCharacteristics); IEnumerable <string> values = variableComponentEvaluator.GetValue(); Assert.IsTrue(values.Count() == 0); }
public void Should_be_possible_to_get_only_unique_values_for_a_list_with_duplicates() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithUnique(). AddLiteralComponent(@"banana"). AddLiteralComponent(@"banana"). AddLiteralComponent(@"apple"). AddLiteralComponent(@"banana"). SetInLocalVariable(). Build(); oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions, "the definitions was loaded"); oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); var uniqueFunctionComponent = factory.GetLocalVariableComponent(localVariable); Assert.IsInstanceOfType(uniqueFunctionComponent, typeof(UniqueFunctionComponent)); IEnumerable <string> values = uniqueFunctionComponent.GetValue(); Assert.AreEqual(2, values.Count()); Assert.AreEqual("banana", values.ElementAt(0)); Assert.AreEqual("apple", values.ElementAt(1)); }
public ConcatFunctionComponent(ConcatFunctionType concatFunctionType, IEnumerable <VariableType> variablesOfDefinitions, oval_system_characteristics systemCharacteristics) { this.variablesOfDefinitions = variablesOfDefinitions; this.systemCharacteristics = systemCharacteristics; this.concatFunctionType = concatFunctionType; this.concatFunction = new OvalConcatFunction(base.components); }
public void MyTestInitialize() { OvalDocumentLoader ovalDocument = new OvalDocumentLoader(); definitions = ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); systemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); }
public void Should_be_possible_to_get_value_to_variableComponent_by_the_LocalVariable() { OvalDocumentLoader ovalDocuments = new OvalDocumentLoader(); oval_definitions definitions = ovalDocuments.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions); oval_system_characteristics systemSystemCharacteristics = ovalDocuments.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemSystemCharacteristics); VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { id = "oval:org.mitre.oval:var:5000" }; VariableComponentType variableComponent = new VariableComponentType() { var_ref = "oval:org.mitre.oval:var:4000" }; LocalVariableVariablesComponent variableComponentEvaluator = new LocalVariableVariablesComponent(localVariable, variableComponent, definitions.variables, systemSystemCharacteristics); IEnumerable <string> values = variableComponentEvaluator.GetValue(); Assert.IsTrue(values.Count() > 0, "the quantity of value is not expected"); Assert.IsTrue(values.ElementAt(0) == @"Software\Microsoft\Windows NT\CurrentVersion", "the value is not expected"); }
public void Should_be_possible_to_get_count_result_for_a_simple_list() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithCount(). AddLiteralComponent(@"banana"). AddLiteralComponent(@"apple"). SetInLocalVariable(). Build(); oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions, "the definitions was loaded"); oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); var countFunctionComponent = factory.GetLocalVariableComponent(localVariable); Assert.IsInstanceOfType(countFunctionComponent, typeof(CountFunctionComponent)); IEnumerable <string> values = countFunctionComponent.GetValue(); Assert.AreEqual(1, values.Count()); Assert.AreEqual("2", values.First()); }
public void Should_be_possible_to_get_value_of_concatFunction_with_ObjectComponent_and_LiteralComponent() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithConcat(). AddLiteralComponent(@"c:\"). AddObjectComponent("oval:org.mitre.oval:obj:1000", "family"). SetInLocalVariable(). Build(); oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions, "the definitions was loaded"); oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent concatFunctionComponent = factory.GetLocalVariableComponent(localVariable); Assert.IsInstanceOfType(concatFunctionComponent, typeof(ConcatFunctionComponent)); IEnumerable <string> values = concatFunctionComponent.GetValue(); Assert.IsTrue(values.Count() > 0, "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0) == @"c:\windows", "the value is not expected"); }
public VariableEvaluator(IEnumerable <VariableType> variables, oval_system_characteristics systemCharacteristics, oval_variables externalVariables) { this.variablesOfDefinitions = variables; this.evaluatorFactory = new EvaluatorFactory(); this.systemCharacteristics = systemCharacteristics; this.externalVariables = externalVariables; }
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 void Should_be_possible_to_get_value_of_concatFunction_with_multiples_values_of_return() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithConcat(). AddObjectComponent("oval:org.mitre.oval:obj:5000", "name"). AddLiteralComponent(@"\"). AddObjectComponent("oval:org.mitre.oval:obj:6000", "name"). AddLiteralComponent(@"\"). AddObjectComponent("oval:org.mitre.oval:obj:7000", "name"). SetInLocalVariable(). Build(); oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions, "the definitions was loaded"); oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent concatFunctionComponent = factory.GetLocalVariableComponent(localVariable); Assert.IsInstanceOfType(concatFunctionComponent, typeof(ConcatFunctionComponent)); IEnumerable <string> values = concatFunctionComponent.GetValue(); Assert.IsTrue(values.Count() == 4, "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0) == @"BuildLabEx\SoftwareType\InstallDate", "the value is not expected"); Assert.IsTrue(values.ElementAt(1) == @"BuildLabEx\SystemRoot\InstallDate", "the value is not expected"); Assert.IsTrue(values.ElementAt(2) == @"CSDBuildNumber\SoftwareType\InstallDate", "the value is not expected"); Assert.IsTrue(values.ElementAt(3) == @"CSDBuildNumber\SystemRoot\InstallDate", "the value is not expected"); }
private List <LocalVariableComponent> GetLocalVariableComponentList(oval_system_characteristics systemCharacteristics) { var components = new List <LocalVariableComponent>(); var literalComponent = new LiteralComponentType() { Value = @"\" }; var objectComponent1 = new ObjectComponentType() { object_ref = "oval:org.mitre.oval:obj:5000", item_field = "name" }; var objectComponent2 = new ObjectComponentType() { object_ref = "oval:org.mitre.oval:obj:6000", item_field = "name" }; var objectComponentEvaluator1 = new LocalVariableObjectComponent(objectComponent1, systemCharacteristics); var literalComponentEvaluator = new LocalVariableLiteralComponent(literalComponent); var objectComponentEvaluator2 = new LocalVariableObjectComponent(objectComponent2, systemCharacteristics); components.Add(objectComponentEvaluator1); components.Add(literalComponentEvaluator); components.Add(objectComponentEvaluator2); return(components); }
public SetEvaluator(oval_system_characteristics systemCharacteristics, IEnumerable <StateType> states, VariablesEvaluated variables) { this.systemCharacteristics = systemCharacteristics; this.ovalDefinitionStates = states; this.variables = variables; this.filterEvaluator = new FilterEvaluator(this.systemCharacteristics, this.ovalDefinitionStates, this.variables); }
public SystemCharacteristicsBuilder() { systemCharacteristics = new oval_system_characteristics(); sequence = 1; newObjectTypes = new List <ObjectType>(); newItemTypes = new List <ItemType>(); addedItemsId = new List <String>(); }
private bool IsSequenceOfItemTypeExpected(oval_system_characteristics systemCharacteristics) { int max = systemCharacteristics.system_data.Max <ItemType>(x => int.Parse(x.id)); int min = systemCharacteristics.system_data.Min <ItemType>(x => int.Parse(x.id)); int total = systemCharacteristics.system_data.Count() - 1; return((max - min) == total); }
private string GetSystemCharacteristicsInXML(string xml) { IEnumerable <string> errors; var sampleDoc = GetType().Assembly.GetManifestResourceStream( GetType().Assembly.GetName().Name + xml); oval_system_characteristics systemCharacteristics = oval_system_characteristics.GetOvalSystemCharacteristicsFromStream(sampleDoc, out errors); return(systemCharacteristics.GetSystemCharacteristicsXML()); }
public LocalVariableComponentsFactory( oval_system_characteristics systemCharacteristics, IEnumerable <VariableType> variablesOfDefinitions, Modulo.Collect.OVAL.Variables.oval_variables externalVariables = null) { this.variablesOfDefinitions = variablesOfDefinitions; this.systemCharacteristics = systemCharacteristics; this.ExternalVariables = externalVariables; }
public void MyTestInitialize() { OvalDocumentLoader ovalDocument = new OvalDocumentLoader(); this.systemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_sets.xml"); oval_definitions definitions = ovalDocument.GetFakeOvalDefinitions("definitionsWithSet.xml"); this.states = definitions.states; }
/// <summary> /// Creates the system characteristics given the probeResult. /// </summary> /// <param name="probeResult">result of the probe execution.</param> /// <returns></returns> public oval_system_characteristics CreateSystemCharacteristics(ProbeResult probeResult) { oval_system_characteristics systemCharacteristics = new oval_system_characteristics(); systemCharacteristics.collected_objects = this.GetCollectedObjects(probeResult); systemCharacteristics.system_data = this.GetSystemType(probeResult); systemCharacteristics.generator = this.GetGenerator(); systemCharacteristics.system_info = this.GetSystemInfo(probeResult); return(systemCharacteristics); }
public void Should_be_possible_to_create_a_systemCharacteristics_eliminating_duplicate_references_for_itemType_in_the_systemData_property() { SystemCharacteristicsFactory factory = new SystemCharacteristicsFactory(); ProbeResult probeResult = new ProbeResultFactory().CreateProbeResultForRegistryCollectWithSytemDataDuplicated(); oval_system_characteristics systemCharacteristics = factory.CreateSystemCharacteristics(probeResult); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics expected is null"); Assert.AreEqual(2, systemCharacteristics.system_data.Count(), "the quantity of system data is not expected"); }
public void Should_be_possible_to_get_systemCharacteristics_from_a_collectResult() { ProbeResult probeResult = new ProbeResultFactory().CreateProbeResultForRegistryCollect(); CollectResult collectResult = new CollectResultFactory().CreateCollectResultForTheProbeExecution(probeResult); oval_system_characteristics systemCharacteristics = collectResult.GetSystemCharacteristic(); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics is null"); Assert.IsTrue(systemCharacteristics.collected_objects.Count() > 0, "the quantity of collected object is 0"); Assert.IsTrue(systemCharacteristics.system_data.Count() > 0, "the quantity of system data is 0"); }
public LocalVariableEvaluator( VariablesTypeVariableLocal_variable variable, oval_system_characteristics systemCharacteristics, IEnumerable <VariableType> variablesOfDefinitions, Modulo.Collect.OVAL.Variables.oval_variables externalVariables = null) { this.variable = variable; this.systemCharacteristics = systemCharacteristics; this.localVariableComponentFactory = new LocalVariableComponentsFactory(systemCharacteristics, variablesOfDefinitions, externalVariables); this.variablesOfDefinitions = variablesOfDefinitions; }
public static CollectInfo CreateFakeCollectInfo( IEnumerable <Definitions.ObjectType> objects, VariablesEvaluated variables = null, oval_system_characteristics systemCharacteristics = null) { CollectInfo collectInfo = new CollectInfo(); collectInfo.Variables = (variables == null) ? new VariablesEvaluated(new List <VariableValue>()) : variables; collectInfo.ObjectTypes = objects; collectInfo.SystemCharacteristics = systemCharacteristics; return(collectInfo); }
public LocalVariableVariablesComponent( VariableType localVariable, VariableComponentType variable, IEnumerable <VariableType> variablesOfOvalDefinitions, oval_system_characteristics systemCharacteristics, Modulo.Collect.OVAL.Variables.oval_variables externalVariables = null) { this.variablesOfDefinitions = variablesOfOvalDefinitions; this.variable = variable; this.systemCharacteristics = systemCharacteristics; this.localVariable = localVariable; this.variableEvaluator = new VariableEvaluator(variablesOfDefinitions, systemCharacteristics, externalVariables); }
/// <summary> /// Gets the system characteristics of all probe execution of this collectExecution. /// </summary> /// <returns>a list of object oval_system_characteristics</returns> public IEnumerable <oval_system_characteristics> GetSystemCharacteristics() { List <oval_system_characteristics> systemCharacteristics = new List <oval_system_characteristics>(); foreach (ProbeExecution probeExecution in ProbeExecutions) { oval_system_characteristics resultSystemCharacteristics = probeExecution.GetSystemCharacteristics(); if (resultSystemCharacteristics != null) { systemCharacteristics.Add(resultSystemCharacteristics); } } return(systemCharacteristics); }
public void Should_be_possible_to_build_a_system_characteristics_in_steps() { SystemCharacteristicsBuilder builder = new SystemCharacteristicsBuilder(); oval_system_characteristics sc = this.GetSystemCharacteristics("oval.org.mitre.oval.sc.5368.xml"); oval_system_characteristics systemCharacteristics = builder.WithGenerator(sc.generator) .WithSystemInfo(sc.system_info) .AddCollectedObjectsWithSystemData(sc.collected_objects, sc.system_data) .Build(); Assert.IsNotNull(systemCharacteristics); Assert.IsTrue(systemCharacteristics.system_data.Count() == sc.system_data.Count(), "the system data is not expected"); Assert.IsTrue(IsSequenceOfItemTypeExpected(systemCharacteristics), "the sequence in the system data is no expected"); }
/// <summary> /// Creates the system characteristics by XML. /// </summary> /// <param name="systemCharacteristicsInXML">The system characteristics in XML.</param> /// <returns></returns> public oval_system_characteristics CreateSystemCharacteristicsByXML(string systemCharacteristicsInXML) { try { MemoryStream m = new MemoryStream(Encoding.UTF8.GetBytes(systemCharacteristicsInXML)); IEnumerable <string> errors; oval_system_characteristics ovalSystemCharacteristics = oval_system_characteristics.GetOvalSystemCharacteristicsFromStream(m, out errors); return(ovalSystemCharacteristics); } catch (Exception ex) { //throw new InvalidXMLOvalSystemCharacteristicsException(String.Format("The Oval System Characteristics XML is Invalid: {0}", ex.Message), ex); throw new InvalidXMLOvalSystemCharacteristicsException( String.Format("The Oval System Characteristics XML is Invalid: {0}", ex.ToString()), ex); } }
/// <summary> /// Creates the correct implementation of variable for the evaluation. /// </summary> /// <param name="variable">The oval definitions variable.</param> /// <returns></returns> public Evaluator CreateVariable(VariableType variable, oval_system_characteristics sytemCharacteristics, IEnumerable <VariableType> variablesOfDefinitions, oval_variables externalVariables) { if (variable is VariablesTypeVariableConstant_variable) { return(new ConstantVariableEvaluator((VariablesTypeVariableConstant_variable)variable)); } else if (variable is VariablesTypeVariableLocal_variable) { return(new LocalVariableEvaluator((VariablesTypeVariableLocal_variable)variable, sytemCharacteristics, variablesOfDefinitions, externalVariables)); } else if (variable is VariablesTypeVariableExternal_variable) { return(new ExternalVariableEvaluator((VariablesTypeVariableExternal_variable)variable, externalVariables)); } return(null); }
public void Should_be_possible_to_build_a_system_characteristics_in_steps_and_generate_a_xml_from_this() { SystemCharacteristicsBuilder builder = new SystemCharacteristicsBuilder(); oval_system_characteristics sc = this.GetSystemCharacteristics("oval.org.mitre.oval.sc.5368.xml"); oval_system_characteristics systemCharacteristics = builder.WithGenerator(sc.generator) .WithSystemInfo(sc.system_info) .AddCollectedObjectsWithSystemData(sc.collected_objects, sc.system_data) .Build(); Assert.IsNotNull(systemCharacteristics); string systemCharacteristicsInXml = systemCharacteristics.GetSystemCharacteristicsXML(); Assert.IsNotNull(systemCharacteristicsInXml); }
public void Should_be_possible_to_create_system_characteristics_given_a_probeResult() { SystemCharacteristicsFactory factory = new SystemCharacteristicsFactory(); ProbeResult probe = new ProbeResultFactory().CreateProbeResultForRegistryCollect(); oval_system_characteristics systemCharacteristics = factory.CreateSystemCharacteristics(probe); Assert.IsNotNull(systemCharacteristics); Assert.IsNotNull(systemCharacteristics.collected_objects, "the collected object is null"); Assert.IsTrue(systemCharacteristics.collected_objects[0].id == ProbeResultFactory.ID_REGISTRY_OBJECT, "the oval id is not expected"); Assert.IsTrue(systemCharacteristics.collected_objects.Count() == 1); Assert.IsNotNull(systemCharacteristics.system_data, "the system data is null"); Assert.IsTrue(systemCharacteristics.system_data.Count() > 0, "the system data is empty."); Assert.IsNotNull(systemCharacteristics.generator, "the generator is null"); Assert.IsNotNull(systemCharacteristics.system_info, "the system info is not null."); Assert.IsTrue(systemCharacteristics.system_info.interfaces.Count() == 1, "the interfaces is not expected"); }
public void Should_be_possible_to_get_a_system_characteristics_in_xml_format_given_a_probeResult() { SystemCharacteristicsFactory factory = new SystemCharacteristicsFactory(); ProbeResult probe = new ProbeResultFactory().CreateProbeResultForRegistryCollect(); string systemCharacteristicsXML = factory.CreateSystemCharacteristicsInXMLFormat(probe); Assert.IsNotNull(systemCharacteristicsXML); //creates a stream for the xml generated MemoryStream m = new MemoryStream(Encoding.UTF8.GetBytes(systemCharacteristicsXML)); IEnumerable <string> loadErrors; oval_system_characteristics systemCharacteristicsFromXmlGenerated = oval_system_characteristics.GetOvalSystemCharacteristicsFromStream(m, out loadErrors); Assert.IsNotNull(systemCharacteristicsFromXmlGenerated, "Not was possible to get a SystemCharacteristis given the xml generated"); Assert.IsTrue(loadErrors.Count() == 0, "there are errors in the xml"); }