Exemple #1
0
def test_mapped_distros(initialized_mappings):
    assert DistroMapping.distros_for("centos", "5", "centos") == [
        DistroTuple("rhel", "5", "RHEL")
    ]
    assert DistroMapping.distros_for("centos", "6", "centos") == [
        DistroTuple("rhel", "6", "RHEL")
    ]
def test_simple_map(anchore_db):
    init_distro_mappings()
    found = DistroMapping()
    found.from_distro = 'centos'
    found.to_distro = 'centos'
    found.flavor = 'RHEL'
    mapper = VersionPreservingDistroMapper('centos', '7', None, found)
    logger.info('Mapped centos to: {}'.format(mapper.mapping))
    assert mapper.mapping == [
        DistroTuple(distro='centos', version='7', flavor='RHEL')
    ]

    found.from_distro = 'fedora'
    found.to_distro = 'centos'
    found.flavor = 'RHEL'
    mapper = VersionPreservingDistroMapper('fedora', '27', 'centos', found)
    logger.info('Mapped fedora to: {}'.format(mapper.mapping))
    assert mapper.mapping == [
        DistroTuple(distro='centos', version='27', flavor='RHEL')
    ]

    mapper = VersionPreservingDistroMapper('fedora', '27', 'centos', None)
    logger.info('Mapped fedora to: {} on empty input'.format(mapper.mapping))
    assert mapper.mapping == [
        DistroTuple(distro='fedora', version='27', flavor='RHEL')
    ]
Exemple #3
0
def test_simple_map(anchore_db):
    init_distro_mappings()
    found = DistroMapping()
    found.from_distro = "centos"
    found.to_distro = "centos"
    found.flavor = "RHEL"
    mapper = VersionPreservingDistroMapper("centos", "7", None, found)
    logger.info("Mapped centos to: {}".format(mapper.mapping))
    assert mapper.mapping == [
        DistroTuple(distro="centos", version="7", flavor="RHEL")
    ]

    found.from_distro = "fedora"
    found.to_distro = "centos"
    found.flavor = "RHEL"
    mapper = VersionPreservingDistroMapper("fedora", "27", "centos", found)
    logger.info("Mapped fedora to: {}".format(mapper.mapping))
    assert mapper.mapping == [
        DistroTuple(distro="centos", version="27", flavor="RHEL")
    ]

    mapper = VersionPreservingDistroMapper("fedora", "27", "centos", None)
    logger.info("Mapped fedora to: {} on empty input".format(mapper.mapping))
    assert mapper.mapping == [
        DistroTuple(distro="fedora", version="27", flavor="RHEL")
    ]
Exemple #4
0
 def test_distro_from(self):
     print((DistroMapping.distros_for('centos', '7', 'rhel')))
     print((DistroMapping.distros_for('centos', '7.4.1', 'rhel')))
     print((DistroMapping.distros_for('debian', '9')))
     print((DistroMapping.distros_for('ubuntu', '16.04')))
     print((DistroMapping.distros_for('busybox', '3')))
     print((DistroMapping.distros_for('raspbian', '5')))
     print((DistroMapping.distros_for('magaiea', '3')))
     print((DistroMapping.distros_for('magaiea', '5', 'fedora,mandriva')))
Exemple #5
0
    def test_simple_map(self):
        found = DistroMapping()
        found.from_distro = 'centos'
        found.to_distro = 'centos'
        found.flavor = 'RHEL'
        mapper = VersionPreservingDistroMapper('centos', '7', None, found)
        print(('Mapped centos to: {}'.format(mapper.mapping)))

        found.from_distro = 'fedora'
        found.to_distro = 'centos'
        found.flavor = 'RHEL'
        mapper = VersionPreservingDistroMapper('fedora', '27', 'centos', found)
        print(('Mapped fedora to: {}'.format(mapper.mapping)))

        mapper = VersionPreservingDistroMapper('fedora', '27', 'centos', None)
        print(('Mapped fedora to: {} on empty input'.format(mapper.mapping)))
Exemple #6
0
def test_distromappings(initialized_mappings):
    c7 = DistroNamespace(name='centos', version='7', like_distro='rhel')
    assert c7.mapped_names() == []
    assert c7.like_namespace_names == ['rhel:7']

    r7 = DistroNamespace(name='rhel', version='7', like_distro='rhel')
    assert set(r7.mapped_names()) == {'centos', 'fedora', 'rhel'}
    assert r7.like_namespace_names == ['rhel:7']

    assert sorted(DistroMapping.distros_mapped_to('rhel', '7')) == sorted([
        DistroTuple('rhel', '7', 'RHEL'),
        DistroTuple('centos', '7', 'RHEL'),
        DistroTuple('fedora', '7', 'RHEL')
    ])
