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");
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        public void Should_be_possible_to_get_a_complete_log_of_collect()
        {
            IDocumentSession fakeSession    = this.GetSession();
            CollectRequest   collectRequest = new CollectRequestFactory().CreateCollectRequestIncompleteAfterCollect(fakeSession);
            IEnumerable <CollectExecutionLog> completeLog = collectRequest.GetExecutionLog(fakeSession);

            Assert.IsTrue(completeLog.Count() > 0, "the quantity of executionLogs is not expected");
        }
Exemplo n.º 4
0
        public void should_not_return_a_null_list_of_variables_if_the_CollectRequest_not_have_variables_defined()
        {
            IDocumentSession           fakeSession    = this.GetSession();
            CollectRequest             collectRequest = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "definitionsSimple.xml");
            IEnumerable <VariableType> ovalVariables  = collectRequest.GetOvalVariables(fakeSession);

            Assert.IsNotNull(ovalVariables);
            Assert.IsTrue(ovalVariables.Count() == 0, "the oval object is not empty");
        }
Exemplo n.º 5
0
        public void Should_not_be_possible_to_close_an_request_collect_if_not_collected_all_objects_of_the_definitions()
        {
            IDocumentSession fakeSession    = this.GetSession();
            CollectRequest   collectRequest = new CollectRequestFactory().CreateCollectRequestIncompleteAfterCollect(fakeSession);

            Assert.AreEqual(true, collectRequest.isOpen(), "the initial state of collectRequest is not expected.");
            collectRequest.TryClose(fakeSession);
            Assert.AreEqual(true, collectRequest.isOpen(), "the state of collectRequest is no expected");
        }
Exemplo n.º 6
0
        public void Should_be_possible_to_create_a_collectResult_given_a_set_of_CollectExecutions()
        {
            CollectResultFactory factory = new CollectResultFactory();

            CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(provider.GetSession());

            //CollectResult collectResult = factory.CreateCollectResultFromOvalSystemCharacteristics(collectRequest.GetExecutedSystemCharacteristics());

            //Assert.IsNotNull(collectResult);
        }
Exemplo n.º 7
0
        public void Should_be_possible_to_get_objectTypes_from_a_collectRequest()
        {
            IDocumentSession         fakeSession    = this.GetSession();
            CollectRequest           collectRequest = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            IEnumerable <ObjectType> ovalObjects    = collectRequest.GetObjectTypes(fakeSession);

            Assert.IsNotNull(ovalObjects);
            Assert.IsTrue(ovalObjects.Count() > 0, "the oval object is empty");
            Assert.IsTrue(ovalObjects.Count() == 47, "the oval object count is not expected");
        }
Exemplo n.º 8
0
        public void Should_be_possible_to_get_variables_from_a_collectRequest()
        {
            IDocumentSession           fakeSession    = this.GetSession();
            CollectRequest             collectRequest = new CollectRequestFactory().CreateCollectRequestWithDefinitionsWithVariables(fakeSession);
            IEnumerable <VariableType> ovalVariables  = collectRequest.GetOvalVariables(fakeSession);

            Assert.IsNotNull(ovalVariables);
            Assert.IsTrue(ovalVariables.Count() > 0, "the oval object is empty");
            Assert.IsTrue(ovalVariables.Count() == 3, "the oval object count is not expected");
        }
        public void Should_be_possible_to_get_a_collectRequest_By_Id()
        {
            IDocumentSession fakeSession = this.GetSession();
            var collectRequest = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            fakeSession.SaveChanges();

            var repository = new CollectRequestRepository(dataprovider);
            var loadedRequest = repository.GetCollectRequest(fakeSession, collectRequest.Oid);
            Assert.IsNotNull(loadedRequest);
            Assert.AreEqual(collectRequest.Oid, loadedRequest.Oid);
        }
