public void Should_be_possible_identify_when_an_unrecoverable_error_occurs() { IDocumentSession fakeSession = provider.GetSession(); CollectRequest collectRequest = this.GetCollectRequest(); session.SaveChanges(); CollectExecutionManagerFactory factory = new CollectExecutionManagerFactory(collectRequest, session); session.SaveChanges(); List <string> registryObjectsThatNotProcessInFirstTime = new List <string>() { "oval:org.mitre.oval:obj:4000" }; List <string> familyObjectsThatNotProcessInFirstTime = new List <string>(); CollectExecutionManager executionManager = factory.CreateExecutionManagerWWithInvalidCredentialsScenario(this.GetResultForRegistry(collectRequest, registryObjectsThatNotProcessInFirstTime), this.GetResultForFamily(collectRequest, familyObjectsThatNotProcessInFirstTime)); session.SaveChanges(); executionManager.ExecuteCollect(fakeSession, collectRequest, FamilyEnumeration.windows); session.SaveChanges(); CollectRequest collectRequestAfterExecute = session.Load <CollectRequest>(collectRequest.Oid.ToString()); this.CheckTheDefaulStateOfRequestCollectAfterOneExecution(collectRequestAfterExecute); Assert.AreEqual(true, collectRequestAfterExecute.GetCollectExecutions(session).First().ProbeExecutions.First().HasErrors()); Assert.IsTrue(collectRequestAfterExecute.isClosed(), "the request Collect is not closed"); }
public CollectRequest CreateCollectRequestCompleteAfterCollect(IDocumentSession session) { CollectRequest collectRequest = new CollectRequest(); session.Store(collectRequest); CollectExecution collectExecution = new CollectExecution(); session.Store(collectExecution); collectExecution.RequestId = collectRequest.Oid; collectExecution.SetDateStartCollect(); collectExecution.SetDateEndCollect(); ProbeResult probeResult = new ProbeResultFactory().CreateProbeResultForRegistryCollect(); CollectFactory collectFactory = new CollectFactory(session); ProbeExecution probeExecution = collectFactory.CreateAProbeExecution(probeResult, "registry"); CollectResult collectResult = new CollectResultFactory().CreateCollectResultForTheProbeExecution(probeResult); collectRequest.Result = collectResult; string systemCharacteristicsXml = this.GetSystemCharacteristicsInXML(".system_characteristics.oval.org.mitre.oval.sc.5368.xml"); collectResult.SystemCharacteristics = systemCharacteristicsXml; probeExecution.SystemCharacteristics = collectResult.SystemCharacteristics; collectExecution.ProbeExecutions.Add(probeExecution); this.CreateTarget(session, collectRequest); //session.Store(collectRequest); collectExecution.RequestId = collectRequest.Oid; return(collectRequest); }
public CollectResponse Collect(CollectRequest request) { return(new CollectResponse { Total = request.Param1 + request.Param2 }); }
public void Should_Parse_Correctly_A_Collect_Request_With_String_Data() { string data = "{ \n" + " \"payer\":{ \n" + " \"name\":\"John\",\n" + " \"surname\":\"Doe\",\n" + " \"email\":\"[email protected]\",\n" + " \"document\":\"1040035000\",\n" + " \"documentType\":\"CC\"\n" + " },\n" + " \"payment\":{ \n" + " \"reference\":\"TESTING123456\",\n" + " \"amount\":{ \n" + " \"currency\":\"COP\",\n" + " \"total\":\"10000\"\n" + " }\n" + " },\n" + " \"instrument\":{ \n" + " \"token\":{ \n" + " \"token\":\"961da9f371a8edc212a525f5e8d69934bec8484f546c720d3c5bf75350602ba0\"\n" + " }\n" + " }\n" + "}"; var request = new CollectRequest(data); Assert.AreEqual("961da9f371a8edc212a525f5e8d69934bec8484f546c720d3c5bf75350602ba0", request.Instrument.Token.TokenText); Assert.AreEqual("TESTING123456", request.GetReference()); Assert.IsNotNull(request.Instrument); }
private oval_results TryToGetOvalResultsDocumentFromCollectedAnalysis(CollectRequest collectRequest, string definitionsText, Result collectResult) { IEnumerable <string> errors; var scMS = new MemoryStream(Encoding.UTF8.GetBytes(collectResult.SystemCharacteristics)); var collectedSC = oval_system_characteristics.GetOvalSystemCharacteristicsFromStream(scMS, out errors); var docMS = new MemoryStream(Encoding.UTF8.GetBytes(definitionsText)); var definitions = oval_definitions.GetOvalDefinitionsFromStream(docMS, out errors); if (definitions == null || (definitions != null && definitions.definitions == null)) { return(null); } oval_variables externalVariables; if (collectRequest.ExternalVariables != null) { externalVariables = oval_variables.GetOvalVariablesFromText(collectRequest.ExternalVariables, out errors); } else { externalVariables = null; } return(oval_results.CreateFromDocuments(definitions, collectedSC, externalVariables)); }
public CollectExecutionManagerFactory(CollectRequest collectRequest, IDocumentSession session) { this.session = session; target = this.CreateTargetInfo(); this.collectRequest = collectRequest; this.ovalObjects = collectRequest.GetObjectTypes(session); }
private CollectExecution CreateCollectExecution(IDocumentSession session, CollectRequest collectRequest) { collectFactory = new CollectFactory(); CollectExecution collectExecution = collectFactory.CreateCollectExecution(session, collectRequest); return(collectExecution); }
private void GetSystemInformationFromTarget(CollectRequest collectRequest, ISystemInformationService systemInformationService) { SystemInformation systemInformation = systemInformationService.GetSystemInformationFrom(Target); SystemInfo systemInfo = new SystemInfoFactory().CreateSystemInfo(systemInformation); collectRequest.Target.SystemInformation = systemInfo; }
private void CreateCollectionExcutionWithError(IDocumentSession session, CollectRequest collectRequest, string capability, Exception ex, ExecutionLogBuilder executionLog) { CollectExecution collectExecution = this.CreateCollectExecution(session, collectRequest); collectExecution.SetDateStartCollect(); EndsACollectRequestBecauseThisErrorIsUnrecoverable(collectRequest, capability, collectExecution, ex, executionLog); }
private void UpdateSystemInformationOfTarget(IDocumentSession session, CollectRequest collectRequest, FamilyEnumeration plataform, ExecutionLogBuilder executionLog) { if (!collectRequest.Target.IsSystemInformationDefined()) { executionLog.CollectSystemInformation(); ISystemInformationService systemInformationService = ProbeManager.GetSystemInformationService(plataform); if (systemInformationService != null) { try { this.GetSystemInformationFromTarget(collectRequest, systemInformationService); session.SaveChanges(); } catch (RecoverableProbeException ex) { CollectExecution collectExecution = this.CreateCollectExecution(session, collectRequest); collectExecution.SetDateStartCollect(); this.ConfigureTheCollectRequestWithAnErrorProbeExecute(collectRequest, "SystemInformation", collectExecution, ex, executionLog); session.SaveChanges(); throw new SystemInformationException(ex.Message, ex); } catch (Exception ex) { CreateCollectionExcutionWithError(session, collectRequest, "SystemInformation", ex, executionLog); session.SaveChanges(); throw new SystemInformationException(ex.Message, ex); } } } }
public ProbeResult GetResultForFamily(CollectRequest collectRequest, List <string> resultsForObjects) { ProbeResultFactory factory = new ProbeResultFactory(); IEnumerable <ObjectType> familyObjects = collectRequest.GetObjectTypes(session).OfType <family_object>(); return(factory.CreateProbeResultForFamilyWithSpecificObjectTypes(familyObjects, resultsForObjects)); }
private CollectRequest GetCollectRequest() { CollectRequestFactory factory = new CollectRequestFactory(); CollectRequest collectRequest = factory.CreateCollectRequestWithSpecificDefinitions(session, "definitionsWithLocalVariable.xml"); return(collectRequest); }
/// <summary> /// Configures the request collect with one probeExecute with the error status. /// </summary> /// <param name="collectRequest">The request collect.</param> /// <param name="probe">The probe.</param> /// <param name="collectExecution">The collect execution.</param> /// <param name="error">The error.</param> private void ConfigureTheCollectRequestWithAnErrorProbeExecute(CollectRequest collectRequest, string probeCapability, CollectExecution collectExecution, Exception error, ExecutionLogBuilder executionLog) { executionLog.AnErrorOccurred(error.Message); executionLog.EndCollect(); ProbeExecution executionWithError = collectFactory.CreateAProbeExecutionWithError(probeCapability, executionLog.BuildExecutionLogs()); collectExecution.ProbeExecutions.Add(executionWithError); }
private void CreateTarget(IDocumentSession session, CollectRequest collectRequest) { Target target = new Target(); target.Address = "172.16.3.166"; //target.CollectRequest = collectRequest; collectRequest.Target = target; }
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 void Should_Parse_Correctly_A_Collect_Request_With_Object_Instance() { Payment payment = new Payment("TESTING_2020", null, false, false, null, null, null, null, null, null, null, null); var request = new CollectRequest(null, null, payment, null); Assert.IsInstanceOf <Payment>(payment); Assert.IsNotNull(request.Payment); Assert.AreEqual("TESTING_2020", request.GetReference()); }
public Result CreateDTOFromCollectResult(IDocumentSession session, CollectRequest collectRequest) { var collectResultDTO = new Result(); collectResultDTO.Date = collectRequest.Result.Date; collectResultDTO.SystemCharacteristics = collectRequest.Result.SystemCharacteristics; collectResultDTO.Status = collectRequest.Result.Status; collectResultDTO.ExecutionLogs = this.GetExecutionErrorLogs(session, collectRequest).ToArray(); return(collectResultDTO); }
public CollectRequest CreateCollectRequestFromDTO(Request collectRequestDTO, string definitionId) { var collectRequest = new CollectRequest(); targetAssembler.AddTargetInCollectRequest(collectRequestDTO, collectRequest); collectRequest.OvalDefinitionsId = definitionId; collectRequest.ExternalVariables = collectRequestDTO.ExternalVariables; return(collectRequest); }
public void AddTargetInCollectRequest(Request collectRequestDTO, CollectRequest collectRequest) { Target target = new Target(); target.Address = collectRequestDTO.Address; collectRequest.Target = target; this.AddCredentialToTarget(collectRequestDTO, target); this.AddTargetParametersInCollectRequest(collectRequestDTO, target); }
private string SaveCollectRequest(CollectRequest collectRequest) { try { return(collectRequest.Oid); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
public CollectRequest GetCollectRequest(IDocumentSession session, string id) { if (id != null) { CollectRequest collectRequest = session.Load <CollectRequest>(id); return(collectRequest); } else { return(null); } }
public void Should_Parse_Correctly_A_Collect_With_Credit() { string data = JsonConvert.SerializeObject(new { locale = "en_US", payer = new { document = "123456789", documentType = "CC", name = "Simon", surname = "Godoy", email = "*****@*****.**", }, payment = new { reference = "Testing_2020", description = "Testing payment for NUnit", amount = new { currency = "COP", total = 143000, }, allowPartial = false, subscribe = false, }, instrument = new { credit = new { code = 500, type = "02", groupCode = "P", installment = 3, }, token = new { token = "e317950201950c59e91b6a59b25d439888a504579715a09bc0862c76b64335d9", }, }, }); JObject json = JObject.Parse(data); var request = new CollectRequest(json); Assert.AreEqual((int)json["instrument"]["credit"]["code"], request.Instrument.Credit.Code); Assert.AreEqual((string)json["instrument"]["credit"]["type"], request.Instrument.Credit.Type); Assert.AreEqual((string)json["instrument"]["credit"]["groupCode"], request.Instrument.Credit.GroupCode); Assert.AreEqual((int)json["instrument"]["credit"]["installment"], request.Instrument.Credit.Installment); Assert.AreEqual((int)json["payment"]["amount"]["total"], request.Payment.Amount.Total); Assert.AreEqual(JObject.Parse(JsonConvert.SerializeObject(json["instrument"])), request.Instrument.ToJsonObject()); Assert.AreEqual(json, request.ToJsonObject()); }
public CollectInfo CreateCollectInfoFromCollectRequest(CollectRequest collectRequest) { CollectInfo collectInfoDTO = new CollectInfo(); collectInfoDTO.Address = collectRequest.Target.Address; collectInfoDTO.ReceivedOn = collectRequest.ReceivedOn; collectInfoDTO.CollectRequestId = collectRequest.Oid.ToString(); collectInfoDTO.ClientId = collectRequest.ClientId; collectInfoDTO.Status = collectRequest.Status; return(collectInfoDTO); }
public void Should_be_possible_to_save_a_request_collect_without_system_characteristics_defined() { IDocumentSession session = this.GetSession(); CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequest(session).Item2; Assert.IsNull(collectRequest.Result, "the systemcharacteristics is not null"); //collectRequest.Save(); session.SaveChanges(); CollectRequest newCollectRequest = session.Load <CollectRequest>(collectRequest.Oid.ToString()); Assert.IsNull(collectRequest.Result, "the result is null"); }
private DateTime GetCollectionStartDate(IDocumentSession session, CollectRequest collectRequest) { var firstExecution = collectRequest.GetCollectExecutions(session).FirstOrDefault(); if (firstExecution != null) { return(firstExecution.StartDate.ToUniversalTime()); } var collectPackage = Repository.GetCollectPackages(session, new[] { collectRequest.CollectPackageId }).First(); return(collectPackage.ScheduleInformation.ExecutionDate); }
public oval_results GetDocument(CollectRequest collectRequest, string definitions, Result collectResult) { if ((collectRequest != null) && (collectRequest.HasResult())) { var ovalResults = TryToGetOvalResultsDocumentFromCollectedAnalysis(collectRequest, definitions, collectResult); if (ovalResults != null) { ovalResults.Analyze(); return(ovalResults); } } return(null); }
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); }
/// <summary> /// Collect endpoint. /// </summary> /// <param name="collectRequest">collect request instance object.</param> /// <returns>redirect information instance object.</returns> public override RedirectInformation Collect(CollectRequest collectRequest) { XmlDocument response = new XmlDocument(); XmlDocument payload = JsonConvert.DeserializeXmlNode(collectRequest.ToJsonObject().ToString(), "payload"); XElement body = new XElement(wsdl.GetName("collect"), XElement.Parse(payload.InnerXml)); response.LoadXml(MakeRequest(body)); response = RemoveNullFields(response); XmlNode data = response.SelectSingleNode("descendant::collectResult"); JObject json = JObject.Parse(JsonConvert.SerializeXmlNode(data)); return(new RedirectInformation(json.GetValue("collectResult").ToString())); }
private static Tuple <CollectPackage, CollectRequest> GEtCollectRequest(IDocumentSession session) { CollectRequest collectRequest = new CollectRequest(); collectRequest.ReceivedOn = DateTime.Now; CollectPackage collectPackage = new CollectPackage(); collectPackage.ScheduleInformation = new CollectScheduleInformation() { ExecutionDate = DateTime.Now }; session.Store(collectPackage); collectRequest.CollectPackageId = collectPackage.Oid; return(new Tuple <CollectPackage, CollectRequest>(collectPackage, collectRequest)); }
public void CrearCollect() { Token token = new Token("e35935ecac1c134e4de2240aff62d11e6196bf7d3a6594ad0dc54528fff67276", null, "7157190631451111"); Instrument instrument = new Instrument(token); Person buyer = new Person("10000004", "CC", "Daniel", "Betancur", "*****@*****.**"); Amount amount = new Amount(1000); Payment payment = new Payment("123456789", "TEST", amount); CollectRequest collectRequest = new CollectRequest(buyer, payment, instrument); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Gateway gateway = CrearAutenticacion(); RedirectInformation collect = gateway.Collect(collectRequest); }