from tests.utils import init_test_logging
from anchore_engine.subsys import logger
from anchore_engine.services.policy_engine.engine.feeds.download import (
    FeedDataFileJsonIterator,
    FileListJsonIterator,
    LocalFeedDataRepo,
    FeedDownloader,
)
from anchore_engine.services.policy_engine.engine.feeds.schemas import (
    LocalFeedDataRepoMetadata,
    DownloadOperationResult,
)
from anchore_engine.utils import ensure_bytes, timer

init_test_logging(level="debug")

ANCHOREIO_URI = "https://ancho.re/v1/service/feeds"

simple_data = {
    "next_token": "sometokenvalue",
    "data": [
        {"vulnerability": "vuln1"},
        {"vulnerability": "vuln2"},
        {"vulnerability": "vuln3"},
    ],
    "since": "2020-01-01T00:00:00Z",
}

sequence_data = [
    {
import datetime
from tests.utils import init_test_logging
from anchore_engine.services.policy_engine.engine.feeds.client import get_client
from anchore_engine.subsys import logger

feed_url = "https://ancho.re/v1/service/feeds"
init_test_logging(level="info")


def test_anon_user():
    test_client = get_client(
        feeds_url=feed_url,
        user=("*****@*****.**", "pbiU2RYZ2XrmYQ"),
        conn_timeout=10,
        read_timeout=30,
    )
    for f in test_client.list_feeds().feeds:
        try:
            test_client.list_feed_groups(f.name)
        except Exception as e:
            logger.error(("Caught: {} for feed:  {}".format(e, f)))
    test_client.get_feed_group_data("vulnerabilities",
                                    "alpine:3.6",
                                    since=datetime.datetime.utcnow())


# def test_auth_error():
#    with pytest.raises(InvalidCredentialsError):
#        test_client = get_client(feeds_url=feed_url,
#                                 token_url=token_url,
#                                 client_url=client_url,
Exemple #3
0
Tests the feed data fetcher
"""

import datetime
import pytest
import tempfile
import json
import os

from tests.utils import init_test_logging
from anchore_engine.subsys import logger
from anchore_engine.services.policy_engine.engine.feeds.download import FeedDataFileJsonIterator, FileListJsonIterator, LocalFeedDataRepo, FeedDownloader
from anchore_engine.services.policy_engine.engine.feeds.schemas import LocalFeedDataRepoMetadata, DownloadOperationResult
from anchore_engine.utils import ensure_bytes, timer

init_test_logging(level='debug')

ANCHOREIO_URI = 'https://ancho.re/v1/service/feeds'

simple_data = {
    'next_token':
    'sometokenvalue',
    'data': [{
        'vulnerability': 'vuln1'
    }, {
        'vulnerability': 'vuln2'
    }, {
        'vulnerability': 'vuln3'
    }],
    'since':
    '2020-01-01T00:00:00Z'
Exemple #4
0
"""
Brings up each api in a test process to ensure spec is clean and works
"""

import pytest
import connexion
from connexion.mock import MockResolver
import os
import signal
import time
from tests.utils import init_test_logging
from anchore_engine.subsys import logger

init_test_logging()

prefix = os.getcwd()

service_swaggers = [
    "anchore_engine/services/apiext/swagger/swagger.yaml",
    "anchore_engine/services/catalog/swagger/swagger.yaml",
    "anchore_engine/services/simplequeue/swagger/swagger.yaml",
    "anchore_engine/services/analyzer/swagger/swagger.yaml",
    "anchore_engine/services/policy_engine/swagger/swagger.yaml",
]


@pytest.mark.parametrize("service", service_swaggers)
def test_api_service(service):
    """
    Creates a mocked interface for each specified swagger spec and creates
    a server to ensure swagger validates fully.
Exemple #5
0
import pytest

from tests.utils import init_test_logging
from anchore_engine.db import session_scope, FixedArtifact, Vulnerability
from anchore_engine.subsys import logger
from tests.fixtures import anchore_db

init_test_logging(level='info')


def tearDown():
    with session_scope() as session:
        records = session.query(Vulnerability).filter(
            Vulnerability.id == 'FA_TEST-1234').all()
        for record in records:
            logger.info("DELETING test record {}".format(record))
            session.delete(record)


def test_FixedArtifact_fix_observed_at_behavior(anchore_db):
    try:
        with session_scope() as session:
            testV = Vulnerability()
            testV.id = 'FA_TEST-1234'
            testV.namespace_name = 'fa_testnamespace:1'
            testV.severity = 'Unknown'

            # this indicates a fix available
            testFA_wfix = FixedArtifact()
            testFA_wfix.name = 'fa_testpkg1'
            testFA_wfix.version = '1.0'