Exemplo n.º 10
0
        public void Should_be_possible_to_initialize_a_new_Collect_Execution()
        {
            var            session        = provider.GetSession();
            CollectFactory collectFactory = new CollectFactory(session);
            //ProbeResult probeResult = probeResultFactory.CreateProbeResultForRegostryCollectWithError();
            var request = new CollectRequestFactory().CreateCollectRequest(session).Item2;

            var execution = collectFactory.CreateCollectExecution(session, request);

            Assert.IsNotNull(execution);
        }
Exemplo n.º 11
0
        public void Should_be_possible_to_get_all_StateType_that_have_references_for_variableId_informed()
        {
            IDocumentSession        fakeSession          = this.GetSession();
            CollectRequest          collectRequest       = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "definitionsWithLocalVariable.xml");
            IEnumerable <StateType> stateTypeOfVariables = collectRequest.GetStateTypeByVariableId(fakeSession, "oval:org.mitre.oval:var:5000");

            Assert.IsTrue(stateTypeOfVariables.Count() == 1, "the quantity of objectTypes is not Expected");

            stateTypeOfVariables = collectRequest.GetStateTypeByVariableId(fakeSession, "oval:org.mitre.oval:var:5001");
            Assert.IsTrue(stateTypeOfVariables.Count() == 0, "the quantity of objectTypes is not Expected");
        }
Exemplo n.º 12
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();
 }
Exemplo n.º 13
0
        public void Should_not_load_the_objectTypes_if_the_objectType_attribute_was_already_set()
        {
            IDocumentSession         fakeSession    = this.GetSession();
            CollectRequest           collectRequest = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            IEnumerable <ObjectType> ovalObjects    = collectRequest.GetObjectTypes(fakeSession);

            Assert.IsNotNull(ovalObjects);

            IEnumerable <ObjectType> sameObjectTypes = collectRequest.GetObjectTypes(fakeSession);

            Assert.AreSame(sameObjectTypes, ovalObjects, "the objectTypes were loaded again");
        }
Exemplo n.º 14
0
        public void Should_be_possible_to_get_all_system_characteristcs_objects_of_collectRequest()
        {
            var            session        = GetSession();
            CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(session);

            session.SaveChanges();
            IEnumerable <Modulo.Collect.OVAL.SystemCharacteristics.oval_system_characteristics> systemCharacteristics
                = collectRequest.GetExecutedSystemCharacteristics(session);

            Assert.IsNotNull(systemCharacteristics, "the system characteristics is null");
            Assert.AreEqual(1, systemCharacteristics.Count());
        }
Exemplo n.º 15
0
        public void Should_not_load_the_variables_if_the_variable_attribute_was_already_set()
        {
            IDocumentSession           fakeSession    = this.GetSession();
            CollectRequest             collectRequest = new CollectRequestFactory().CreateCollectRequestWithDefinitionsWithVariables(fakeSession);
            IEnumerable <VariableType> ovalVariables  = collectRequest.GetOvalVariables(fakeSession);

            Assert.IsNotNull(ovalVariables);

            IEnumerable <VariableType> variables = collectRequest.GetOvalVariables(fakeSession);

            Assert.AreSame(variables, ovalVariables, "the variables were loaded again");
        }
Exemplo n.º 16
0
        public void Should_be_possible_to_get_the_states_of_a_collectRequest()
        {
            IDocumentSession        fakeSession    = this.GetSession();
            CollectRequest          collectRequest = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "definitionsWithLocalVariable.xml");
            IEnumerable <StateType> states         = collectRequest.GetStates(fakeSession);

            Assert.IsNotNull(states);
            Assert.AreEqual(5, states.Count(), "the quantity of objects is not expected");
            StateType state = states.Where(obj => obj.id == "oval:org.mitre.oval:ste:3794").SingleOrDefault();

            Assert.IsNotNull(state);
        }
Exemplo n.º 17
0
        public void Should_not_load_the_states_if_the_state_attribute_was_already_set()
        {
            IDocumentSession        fakeSession    = this.GetSession();
            CollectRequest          collectRequest = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "definitionsWithLocalVariable.xml");
            IEnumerable <StateType> states         = collectRequest.GetStates(fakeSession);

            Assert.IsNotNull(states);
            Assert.AreEqual(5, states.Count(), "the quantity of objects is not expected");
            IEnumerable <StateType> sameState = collectRequest.GetStates(fakeSession);

            Assert.AreSame(sameState, states, "the states were loaded again");
        }
