def test_namespace_registration(): Model.register_namespace('scap.model.derp', 'http://jaymes.biz/derp') Model.xmlns_to_package('http://jaymes.biz/derp') == 'scap.model.derp' Model.unregister_namespace('scap.model.derp') with pytest.raises(UnregisteredNamespaceException): Model.xmlns_to_package('http://jaymes.biz/derp')
# PySCAP is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # PySCAP is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with PySCAP. If not, see <http://www.gnu.org/licenses/>. from scap.Model import Model Model.register_namespace('scap.model.ai_1_1', 'http://scap.nist.gov/schema/asset-identification/1.1') Model.register_namespace('scap.model.arf_1_1', 'http://scap.nist.gov/schema/asset-reporting-format/1.1') Model.register_namespace('scap.model.arf_rel_1_0', 'http://scap.nist.gov/specifications/arf/vocabulary/relationships/1.0') Model.register_namespace('scap.model.cpe_1_0', 'http://cpe.mitre.org/XMLSchema/cpe/1.0') Model.register_namespace('scap.model.cpe_dict_2_3', 'http://cpe.mitre.org/dictionary/2.0') Model.register_namespace('scap.model.cpe_lang_2_3', 'http://cpe.mitre.org/language/2.0') Model.register_namespace('scap.model.cpe_naming_2_3', 'http://cpe.mitre.org/naming/2.0') Model.register_namespace('scap.model.dc_elements_1_1', 'http://purl.org/dc/elements/1.1/') Model.register_namespace('scap.model.tmsad_1_0', 'http://scap.nist.gov/schema/xml-dsig/1.0') Model.register_namespace('scap.model.ocil_2_0', 'http://scap.nist.gov/schema/ocil/2.0') Model.register_namespace('scap.model.ocil_2_0', 'http://scap.nist.gov/schema/ocil/2') Model.register_namespace('scap.model.oval_5', 'http://oval.mitre.org/XMLSchema/oval-common-5') Model.register_namespace('scap.model.oval_5.defs', 'http://oval.mitre.org/XMLSchema/oval-definitions-5') Model.register_namespace('scap.model.oval_5.defs.independent', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#independent') Model.register_namespace('scap.model.oval_5.defs.linux', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#linux') Model.register_namespace('scap.model.oval_5.defs.windows', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#windows')
import pytest import pkgutil import xml.etree.ElementTree as ET from scap.Model import Model # import all the classes in the package import scap.model.oval_5.defs.windows as pkg for m_finder, m_name, m_ispkg in pkgutil.iter_modules(path=pkg.__path__): try: mod = importlib.import_module(pkg.__name__ + '.' + m_name, pkg.__name__) globals()[m_name] = getattr(mod, m_name) except AttributeError: pass Model.register_namespace('scap.model.oval_5', 'http://oval.mitre.org/XMLSchema/oval-common-5') Model.register_namespace('scap.model.oval_5.defs', 'http://oval.mitre.org/XMLSchema/oval-definitions-5') Model.register_namespace('scap.model.oval_5.defs.independent', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#independent') Model.register_namespace('scap.model.oval_5.defs.linux', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#linux') Model.register_namespace('scap.model.oval_5.defs.windows', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#windows') Model.register_namespace('scap.model.oval_5.defs.unix', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#unix') logging.basicConfig(level=logging.DEBUG) def test_EntityObjectCmdletVerbType_parse(): assert EntityObjectCmdletVerbType(value='Request').get_value() == 'Request' def test_EntityObjectGUIDType_parse(): assert EntityObjectGUIDType(value='{12345678-1234-1234-1234-1234567890ab}').get_value() == '{12345678-1234-1234-1234-1234567890ab}' def test_EntityObjectNamingContextType_parse():
import pkgutil import xml.etree.ElementTree as ET from scap.Model import Model from scap.model.oval_5.defs.SetElement import SetElement # import all the classes in the package import scap.model.oval_5 as pkg for m_finder, m_name, m_ispkg in pkgutil.iter_modules(path=pkg.__path__): try: mod = importlib.import_module(pkg.__name__ + '.' + m_name, pkg.__name__) globals()[m_name] = getattr(mod, m_name) except AttributeError: pass Model.register_namespace('scap.model.oval_5', 'http://oval.mitre.org/XMLSchema/oval-common-5') Model.register_namespace('scap.model.oval_5.defs', 'http://oval.mitre.org/XMLSchema/oval-definitions-5') Model.register_namespace('scap.model.oval_5.defs.independent', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#independent') Model.register_namespace('scap.model.oval_5.defs.linux', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#linux') Model.register_namespace('scap.model.oval_5.defs.windows', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#windows') logging.basicConfig(level=logging.DEBUG) def test_oval_5_3_detected(): test_xml = '<oval_definitions ' + \ 'xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" ' + \ 'xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" ' + \ 'xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5">' + \ '<generator>' + \ '<oval:product_name>The OVAL Repository</oval:product_name>' + \ '<oval:schema_version>5.3</oval:schema_version>' + \
# PySCAP is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with PySCAP. If not, see <http://www.gnu.org/licenses/>. import logging import pathlib import pytest import xml.etree.ElementTree as ET from scap.Model import Model import scap.model.xccdf_1_1 logging.basicConfig(level=logging.DEBUG) Model.register_namespace('scap.model.xccdf_1_1', 'http://checklists.nist.gov/xccdf/1.1') Model.register_namespace('scap.model.xhtml', 'http://www.w3.org/1999/xhtml') Model.register_namespace('scap.model.dc_elements_1_1', 'http://purl.org/dc/elements/1.1/') Model.register_namespace('scap.model.cpe_lang_2_3', 'http://cpe.mitre.org/language/2.0') def test_benchmark(): path = pathlib.Path(str(pytest.config.rootdir) ) / 'test' / 'scap' / 'model' / 'test_xccdf_1_1.xml' model = Model.load(None, ET.parse(str(path)).getroot())
try: mod = importlib.import_module(pkg.__name__ + '.' + m_name, pkg.__name__) globals()[m_name] = getattr(mod, m_name) except AttributeError: pass import scap.model.oval_5.sc.independent as pkg for m_finder, m_name, m_ispkg in pkgutil.iter_modules(path=pkg.__path__): try: mod = importlib.import_module(pkg.__name__ + '.' + m_name, pkg.__name__) globals()[m_name] = getattr(mod, m_name) except AttributeError: pass Model.register_namespace('scap.model.oval_5', 'http://oval.mitre.org/XMLSchema/oval-common-5') Model.register_namespace('scap.model.oval_5.defs', 'http://oval.mitre.org/XMLSchema/oval-definitions-5') Model.register_namespace( 'scap.model.oval_5.defs.independent', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#independent') Model.register_namespace( 'scap.model.oval_5.sc', 'http://oval.mitre.org/XMLSchema/oval-system-characteristics-5') Model.register_namespace( 'scap.model.oval_5.sc.independent', 'http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#independent' ) logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with PySCAP. If not, see <http://www.gnu.org/licenses/>. import logging import pytest import xml.etree.ElementTree as ET from scap.Model import Model import scap.model.xml_cat_1_1 from scap.model.xml_cat_1_1.Catalog import Catalog logging.basicConfig(level=logging.DEBUG) Model.register_namespace('scap.model.xml_cat_1_1', 'urn:oasis:names:tc:entity:xmlns:xml:catalog') cat1 = Model.load(None, ET.fromstring('''<xml_cat_1_1:catalog xmlns:xml_cat_1_1="urn:oasis:names:tc:entity:xmlns:xml:catalog"> <xml_cat_1_1:uri name="name1" uri="uri1"/> <xml_cat_1_1:uri name="name2" uri="uri2"/> <xml_cat_1_1:uri name="name3" uri="uri3"/> </xml_cat_1_1:catalog>''')) def test_parsed(): assert 'name1' in cat1.entries assert 'name2' in cat1.entries assert 'name2' in cat1.entries assert cat1.entries['name1'] == 'uri1' assert cat1.entries['name2'] == 'uri2' assert cat1.entries['name3'] == 'uri3' assert 'name4' not in cat1.entries
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with PySCAP. If not, see <http://www.gnu.org/licenses/>. import logging import pytest import xml.etree.ElementTree as ET from scap.Model import Model import scap.model.xml_cat_1_1 from scap.model.xml_cat_1_1.Catalog import Catalog logging.basicConfig(level=logging.DEBUG) Model.register_namespace('scap.model.xml_cat_1_1', 'urn:oasis:names:tc:entity:xmlns:xml:catalog') cat1 = Model.load( None, ET.fromstring( '''<xml_cat_1_1:catalog xmlns:xml_cat_1_1="urn:oasis:names:tc:entity:xmlns:xml:catalog"> <xml_cat_1_1:uri name="name1" uri="uri1"/> <xml_cat_1_1:uri name="name2" uri="uri2"/> <xml_cat_1_1:uri name="name3" uri="uri3"/> </xml_cat_1_1:catalog>''')) def test_parsed(): assert 'name1' in cat1.entries assert 'name2' in cat1.entries assert 'name2' in cat1.entries
import importlib import logging import pytest import pkgutil from scap.Model import Model # import all the classes in the package import scap.model.oval_5.defs.unix as pkg for m_finder, m_name, m_ispkg in pkgutil.iter_modules(path=pkg.__path__): try: mod = importlib.import_module(pkg.__name__ + '.' + m_name, pkg.__name__) globals()[m_name] = getattr(mod, m_name) except AttributeError: pass Model.register_namespace('scap.model.oval_5', 'http://oval.mitre.org/XMLSchema/oval-common-5') Model.register_namespace('scap.model.oval_5.defs', 'http://oval.mitre.org/XMLSchema/oval-definitions-5') Model.register_namespace( 'scap.model.oval_5.defs.unix', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#unix') logging.basicConfig(level=logging.DEBUG) def test_parse(): pass
# You should have received a copy of the GNU General Public License # along with PySCAP. If not, see <http://www.gnu.org/licenses/>. import logging import pathlib import pytest import xml.etree.ElementTree as ET from fixtures.test.RootFixture import RootFixture from fixtures.test.EnclosedFixture import EnclosedFixture from scap.Model import Model, ModelList from scap.Inventory import Inventory import scap.model.xlink logging.basicConfig(level=logging.DEBUG) Model.register_namespace('scap.model.xlink', 'http://www.w3.org/1999/xlink') def test_simple_local(): path = ( pathlib.Path(str(pytest.config.rootdir)) / 'tests' / 'model' / 'test_xlink.xml' ).as_posix() if not path.startswith('/'): path = '/' + path model = Model.load(None, ET.fromstring('<test:XLinkFixture ' + 'xmlns:test="http://jaymes.biz/test" ' + 'xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" ' + 'xlink:href="file://' + path + '" />')) assert isinstance(model._elements, ModelList) assert len(model._elements) > 0 assert isinstance(model._elements[0], RootFixture) assert isinstance(model._elements[0].EnclosedFixture, EnclosedFixture)
from fixtures.test.RootFixture import RootFixture from fixtures.test.EnclosedFixture import EnclosedFixture from fixtures.test.AttributeFixture import AttributeFixture from fixtures.test.RequiredAttributeFixture import RequiredAttributeFixture from fixtures.test.WildcardElementNotInFixture import WildcardElementNotInFixture from fixtures.test.WildcardElementInFixture import WildcardElementInFixture from fixtures.test.AppendElementFixture import AppendElementFixture from fixtures.test.MapElementFixture import MapElementFixture from fixtures.test.MappableElementFixture import MappableElementFixture from fixtures.test.InitFixture import InitFixture from fixtures.test.MinMaxElementFixture import MinMaxElementFixture from fixtures.test2.EnclosedFixture import EnclosedFixture as EnclosedFixture2 logging.basicConfig(level=logging.DEBUG) Model.register_namespace('fixtures.test', 'http://jaymes.biz/test') Model.register_namespace('fixtures.test2', 'http://jaymes.biz/test2') def test_namespace_registration(): Model.register_namespace('scap.model.derp', 'http://jaymes.biz/derp') Model.xmlns_to_package('http://jaymes.biz/derp') == 'scap.model.derp' Model.unregister_namespace('scap.model.derp') with pytest.raises(UnregisteredNamespaceException): Model.xmlns_to_package('http://jaymes.biz/derp') def test_is_nil(): root = Model.load(None, ET.fromstring('<test:RootFixture xmlns:test="http://jaymes.biz/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />')) assert root.get_value() is None
def register_namespaces(): from scap.Model import Model Model.register_namespace('scap.model.ai_1_1', 'http://scap.nist.gov/schema/asset-identification/1.1') Model.register_namespace('scap.model.arf_1_1', 'http://scap.nist.gov/schema/asset-reporting-format/1.1') Model.register_namespace('scap.model.arf_rel_1_0', 'http://scap.nist.gov/specifications/arf/vocabulary/relationships/1.0') Model.register_namespace('scap.model.cpe_1_0', 'http://cpe.mitre.org/XMLSchema/cpe/1.0') Model.register_namespace('scap.model.cpe_dict_2_3', 'http://cpe.mitre.org/dictionary/2.0') Model.register_namespace('scap.model.cpe_lang_2_3', 'http://cpe.mitre.org/language/2.0') Model.register_namespace('scap.model.cpe_naming_2_3', 'http://cpe.mitre.org/naming/2.0') Model.register_namespace('scap.model.dc_elements_1_1', 'http://purl.org/dc/elements/1.1/') Model.register_namespace('scap.model.tmsad_1_0', 'http://scap.nist.gov/schema/xml-dsig/1.0') Model.register_namespace('scap.model.ocil_2_0', 'http://scap.nist.gov/schema/ocil/2.0') Model.register_namespace('scap.model.ocil_2_0', 'http://scap.nist.gov/schema/ocil/2') Model.register_namespace('scap.model.oval_5', 'http://oval.mitre.org/XMLSchema/oval-common-5') Model.register_namespace('scap.model.oval_5.defs', 'http://oval.mitre.org/XMLSchema/oval-definitions-5') Model.register_namespace('scap.model.oval_5.defs.independent', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#independent') Model.register_namespace('scap.model.oval_5.defs.linux', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#linux') Model.register_namespace('scap.model.oval_5.defs.windows', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#windows') Model.register_namespace('scap.model.oval_5.dir', 'http://oval.mitre.org/XMLSchema/oval-directives-5') Model.register_namespace('scap.model.oval_5.sc', 'http://oval.mitre.org/XMLSchema/oval-system-characteristics-5') Model.register_namespace('scap.model.oval_5.sc.linux', 'http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#linux') Model.register_namespace('scap.model.oval_5.var', 'http://oval.mitre.org/XMLSchema/oval-variables-5') Model.register_namespace('scap.model.scap_source_1_2', 'http://scap.nist.gov/schema/scap/source/1.2') Model.register_namespace('scap.model.rep_core_1_1', 'http://scap.nist.gov/schema/reporting-core/1.1') Model.register_namespace('scap.model.vuln_0_4', 'http://scap.nist.gov/schema/vulnerability/0.4') Model.register_namespace('scap.model.xal_2_0', 'urn:oasis:names:tc:ciq:xsdschema:xAL:2.0') Model.register_namespace('scap.model.xccdf_1_1', 'http://checklists.nist.gov/xccdf/1.1') Model.register_namespace('scap.model.xccdf_1_2', 'http://checklists.nist.gov/xccdf/1.2') Model.register_namespace('scap.model.xccdf_p_1_1', 'http://checklists.nist.gov/xccdf-p/1.1') Model.register_namespace('scap.model.xccdf_p_0_2_3', 'http://www.cisecurity.org/xccdf/platform/0.2.3') Model.register_namespace('scap.model.xhtml', 'http://www.w3.org/1999/xhtml') Model.register_namespace('scap.model.xlink', 'http://www.w3.org/1999/xlink') Model.register_namespace('scap.model.xml_cat_1_1', 'urn:oasis:names:tc:entity:xmlns:xml:catalog') Model.register_namespace('scap.model.xmldsig_2000_09', 'http://www.w3.org/2000/09/xmldsig#') Model.register_namespace('scap.model.xnl_2_0', 'urn:oasis:names:tc:ciq:xsdschema:xNL:2.0')
# You should have received a copy of the GNU General Public License # along with PySCAP. If not, see <http://www.gnu.org/licenses/>. import logging import pathlib import pytest import xml.etree.ElementTree as ET from fixtures.test.RootFixture import RootFixture from fixtures.test.EnclosedFixture import EnclosedFixture from scap.Model import Model, ModelList from scap.Inventory import Inventory import scap.model.xlink logging.basicConfig(level=logging.DEBUG) Model.register_namespace('scap.model.xlink', 'http://www.w3.org/1999/xlink') def test_simple_local(): path = (pathlib.Path(str(pytest.config.rootdir)) / 'tests' / 'model' / 'test_xlink.xml').as_posix() if not path.startswith('/'): path = '/' + path model = Model.load( None, ET.fromstring( '<test:XLinkFixture ' + 'xmlns:test="http://jaymes.biz/test" ' + 'xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" ' + 'xlink:href="file://' + path + '" />')) assert isinstance(model._elements, ModelList) assert len(model._elements) > 0
import scap.model.oval_5.defs.independent as pkg for m_finder, m_name, m_ispkg in pkgutil.iter_modules(path=pkg.__path__): try: mod = importlib.import_module(pkg.__name__ + '.' + m_name, pkg.__name__) globals()[m_name] = getattr(mod, m_name) except AttributeError: pass import scap.model.oval_5.sc.independent as pkg for m_finder, m_name, m_ispkg in pkgutil.iter_modules(path=pkg.__path__): try: mod = importlib.import_module(pkg.__name__ + '.' + m_name, pkg.__name__) globals()[m_name] = getattr(mod, m_name) except AttributeError: pass Model.register_namespace('scap.model.oval_5', 'http://oval.mitre.org/XMLSchema/oval-common-5') Model.register_namespace('scap.model.oval_5.defs', 'http://oval.mitre.org/XMLSchema/oval-definitions-5') Model.register_namespace('scap.model.oval_5.defs.independent', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#independent') Model.register_namespace('scap.model.oval_5.sc', 'http://oval.mitre.org/XMLSchema/oval-system-characteristics-5') Model.register_namespace('scap.model.oval_5.sc.independent', 'http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#independent') logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) filename = str(pathlib.Path(os.path.expanduser('~')) / '.pyscap' / 'inventory.ini') try: with open(filename, 'r') as fp: logger.debug('Loading inventory from ' + filename) Inventory().readfp(fp) except IOError: logger.error('Could not read from inventory file ' + filename)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with PySCAP. If not, see <http://www.gnu.org/licenses/>. import importlib import logging import pytest import pkgutil from scap.Model import Model # import all the classes in the package import scap.model.oval_5.defs.unix as pkg for m_finder, m_name, m_ispkg in pkgutil.iter_modules(path=pkg.__path__): try: mod = importlib.import_module(pkg.__name__ + '.' + m_name, pkg.__name__) globals()[m_name] = getattr(mod, m_name) except AttributeError: pass Model.register_namespace('scap.model.oval_5', 'http://oval.mitre.org/XMLSchema/oval-common-5') Model.register_namespace('scap.model.oval_5.defs', 'http://oval.mitre.org/XMLSchema/oval-definitions-5') Model.register_namespace('scap.model.oval_5.defs.unix', 'http://oval.mitre.org/XMLSchema/oval-definitions-5#unix') logging.basicConfig(level=logging.DEBUG) def test_parse(): pass
# PySCAP is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # PySCAP is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with PySCAP. If not, see <http://www.gnu.org/licenses/>. import logging import pathlib import pytest import xml.etree.ElementTree as ET from scap.Model import Model import scap.model.xccdf_1_1 logging.basicConfig(level=logging.DEBUG) Model.register_namespace('scap.model.xccdf_1_1', 'http://checklists.nist.gov/xccdf/1.1') Model.register_namespace('scap.model.xhtml', 'http://www.w3.org/1999/xhtml') Model.register_namespace('scap.model.dc_elements_1_1', 'http://purl.org/dc/elements/1.1/') Model.register_namespace('scap.model.cpe_lang_2_3', 'http://cpe.mitre.org/language/2.0') def test_benchmark(): path = pathlib.Path(str(pytest.config.rootdir)) / 'tests' / 'model' / 'test_xccdf_1_1.xml' model = Model.load(None, ET.parse(str(path)).getroot())