public void Should_be_possible_to_evaluate_variables_from_request_collect() { var session = GetSession(); var collectRequest = new CollectRequestFactory() .CreateCollectRequestWithSpecificDefinitions( session, "definitionsWithLocalVariable.xml"); var evaluatedVariables = new VariableEvaluatorService().Evaluate(collectRequest, session); Assert.AreEqual(3, evaluatedVariables.GetQuantityOfVariables(), "The quantity of variables is not expected."); var variables = evaluatedVariables.GetVariableValueForVariableId("oval:org.mitre.oval:var:5000"); Assert.AreEqual(2, variables.Count(), "The quantity of variable of id 5000 is not expected."); Assert.AreEqual("oval:org.mitre.oval:obj:5000", variables.ElementAt(0).OvalComponentId, "The variable oval component id is not expected."); Assert.AreEqual(1, variables.ElementAt(0).values.Count(), 1, "The quantity of values from variable of id 5000 is not expected."); Assert.AreEqual("CurrentType", variables.ElementAt(0).values.ElementAt(0), "The value from variable of id 5000 is not expected."); variables = evaluatedVariables.GetVariableValueForVariableId("oval:org.mitre.oval:var:4000"); Assert.AreEqual(1, variables.Count(), "The quantity of variable of id 4000 is not expected"); Assert.AreEqual("oval:org.mitre.oval:obj:4000", variables.ElementAt(0).OvalComponentId, "The variable oval component id is not expected."); // not exists value because the system characteristics was not generate yet Assert.AreEqual(0, variables.ElementAt(0).values.Count(), "The quantity of values from variable of id 4000 is not expected"); }
private CollectRequest GetCollectRequest() { CollectRequestFactory factory = new CollectRequestFactory(); CollectRequest collectRequest = factory.CreateCollectRequestWithSpecificDefinitions(session, "definitionsWithLocalVariable.xml"); return(collectRequest); }
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_to_reschedule_the_collectRequest_that_was_not_collect() { var fakeSession = DataProvider.GetSession(); var package1 = new CollectRequestFactory().CreateCollectRequest(fakeSession); var collectRequest = package1.Item2; this.SaveCollectRequest(collectRequest); var package2 = new CollectRequestFactory().CreateCollectRequest(fakeSession); var otherCollectRequest = package2.Item2; this.SaveCollectRequest(otherCollectRequest); package1.Item1.ScheduleInformation.ExecutionDate.AddSeconds(100); package2.Item1.ScheduleInformation.ExecutionDate.AddSeconds(100); var fakeRepository = new CollectRequestRepository(DataProvider); var scheduler = new StdSchedulerFactory().GetScheduler(); var scheduleController = new ScheduleController(scheduler); scheduleController.TypeOfExecutionJob = typeof(TestJob); scheduleController.ReScheduleCollectRequests( fakeSession, new[] { collectRequest, otherCollectRequest }, fakeRepository); Assert.AreEqual(2, scheduleController.GetNumberOfCollectRequestScheduled(), "the number of collectRequest schedule is not expected"); scheduler.Shutdown(); }
public void Should_be_possible_to_get_the_results_of_collect() { var collectRequest = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(this.SessionDefault); var id = this.SaveCollectRequest(collectRequest, SessionDefault); var collectResult = this.CollectController.GetCollectedResultDocument(id.ToString()); Assert.IsNotNull(collectResult); Assert.IsNotNull(collectResult.Date); Assert.IsNotNull(collectResult.SystemCharacteristics); }
private IEnumerable <CollectExecutionLog> GetExecutionLogs() { LocalDataProvider provider = new LocalDataProvider(); IDocumentSession fakeSession = provider.GetSession(); CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(fakeSession); fakeSession.SaveChanges(); IEnumerable <CollectExecutionLog> executionLogs = collectRequest.GetExecutionLog(fakeSession); return(executionLogs); }
public void Should_be_possible_to_create_CollectInfoDTO_from_RequestColect() { var session = this.GetSession(); CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequest(session).Item2; CollectRequestAssembler assembler = new CollectRequestAssembler(dataProvider); CollectInfo collectInfo = assembler.CreateCollectInfoFromCollectRequest(collectRequest); Assert.IsNotNull(collectInfo); Assert.AreEqual(collectRequest.Oid.ToString(), collectInfo.CollectRequestId); Assert.AreEqual(collectRequest.Target.Address, collectInfo.Address); Assert.AreEqual(collectRequest.ReceivedOn, collectInfo.ReceivedOn); }
public void Should_be_possible_to_get_CollectResultDTO_from_CollectResult() { LocalDataProvider provider = new LocalDataProvider(); var fakeSession = provider.GetSession(); CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(fakeSession); fakeSession.SaveChanges(); CollectResultAssembler assembler = new CollectResultAssembler(); var collectResult = assembler.CreateDTOFromCollectResult(fakeSession, collectRequest); Assert.IsNotNull(collectResult); Assert.IsNotNull(collectResult.Date); Assert.IsNotNull(collectResult.SystemCharacteristics); }
public void Should_be_possible_to_get_A_compressed_execution_Log_from_CollectResult() { LocalDataProvider provider = new LocalDataProvider(); var fakeSession = provider.GetSession(); CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(fakeSession); fakeSession.SaveChanges(); CollectResultAssembler assembler = new CollectResultAssembler(); var serializedCollectLog = assembler.CreateCompressedSerializedExecutionLog(fakeSession, collectRequest); var collectResult = JsonConvert.DeserializeObject <IEnumerable <ExecutionLog> >(serializedCollectLog.ToUncompressedString()); Assert.IsNotNull(serializedCollectLog); Assert.IsNotNull(collectResult); Assert.IsTrue(collectResult.Count() > 0); }
public void Should_be_possible_to_schedule_a_request_collect_in_specific_date() { var collectRequest = new CollectRequestFactory().CreateCollectRequest(DataProvider.GetSession()).Item2; var scheduleInformation = new ScheduleInformation() { ScheduleDate = DateTime.Now.AddSeconds(1) }; var scheduler = new StdSchedulerFactory().GetScheduler(); var scheduleController = new ScheduleController(scheduler) { TypeOfExecutionJob = typeof(TestJob) }; scheduleController.ScheduleCollection(collectRequest.Oid.ToString(), "", scheduleInformation.ScheduleDate); Assert.AreEqual(1, scheduleController.GetNumberOfCollectRequestScheduled()); scheduler.Shutdown(); }
public void Should_be_possible_to_evaluate_variables() { var session = GetSession(); string externalVariables = CreateOvalVariablesWithFakeValues(); var fakeCollectRequest = new CollectRequestFactory() .CreateCompleteCollectRequestAfterCollectWithSystemCharacteristics( session, string.Format(".definitions.{0}", FDCC_XPFIREWALL), ".system_characteristics.fdcc_xpfirewall_oval.sc.xml", CreateOvalVariablesWithFakeValues()); session.SaveChanges(); var evaluatedVariables = new VariableEvaluatorService().Evaluate(fakeCollectRequest, session); Assert.IsNotNull(evaluatedVariables); Assert.AreEqual(23, evaluatedVariables.GetQuantityOfVariables()); Assert.AreEqual("50001", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50001").Single().values.Single()); Assert.AreEqual("50031", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50031").Single().values.Single()); Assert.AreEqual("50041", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50041").Single().values.Single()); Assert.AreEqual("50051", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50051").Single().values.Single()); Assert.AreEqual("50071", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50071").Single().values.Single()); Assert.AreEqual("50081", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50081").Single().values.Single()); Assert.AreEqual("50091", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50091").Single().values.Single()); Assert.AreEqual("50111", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50111").Single().values.Single()); Assert.AreEqual("50131", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50131").Single().values.Single()); Assert.AreEqual("50141", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50141").Single().values.Single()); Assert.AreEqual("50151", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50151").Single().values.Single()); Assert.AreEqual("50161", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50161").Single().values.Single()); Assert.AreEqual("50171", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:50171").Single().values.Single()); Assert.AreEqual("51001", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51001").Single().values.Single()); Assert.AreEqual("51011", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51011").Single().values.Single()); Assert.AreEqual("51031", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51031").Single().values.Single()); Assert.AreEqual("51041", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51041").Single().values.Single()); Assert.AreEqual("51051", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51051").Single().values.Single()); Assert.AreEqual("51071", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51071").Single().values.Single()); Assert.AreEqual("51081", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51081").Single().values.Single()); Assert.AreEqual("51091", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51091").Single().values.Single()); Assert.AreEqual("51111", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51111").Single().values.Single()); Assert.AreEqual("51131", evaluatedVariables.GetVariableValueForVariableId("oval:gov.nist.fdcc.xpfirewall:var:51131").Single().values.Single()); }
public void Should_not_possible_schedule_the_collectRequest_if_already_exists_a_job_defined() { var scheduleInformation = new ScheduleInformation() { ScheduleDate = DateTime.Now.AddSeconds(1) }; var collectRequest = new CollectRequestFactory().CreateCollectRequest(DataProvider.GetSession()).Item2; this.SaveCollectRequest(collectRequest); var scheduler = new StdSchedulerFactory().GetScheduler(); var scheduleController = new ScheduleController(scheduler) { TypeOfExecutionJob = typeof(TestJob) }; var collectRequestId = collectRequest.Oid.ToString(); scheduleController.ScheduleCollection(collectRequestId, "", scheduleInformation.ScheduleDate); scheduleController.ScheduleCollection(collectRequestId, "", scheduleInformation.ScheduleDate); Assert.AreEqual(1, scheduleController.GetNumberOfCollectRequestScheduled()); scheduler.Shutdown(); }
public void Should_be_possible_get_the_collectRequestIds_that_are_executing_in_the_scheduler() { var collectRequest = new CollectRequestFactory().CreateCollectRequest(DataProvider.GetSession()).Item2; var scheduleInformation = new ScheduleInformation() { ScheduleDate = DateTime.Now.AddSeconds(1) }; this.SaveCollectRequest(collectRequest); var scheduler = new StdSchedulerFactory().GetScheduler(); var scheduleController = new ScheduleController(scheduler) { TypeOfExecutionJob = typeof(TestJob) }; scheduleController.ScheduleCollection(collectRequest.Oid.ToString(), "", scheduleInformation.ScheduleDate); Thread.Sleep(1000); var collectRequestIds = scheduleController.GetCollectRequestIdRunning(); Assert.IsTrue(collectRequestIds.Count() > 0); scheduler.Shutdown(); }