Exemplo n.º 18
0
        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");
        }
Exemplo n.º 19
0
        public void Should_be_possible_to_get_a_collectRequest_By_Id()
        {
            IDocumentSession fakeSession = this.GetSession();
            var collectRequest           = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;

            fakeSession.SaveChanges();

            var repository    = new CollectRequestRepository(dataprovider);
            var loadedRequest = repository.GetCollectRequest(fakeSession, collectRequest.Oid);

            Assert.IsNotNull(loadedRequest);
            Assert.AreEqual(collectRequest.Oid, loadedRequest.Oid);
        }
Exemplo n.º 20
0
        public void Should_be_possible_to_get_collectRequests_By_Ids()
        {
            IDocumentSession fakeSession = this.GetSession();
            var collectRequest1 = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            var collectRequest2 = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            fakeSession.SaveChanges();

            var repository = new CollectRequestRepository(dataprovider);
            var loadedRequests = repository.GetCollectRequests(fakeSession, collectRequest1.Oid, collectRequest2.Oid);
            Assert.IsNotNull(loadedRequests);
            Assert.AreEqual(2, loadedRequests.Count());
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest1.Oid));
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest2.Oid));
        }
Exemplo n.º 21
0
        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();
        }
Exemplo n.º 22
0
        public void When_the_list_of_ids_contains_repeated_items_GetCollectRequests_should_not_return_repeated_collect_requests()
        {
            IDocumentSession fakeSession = this.GetSession();
            var collectRequest1          = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            var collectRequest2          = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;

            fakeSession.SaveChanges();

            var repository     = new CollectRequestRepository(dataprovider);
            var loadedRequests = repository.GetCollectRequests(fakeSession, collectRequest1.Oid, collectRequest1.Oid, collectRequest2.Oid);

            Assert.IsNotNull(loadedRequests);
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest1.Oid), MORE_THAN_ONE_COLLECT_REQUEST_WAS_FOUND, collectRequest1.Oid);
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest2.Oid), MORE_THAN_ONE_COLLECT_REQUEST_WAS_FOUND, collectRequest2.Oid);
            Assert.AreEqual(2, loadedRequests.Count());
        }
Exemplo n.º 23
0
        public void Should_be_possible_to_get_collectRequests_By_Ids()
        {
            IDocumentSession fakeSession = this.GetSession();
            var collectRequest1          = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            var collectRequest2          = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;

            fakeSession.SaveChanges();

            var repository     = new CollectRequestRepository(dataprovider);
            var loadedRequests = repository.GetCollectRequests(fakeSession, collectRequest1.Oid, collectRequest2.Oid);

            Assert.IsNotNull(loadedRequests);
            Assert.AreEqual(2, loadedRequests.Count());
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest1.Oid));
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest2.Oid));
        }
Exemplo n.º 24
0
        public void Should_be_possible_to_get_the_objects_that_still_was_not_collected()
        {
            IDocumentSession fakeSession    = this.GetSession();
            CollectRequest   collectRequest = new CollectRequestFactory().CreateCollectRequestIncompleteAfterCollect(fakeSession);

            fakeSession.SaveChanges();
            IEnumerable <ObjectType> objectTypes = collectRequest.GetObjectTypesWasNotCollected(fakeSession);

            Assert.AreEqual(2, objectTypes.Count(), "the quantity of objects is not expected");

            ObjectType objectType = objectTypes.Where <ObjectType>(obj => obj.id == "oval:gov.nist.fdcc.xpfirewall:obj:50111").SingleOrDefault();

            Assert.IsNotNull(objectType, "the object is not expected");
            objectType = objectTypes.Where <ObjectType>(obj => obj.id == "oval:gov.nist.fdcc.xpfirewall:obj:51062").SingleOrDefault();
            Assert.IsNotNull(objectType, "the object is not expected");
        }
