Ejemplo n.º 1
0
 public TargetPlatformDiscovererTests()
 {
     var ovalDocLoader = new OvalDocumentLoader();
     this.WindowsOvalDefinitionsSample = ovalDocLoader.GetFakeOvalDefinitions("fdcc_xpfirewall_oval.xml");
     this.UnixOvalDefinitionsSample = ovalDocLoader.GetFakeOvalDefinitions("RM7-scap-sol10-oval.xml");
     this.IndependentOvalDefinitionsSample = ovalDocLoader.GetFakeOvalDefinitions("definitions_all_independent.xml");
     this.CiscoIosOvalDefinitionsSample = ovalDocLoader.GetFakeOvalDefinitions("modulo-ios122-oval.xml");
 }
        public void Should_be_possible_to_validate_a_valid_OvalDefinitions()
        {
            var validOvalDefinitionsXml = new OvalDocumentLoader().GetFakeOvalDefinitions("oval.org.mitre.oval.def.5368.xml").GetDefinitionsXml();
            
            var ovalDefinitionsValidator = new OvalDefinitionsValidator(validOvalDefinitionsXml);

            Assert.IsNotNull(ovalDefinitionsValidator.Schema, "The Oval Definitions validation result cannot be null.");
            Assert.IsTrue(ovalDefinitionsValidator.Schema.IsValid, "The Oval Definitions Schema validation result must be TRUE.");
        }
        public void Should_be_possible_to_validate_an_OvalDefinitions_with_valid_schematron()
        {
            var validOvalDefinitionsXml = new OvalDocumentLoader().GetFakeOvalDefinitions("oval.org.mitre.oval.def.5368.xml").GetDefinitionsXml();
            var validator = new OvalDefinitionsValidator(validOvalDefinitionsXml);
            ValidationResultShouldBeValidFor(validator.Schema);

            var schematronValidationResult = validator.ValidateSchematron();

            ValidationResultShouldBeValidFor(schematronValidationResult);
        }
Ejemplo n.º 4
0
        public string GetExternalVariableWithDefaultValueFrom(string  definitionsName)

        {
            var definitions = new OvalDocumentLoader().GetFakeOvalDefinitions(definitionsName);

            var externalVariables = new Variables.oval_variables();
            externalVariables.generator = Modulo.Collect.OVAL.Common.DocumentHelpers.GetDefaultGenerator();
            externalVariables.variables = new List<Variables.VariableType>();

            if (definitions.variables != null)
            {
                foreach (var variable in definitions.variables)
                {
                    string defaultValue = string.Empty;
                    externalVariables.variables.Add(new Variables.VariableType(variable.datatype, variable.id, defaultValue));
                }
            }

            return externalVariables.GetXmlDocument();
        }
        private string GetOvalDefinitionsXml(string resourceFolder, string resouceName)
        {
            var resourcePath = String.Format("{0}.{1}", resourceFolder, resouceName);
            try
            {
                var ovalDefinitionsAsStream = new OvalDocumentLoader().GetStreamFrom(resourcePath);
                if (ovalDefinitionsAsStream == null)
                    Assert.Fail("A resource with name '{0}' could not be found.", resourcePath);

                var ovalDefinitionsAsXml = new StreamReader(ovalDefinitionsAsStream).ReadToEnd();
                Assert.IsNotNull(ovalDefinitionsAsXml, "Could not possible to get Oval Definitions Document from stream.");
                Assert.IsTrue(ovalDefinitionsAsXml.Contains("<oval_definitions "), "The document is not an Oval Definitions file. Missing <oval_definitions> begin tag.");
                Assert.IsTrue(ovalDefinitionsAsXml.Contains("</oval_definitions>"), "The document is not an Oval Definitions file. Missing </oval_definitions> closing tag.");

                return ovalDefinitionsAsXml;
            }
            catch (Exception ex)
            {
                Assert.Fail("An error occurred while trying to load resource '{0}': '{1}'.", resourcePath, ex.Message);
                return null;
            }
        }
Ejemplo n.º 6
0
        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);
        }
        private string CreateOvalVariablesWithFakeValues()
        {
            var ovalDefinitions = new OvalDocumentLoader().GetFakeOvalDefinitions(FDCC_XPFIREWALL);
            var externalVariables = ovalDefinitions.variables.OfType<VariablesTypeVariableExternal_variable>();

            var externalVariablesWithFakeValue = new oval_variables();
            foreach(var declaredExternalVariable in externalVariables)
            {
                var newFakeVariable = CreateVariableType(declaredExternalVariable);
                externalVariablesWithFakeValue.variables.Add(newFakeVariable);
            }

            return externalVariablesWithFakeValue.GetXmlDocument();
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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());
        }