public void When_it_was_not_possible_to_establish_a_connection_to_target_the_status_of_collect_result_must_be_error() { IDocumentSession fakeSession = provider.GetSession(); var fakeRequestCollect = this.GetCollectRequest(); var definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); var newDefinitiondoc = new DefinitionDocument() { OriginalId = "01", Text = definitions.GetDefinitionsXml() }; session.Store(newDefinitiondoc); fakeRequestCollect.OvalDefinitionsId = newDefinitiondoc.Oid; var factory = new CollectExecutionManagerFactory(fakeRequestCollect, session); var executionManager = factory .CreateExecutionManagerWithCannotConnectToHostExceptionScenario( this.GetResultForRegistry(fakeRequestCollect, new List <String>()), this.GetResultForFamily(fakeRequestCollect, new string[] { "oval:org.mitre.oval:obj:1000" }.ToList()), true); //fakeRequestCollect.Collects.Add(new CollectExecution(session)); //fakeRequestCollect.Collects.Add(new CollectExecution(session)); //fakeRequestCollect.Collects.Add(new CollectExecution(session)); session.SaveChanges(); executionManager.ExecuteCollect(fakeSession, fakeRequestCollect, FamilyEnumeration.windows); var requestCollectAfterExecution = session.Load <CollectRequest>(fakeRequestCollect.Oid); Assert.AreEqual(CollectStatus.Error, requestCollectAfterExecution.Result.Status); }
public void Should_be_possible_to_get_the_oval_results_document() { //arrange var loadOvalDocument = new OvalDocumentLoader(); var session = GetSession(); var collectRequest = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(this.SessionDefault); var newDefinitiondoc = new DefinitionDocument() { OriginalId = "01", Text = loadOvalDocument.GetFakeOvalDefinitions("OvalResultDocumentTest.xml").GetDefinitionsXml() }; session.Store(newDefinitiondoc); collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid; var id = this.SaveCollectRequest(collectRequest, session); var collectResult = new Result(); collectResult.SystemCharacteristics = loadOvalDocument.GetFakeOvalSystemCharacteristics("OvalResultDocumentTest.xml").GetSystemCharacteristicsXML(); var ovalDocumentGenerator = new OvalDefinitionDocumentGenerator(); //act oval_results document = ovalDocumentGenerator.GetDocument(collectRequest, newDefinitiondoc.Text, collectResult); //assert Assert.IsNotNull(document); Assert.AreEqual(ResultEnumeration.@true, document.results[0].definitions[0].result); }
public void Should_be_possible_finalize_the_collectRequest_if_the_number_of_execution_exceeds_of_limits() { IDocumentSession fakeSession = provider.GetSession(); CollectRequest collectRequest = this.GetCollectRequest(); oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); var objList = new List <ObjectType>(); objList.Add(new family_object() { id = "oval:org.mitre.oval:obj:1000" }); objList.Add(new file_object() { id = "oval:org.mitre.oval:obj:5000" }); definitions.objects = objList.ToArray(); var newDefinitiondoc = new DefinitionDocument() { OriginalId = "01", Text = definitions.GetDefinitionsXml() }; session.Store(newDefinitiondoc); collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid; CollectExecutionManagerFactory factory = new CollectExecutionManagerFactory(collectRequest, session); List <string> registryObjectsThatNotProcessInFirstTime = new List <string>(); List <string> familyObjectsThatNotProcessInFirstTime = new List <string>(); CollectExecutionManager executionManager = factory.CreateExecutionManagerForTheSuccessScenario(this.GetResultForRegistry(collectRequest, registryObjectsThatNotProcessInFirstTime), this.GetResultForFamily(collectRequest, familyObjectsThatNotProcessInFirstTime)); session.Store(collectRequest); var newExecution1 = new CollectExecution() { RequestId = collectRequest.Oid }; session.Store(newExecution1); var newExecution2 = new CollectExecution() { RequestId = collectRequest.Oid }; session.Store(newExecution2); var newExecution3 = new CollectExecution() { RequestId = collectRequest.Oid }; session.Store(newExecution3); executionManager.ExecuteCollect(fakeSession, collectRequest, FamilyEnumeration.windows); session.SaveChanges(); CollectRequest collectRequestAfterExecute = session.Load <CollectRequest>(collectRequest.Oid.ToString()); Assert.IsNotNull(collectRequest); Assert.AreEqual(4, collectRequestAfterExecute.GetNumberOfExecutions(session)); Assert.IsTrue(collectRequestAfterExecute.isClosed()); }
public CollectRequest CreateCollectRequestWithInvalidDefinitions(IDocumentSession session) { CollectRequest collectRequest = GEtCollectRequest(session).Item2; string definitionsInXml = GetOvalObjectInXML(".definitions.oval.org.mitre.oval.def.5368.invalid.xml"); StringBuilder builder = new StringBuilder(definitionsInXml); var newDefinitiondoc = new DefinitionDocument() { OriginalId = "01", Text = builder.ToString() }; session.Store(newDefinitiondoc); collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid; return(collectRequest); }
private CollectRequest GetOvalObjectInXML( IDocumentSession session, string definitions, string externalVariables) { var newDefinitiondoc = new DefinitionDocument() { OriginalId = "01", Text = definitions }; session.Store(newDefinitiondoc); return(new CollectRequest() { OvalDefinitionsId = newDefinitiondoc.Oid, ExternalVariables = externalVariables }); }
public DefinitionDocument CreateDefinitionDocumentFromInfo(IDocumentSession session, DefinitionInfo definitionInfo) { var definition = new DefinitionDocument(); // Save properties definition.OriginalId = definitionInfo.Id; definition.Text = definitionInfo.Text; // Generate document hash definition.Hash = Convert.ToBase64String(new System.Security.Cryptography.SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(definition.Text))); session.Store(definition); session.SaveChanges(); return definition; }
public CollectRequest CreateCollectRequestWithSpecificDefinitions(IDocumentSession session, string nameOfDefinitions) { string completeName = ".definitions." + nameOfDefinitions; CollectRequest collectRequest = GEtCollectRequest(session).Item2; var newDefinitiondoc = new DefinitionDocument() { OriginalId = "01", Text = GetOvalObjectInXML(completeName) }; session.Store(newDefinitiondoc); collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid; CreateTarget(session, collectRequest); session.Store(collectRequest); return(collectRequest); }
public DefinitionDocument CreateDefinitionDocumentFromInfo(IDocumentSession session, DefinitionInfo definitionInfo) { var definition = new DefinitionDocument(); // Save properties definition.OriginalId = definitionInfo.Id; definition.Text = definitionInfo.Text; // Generate document hash definition.Hash = Convert.ToBase64String(new System.Security.Cryptography.SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(definition.Text))); session.Store(definition); session.SaveChanges(); return(definition); }
public Tuple <CollectPackage, CollectRequest> CreateCollectRequest(IDocumentSession session) { var request = GEtCollectRequest(session); var collectRequestPackage = request.Item1; var collectRequest = request.Item2; var newDefinitiondoc = new DefinitionDocument() { OriginalId = "01", Text = GetOvalObjectInXML(".definitions.fdcc_xpfirewall_oval.xml") }; session.Store(newDefinitiondoc); collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid; collectRequest.ExternalVariables = new ExternalVariableFactory().GetExternalVariableWithDefaultValueFrom("fdcc_xpfirewall_oval.xml"); this.CreateTarget(session, collectRequest); session.Store(collectRequest); return(new Tuple <CollectPackage, CollectRequest>(collectRequestPackage, collectRequest)); }
public void Should_be_possible_to_get_a_definition_by_Ids() { IDocumentSession fakeSession = this.GetSession(); string definitionId = "def1"; var fakeDefinition = new DefinitionDocument() { OriginalId = definitionId }; fakeSession.Store(fakeDefinition); fakeSession.SaveChanges(); var repository = new CollectRequestRepository(dataprovider); var resultByOriginalId = repository.GetDefinitionByOriginalId(fakeSession, definitionId); var resultByNewId = repository.GetDefinitionByDocumentId(fakeSession, fakeDefinition.Oid); Assert.IsNotNull(resultByOriginalId); Assert.AreEqual(definitionId, resultByOriginalId.OriginalId); Assert.AreEqual(fakeDefinition.Oid, resultByOriginalId.Oid); Assert.AreEqual(resultByOriginalId, resultByNewId); }
public CollectRequest CreateCollectRequestIncompleteAfterCollect(IDocumentSession session) { CollectRequest collectRequest = new CollectRequest(); string definitionsInXml = GetOvalObjectInXML(".definitions.fdcc_xpfirewall_oval.xml"); StringBuilder builder = new StringBuilder(definitionsInXml); var newDefinitiondoc = new DefinitionDocument() { OriginalId = "01", Text = builder.ToString() }; session.Store(newDefinitiondoc); collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid; session.Store(collectRequest); CollectExecution collectExecution = new CollectExecution(); collectExecution.RequestId = collectRequest.Oid; session.Store(collectExecution); collectExecution.SetDateStartCollect(); collectExecution.SetDateEndCollect(); //collectRequest.Collects.Add(collectExecution); ProbeResult probeResult = new ProbeResultFactory().CreateProbeResultForRegistryCollect(); CollectFactory collectFactory = new CollectFactory(session); ProbeExecution probeExecution = collectFactory.CreateAProbeExecution(probeResult, "registry"); CollectResult collectResult = new CollectResultFactory().CreateCollectResultForTheProbeExecution(probeResult); string systemCharacteristicsXml = this.GetSystemCharacteristicsInXML(".system_characteristics.fdcc_xpfirewall_oval.sc_incomplete.xml"); collectResult.SystemCharacteristics = systemCharacteristicsXml; probeExecution.SystemCharacteristics = collectResult.SystemCharacteristics; collectExecution.ProbeExecutions.Add(probeExecution); // collectRequest.Collects.Add(collectExecution); this.CreateTarget(session, collectRequest); session.SaveChanges(); return(collectRequest); }