Exemplo n.º 25
0
        public void Should_be_possible_to_check_that_all_object_types_is_being_referenced_by_variable()
        {
            var fakeSession    = this.GetSession();
            var collectRequest = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "public.microsoft.windows.xp_only_objects.xml");

            foreach (var @object in collectRequest.GetObjectTypes(fakeSession))
            {
                try
                {
                    @object.HasReferenceForVariable("");
                }
                catch (Exception ex)
                {
                    Assert.Fail("It was not possible to evaluate {0} type. Error: {1}({2})", @object.ComponentString, ex.Message, ex.GetType().FullName);
                }
            }
        }
Exemplo n.º 26
0
        public void Should_be_possible_to_get_All_Open_CollectRequests()
        {
            IDocumentSession fakeSession = this.GetSession();
            var collectRequest1 = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            collectRequest1.Status = CollectRequestStatus.Open;
            var collectRequest2 = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            collectRequest2.Status = CollectRequestStatus.Open;
            var collectRequest3 = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            collectRequest3.Status = CollectRequestStatus.Close;
            fakeSession.SaveChanges();

            var repository = new CollectRequestRepository(dataprovider);
            var loadedRequests = repository.GetOpenCollectRequests(fakeSession).ToList();
            Assert.IsNotNull(loadedRequests);
            Assert.AreEqual(2, loadedRequests.Count());
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest1.Oid));
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest2.Oid));
        }
Exemplo n.º 27
0
        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());
        }
Exemplo n.º 28
0
        public void Should_be_possible_to_get_a_number_of_times_that_was_executed_the_collectRequest()
        {
            CollectRequestFactory factory        = new CollectRequestFactory();
            IDocumentSession      fakeSession    = this.GetSession();
            CollectRequest        collectRequest = factory.CreateCollectRequest(fakeSession).Item2;

            Assert.IsTrue(collectRequest.GetNumberOfExecutions(fakeSession) == 0, "this request collect still not executed");

            //add two executions
            CollectExecution firstExecution = factory.CreateCollect(fakeSession);

            firstExecution.RequestId = collectRequest.Oid;
            firstExecution.ProbeExecutions.Add(factory.CreateProbeExecution(fakeSession, "registry"));
            firstExecution.ProbeExecutions.Add(factory.CreateProbeExecution(fakeSession, "family"));

            CollectExecution secondExecution = factory.CreateCollect(fakeSession);

            secondExecution.RequestId = collectRequest.Oid;
            secondExecution.ProbeExecutions.Add(factory.CreateProbeExecution(fakeSession, "registry"));
            fakeSession.SaveChanges();
            Assert.AreEqual(2, collectRequest.GetNumberOfExecutions(fakeSession));
        }
Exemplo n.º 29
0
        public void Should_be_possible_to_get_All_Open_CollectRequests()
        {
            IDocumentSession fakeSession = this.GetSession();
            var collectRequest1          = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;

            collectRequest1.Status = CollectRequestStatus.Open;
            var collectRequest2 = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;

            collectRequest2.Status = CollectRequestStatus.Open;
            var collectRequest3 = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;

            collectRequest3.Status = CollectRequestStatus.Close;
            fakeSession.SaveChanges();

            var repository     = new CollectRequestRepository(dataprovider);
            var loadedRequests = repository.GetOpenCollectRequests(fakeSession).ToList();

            Assert.IsNotNull(loadedRequests);
            Assert.AreEqual(2, loadedRequests.Count());
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest1.Oid));
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest2.Oid));
        }
Exemplo n.º 30
0
        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");           
        }
Exemplo n.º 31
0
 public void Should_raise_an_exception_if_the_list_of_errors_of_the_schema_validation_is_not_empty()
 {
     IDocumentSession         fakeSession    = this.GetSession();
     CollectRequest           collectRequest = new CollectRequestFactory().CreateCollectRequestWithInvalidSchemaDefinitions(fakeSession);
     IEnumerable <ObjectType> ovalObjects    = collectRequest.GetObjectTypes(fakeSession);
 }