def test_distro_from(anchore_db):
    init_distro_mappings()
    session = get_thread_scoped_session()
    try:
        distros = DistroMapping.distros_for('centos', '7', 'rhel')
        logger.info('Distros for centos 7 (rhel) = {}'.format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for('centos', '7.4.1', 'rhel')
        logger.info('Distros for centos 7.4.1 (rhel) = {}'.format(distros))
        assert distros is not None
        assert len(distros) == 3

        distros = DistroMapping.distros_for('debian', '9')
        logger.info('Distros for debian 9 = {}'.format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for('ubuntu', '16.04')
        logger.info('Distros for ubuntu 16.04 = {}'.format(distros))
        assert distros is not None
        assert len(distros) == 3

        distros = DistroMapping.distros_for('busybox', '3')
        logger.info('Distros for busybox 3 = {}'.format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for('raspbian', '5')
        logger.info('Distros for raspbian 5 = {}'.format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for('magaiea', '3')
        logger.info('Distros for magaiea 3 = {}'.format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for('magaiea', '5', 'fedora,mandriva')
        logger.info(
            'Distros for magaiea 5 (fedora, mandriva) = {}'.format(distros))
        assert distros is not None
        assert len(distros) == 1
    finally:
        session.commit()
def test_distromappings(initialized_mappings):
    c7 = DistroNamespace(name="centos", version="7", like_distro="rhel")
    assert c7.mapped_names() == []
    assert c7.like_namespace_names == ["rhel:7"]

    r7 = DistroNamespace(name="rhel", version="7", like_distro="rhel")
    assert set(r7.mapped_names()) == {"centos", "fedora", "rhel", "redhat"}
    assert r7.like_namespace_names == ["rhel:7"]

    assert sorted(DistroMapping.distros_mapped_to("rhel", "7")) == sorted([
        DistroTuple("redhat", "7", "RHEL"),
        DistroTuple("rhel", "7", "RHEL"),
        DistroTuple("centos", "7", "RHEL"),
        DistroTuple("fedora", "7", "RHEL"),
    ])
Exemple #9
0
def test_distro_from(anchore_db):
    init_distro_mappings()
    session = get_thread_scoped_session()
    try:
        distros = DistroMapping.distros_for("centos", "7", "rhel")
        logger.info("Distros for centos 7 (rhel) = {}".format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for("centos", "7.4.1", "rhel")
        logger.info("Distros for centos 7.4.1 (rhel) = {}".format(distros))
        assert distros is not None
        assert len(distros) == 3

        distros = DistroMapping.distros_for("debian", "9")
        logger.info("Distros for debian 9 = {}".format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for("ubuntu", "16.04")
        logger.info("Distros for ubuntu 16.04 = {}".format(distros))
        assert distros is not None
        assert len(distros) == 3

        distros = DistroMapping.distros_for("busybox", "3")
        logger.info("Distros for busybox 3 = {}".format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for("raspbian", "5")
        logger.info("Distros for raspbian 5 = {}".format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for("magaiea", "3")
        logger.info("Distros for magaiea 3 = {}".format(distros))
        assert distros is not None
        assert len(distros) == 1

        distros = DistroMapping.distros_for("magaiea", "5", "fedora,mandriva")
        logger.info(
            "Distros for magaiea 5 (fedora, mandriva) = {}".format(distros))
        assert distros is not None
        assert len(distros) == 1
    finally:
        session.commit()
from anchore_engine.services.policy_engine import init_feed_registry
from anchore_engine.services.policy_engine.engine.policy.gate import ExecutionContext
from anchore_engine.services.policy_engine.engine.policy.gates.vulnerabilities import (
    FeedOutOfDateTrigger,
    UnsupportedDistroTrigger,
    VulnerabilitiesGate,
    VulnerabilityBlacklistTrigger,
    VulnerabilityMatchTrigger,
)
from anchore_engine.services.policy_engine.engine.vulns.providers import (
    GrypeProvider,
    LegacyProvider,
)

DISTRO_MAPPINGS = [
    DistroMapping(from_distro="alpine", to_distro="alpine", flavor="ALPINE"),
    DistroMapping(from_distro="busybox", to_distro="busybox", flavor="BUSYB"),
    DistroMapping(from_distro="centos", to_distro="rhel", flavor="RHEL"),
    DistroMapping(from_distro="debian", to_distro="debian", flavor="DEB"),
    DistroMapping(from_distro="fedora", to_distro="rhel", flavor="RHEL"),
    DistroMapping(from_distro="ol", to_distro="ol", flavor="RHEL"),
    DistroMapping(from_distro="rhel", to_distro="rhel", flavor="RHEL"),
    DistroMapping(from_distro="ubuntu", to_distro="ubuntu", flavor="DEB"),
    DistroMapping(from_distro="amzn", to_distro="amzn", flavor="RHEL"),
    DistroMapping(from_distro="redhat", to_distro="rhel", flavor="RHEL"),
]
MAPPINGS_MAP = {mapping.from_distro: mapping for mapping in DISTRO_MAPPINGS}


@pytest.fixture
def set_provider(monkeypatch):
Exemple #11
0
def test_mapped_distros(initialized_mappings):
    assert DistroMapping.distros_for(
        'centos', '5', 'centos') == [DistroTuple('rhel', '5', 'RHEL')]
    assert DistroMapping.distros_for(
        'centos', '6', 'centos') == [DistroTuple('rhel', '6', 'RHEL')]