Exemplo n.º 32
0
 public void Should_raise_an_exception_if_ovalDefinitions_xml_schema_is_invalid()
 {
     IDocumentSession         fakeSession    = this.GetSession();
     CollectRequest           collectRequest = new CollectRequestFactory().CreateCollectRequestWithInvalidDefinitions(fakeSession);
     IEnumerable <ObjectType> ovalObjects    = collectRequest.GetObjectTypes(fakeSession);
 }
Exemplo n.º 33
0
 public void Should_be_possible_to_check_that_all_object_types_is_being_referenced_by_variable()
 {
     var fakeSession = this.GetSession();
     var collectRequest = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "public.microsoft.windows.xp_only_objects.xml");
     foreach (var @object in collectRequest.GetObjectTypes(fakeSession))
     {
         try
         {
             @object.HasReferenceForVariable("");
         }
         catch (Exception ex)
         {
             Assert.Fail("It was not possible to evaluate {0} type. Error: {1}({2})", @object.ComponentString, ex.Message, ex.GetType().FullName);
         }
     }
 }
Exemplo n.º 34
0
 public void Should_raise_an_exception_if_the_list_of_errors_of_the_schema_validation_is_not_empty()
 {
     IDocumentSession fakeSession = this.GetSession();
     CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestWithInvalidSchemaDefinitions(fakeSession);
     IEnumerable<ObjectType> ovalObjects = collectRequest.GetObjectTypes(fakeSession);        
 }
Exemplo n.º 35
0
        public void Should_not_load_the_objectTypes_if_the_objectType_attribute_was_already_set()
        {
            IDocumentSession fakeSession = this.GetSession();
            CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            IEnumerable<ObjectType> ovalObjects = collectRequest.GetObjectTypes(fakeSession); 
            Assert.IsNotNull(ovalObjects);

            IEnumerable<ObjectType> sameObjectTypes = collectRequest.GetObjectTypes(fakeSession);
            Assert.AreSame(sameObjectTypes,ovalObjects, "the objectTypes were loaded again");
            
        }
Exemplo n.º 36
0
        public void Should_be_possible_to_initialize_a_new_Collect_Execution()
        {
            var session = provider.GetSession();
            CollectFactory collectFactory = new CollectFactory(session);
            //ProbeResult probeResult = probeResultFactory.CreateProbeResultForRegostryCollectWithError();
            var request = new CollectRequestFactory().CreateCollectRequest(session).Item2;

            var execution = collectFactory.CreateCollectExecution(session, request);
            Assert.IsNotNull(execution);
            
        }
Exemplo n.º 37
0
 public void Should_not_load_the_states_if_the_state_attribute_was_already_set()
 {
     IDocumentSession fakeSession = this.GetSession();
     CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "definitionsWithLocalVariable.xml"); 
     IEnumerable<StateType> states = collectRequest.GetStates(fakeSession);
     Assert.IsNotNull(states);
     Assert.AreEqual(5, states.Count(), "the quantity of objects is not expected" );
     IEnumerable<StateType> sameState = collectRequest.GetStates(fakeSession);
     Assert.AreSame(sameState, states, "the states were loaded again");
 }
Exemplo n.º 38
0
 public void Should_be_possible_to_get_variables_from_a_collectRequest()
 {
     IDocumentSession fakeSession = this.GetSession();
     CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestWithDefinitionsWithVariables(fakeSession);
     IEnumerable<VariableType> ovalVariables = collectRequest.GetOvalVariables(fakeSession);
     Assert.IsNotNull(ovalVariables);
     Assert.IsTrue(ovalVariables.Count() > 0, "the oval object is empty");
     Assert.IsTrue(ovalVariables.Count() == 3, "the oval object count is not expected");
 }
Exemplo n.º 39
0
        public void Should_not_load_the_variables_if_the_variable_attribute_was_already_set()
        {
            IDocumentSession fakeSession = this.GetSession();
            CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestWithDefinitionsWithVariables(fakeSession);
            IEnumerable<VariableType> ovalVariables = collectRequest.GetOvalVariables(fakeSession);
            Assert.IsNotNull(ovalVariables);

            IEnumerable<VariableType> variables = collectRequest.GetOvalVariables(fakeSession);
            Assert.AreSame(variables, ovalVariables, "the variables were loaded again");
        }
Exemplo n.º 40
0
        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);
        }
Exemplo n.º 41
0
        public void Should_be_possible_to_get_a_number_of_times_that_was_executed_the_collectRequest()
        {
            CollectRequestFactory factory = new CollectRequestFactory();
            IDocumentSession fakeSession = this.GetSession();
            CollectRequest collectRequest = factory.CreateCollectRequest(fakeSession).Item2;
            Assert.IsTrue(collectRequest.GetNumberOfExecutions(fakeSession) == 0, "this request collect still not executed");

            //add two executions 
            CollectExecution firstExecution = factory.CreateCollect(fakeSession);
            firstExecution.RequestId = collectRequest.Oid;
            firstExecution.ProbeExecutions.Add(factory.CreateProbeExecution(fakeSession, "registry" ));
            firstExecution.ProbeExecutions.Add(factory.CreateProbeExecution(fakeSession, "family"));

            CollectExecution secondExecution = factory.CreateCollect(fakeSession);
            secondExecution.RequestId = collectRequest.Oid;
            secondExecution.ProbeExecutions.Add(factory.CreateProbeExecution(fakeSession, "registry"));
            fakeSession.SaveChanges();
            Assert.AreEqual(2, collectRequest.GetNumberOfExecutions(fakeSession));
        }
Exemplo n.º 42
0
        public void Should_be_possible_to_get_the_objects_that_still_was_not_collected()
        {
            IDocumentSession fakeSession = this.GetSession();
            CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestIncompleteAfterCollect(fakeSession);
            fakeSession.SaveChanges();
            IEnumerable<ObjectType> objectTypes = collectRequest.GetObjectTypesWasNotCollected(fakeSession);
            Assert.AreEqual(2, objectTypes.Count(), "the quantity of objects is not expected");

            ObjectType objectType = objectTypes.Where<ObjectType>(obj => obj.id == "oval:gov.nist.fdcc.xpfirewall:obj:50111").SingleOrDefault();
            Assert.IsNotNull(objectType, "the object is not expected");
            objectType = objectTypes.Where<ObjectType>(obj => obj.id == "oval:gov.nist.fdcc.xpfirewall:obj:51062").SingleOrDefault();
            Assert.IsNotNull(objectType, "the object is not expected");
        }
Exemplo n.º 43
0
 public void Should_not_be_possible_to_close_an_request_collect_if_not_collected_all_objects_of_the_definitions()
 {
     IDocumentSession fakeSession = this.GetSession();
     CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestIncompleteAfterCollect(fakeSession);
     Assert.AreEqual(true,collectRequest.isOpen(),"the initial state of collectRequest is not expected.");
     collectRequest.TryClose(fakeSession);
     Assert.AreEqual(true, collectRequest.isOpen(), "the state of collectRequest is no expected");
 }
Exemplo n.º 44
0
 public void Should_raise_an_exception_if_ovalDefinitions_xml_schema_is_invalid()
 {
     IDocumentSession fakeSession = this.GetSession();
     CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestWithInvalidDefinitions(fakeSession);
     IEnumerable<ObjectType> ovalObjects = collectRequest.GetObjectTypes(fakeSession);
 }
Exemplo n.º 45
0
 public void Should_be_possible_to_get_the_states_of_a_collectRequest()
 {
     IDocumentSession fakeSession = this.GetSession();
     CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "definitionsWithLocalVariable.xml"); 
     IEnumerable<StateType> states = collectRequest.GetStates(fakeSession);
     Assert.IsNotNull(states);
     Assert.AreEqual(5, states.Count(), "the quantity of objects is not expected" );
     StateType state = states.Where(obj => obj.id == "oval:org.mitre.oval:ste:3794").SingleOrDefault();
     Assert.IsNotNull(state);
 }
Exemplo n.º 46
0
        public void When_the_list_of_ids_contains_repeated_items_GetCollectRequests_should_not_return_repeated_collect_requests()
        {
            IDocumentSession fakeSession = this.GetSession();
            var collectRequest1 = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            var collectRequest2 = new CollectRequestFactory().CreateCollectRequest(fakeSession).Item2;
            fakeSession.SaveChanges();

            var repository = new CollectRequestRepository(dataprovider);
            var loadedRequests = repository.GetCollectRequests(fakeSession, collectRequest1.Oid, collectRequest1.Oid, collectRequest2.Oid);
            Assert.IsNotNull(loadedRequests);
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest1.Oid), MORE_THAN_ONE_COLLECT_REQUEST_WAS_FOUND, collectRequest1.Oid);
            Assert.AreEqual(1, loadedRequests.Count(x => x.Oid == collectRequest2.Oid), MORE_THAN_ONE_COLLECT_REQUEST_WAS_FOUND, collectRequest2.Oid);
            Assert.AreEqual(2, loadedRequests.Count());
        }
Exemplo n.º 47
0
        public void Should_be_possible_to_get_all_system_characteristcs_objects_of_collectRequest()
        {
            var session = GetSession();
            CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(session);
            session.SaveChanges();
            IEnumerable<Modulo.Collect.OVAL.SystemCharacteristics.oval_system_characteristics> systemCharacteristics 
                = collectRequest.GetExecutedSystemCharacteristics(session);

            Assert.IsNotNull(systemCharacteristics, "the system characteristics is null");
            Assert.AreEqual(1, systemCharacteristics.Count());

        }
Exemplo n.º 48
0
 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);
 }
Exemplo n.º 49
0
 public void should_not_return_a_null_list_of_variables_if_the_CollectRequest_not_have_variables_defined()
 {
     IDocumentSession fakeSession = this.GetSession();
     CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "definitionsSimple.xml");
     IEnumerable<VariableType> ovalVariables = collectRequest.GetOvalVariables(fakeSession);
     Assert.IsNotNull(ovalVariables);
     Assert.IsTrue(ovalVariables.Count() == 0, "the oval object is not empty");            
 }            
Exemplo n.º 50
0
        public void Should_be_possible_to_get_all_StateType_that_have_references_for_variableId_informed()
        {
            IDocumentSession fakeSession = this.GetSession();
            CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestWithSpecificDefinitions(fakeSession, "definitionsWithLocalVariable.xml");
            IEnumerable<StateType> stateTypeOfVariables = collectRequest.GetStateTypeByVariableId(fakeSession, "oval:org.mitre.oval:var:5000");
            Assert.IsTrue(stateTypeOfVariables.Count() == 1, "the quantity of objectTypes is not Expected");

            stateTypeOfVariables = collectRequest.GetStateTypeByVariableId(fakeSession, "oval:org.mitre.oval:var:5001");
            Assert.IsTrue(stateTypeOfVariables.Count() == 0, "the quantity of objectTypes is not Expected");
        }
Exemplo n.º 51
0
        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();
        }
Exemplo n.º 52
0
        public void Should_be_possible_to_create_a_collectResult_given_a_set_of_CollectExecutions()
        {
            CollectResultFactory factory = new CollectResultFactory();

            CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestCompleteAfterCollect(provider.GetSession());

            //CollectResult collectResult = factory.CreateCollectResultFromOvalSystemCharacteristics(collectRequest.GetExecutedSystemCharacteristics());

            //Assert.IsNotNull(collectResult);
        }
Exemplo n.º 53
0
 public void Should_be_possible_to_get_a_complete_log_of_collect()
 {
     IDocumentSession fakeSession = this.GetSession();
     CollectRequest collectRequest = new CollectRequestFactory().CreateCollectRequestIncompleteAfterCollect(fakeSession);
     IEnumerable<CollectExecutionLog> completeLog = collectRequest.GetExecutionLog(fakeSession);
     Assert.IsTrue(completeLog.Count() > 0, "the quantity of executionLogs is not expected");
 }