1# This file is dual licensed under the terms of the Apache License, Version 2# 2.0, and the BSD License. See the LICENSE file in the root of this repository 3# for complete details. 4 5from __future__ import absolute_import, division, print_function 6 7import pytest 8 9from cryptography.hazmat.backends.openssl import backend as openssl_backend 10 11from .utils import ( 12 check_backend_support, load_wycheproof_tests, skip_if_wycheproof_none 13) 14 15 16def pytest_report_header(config): 17 return "OpenSSL: {0}".format(openssl_backend.openssl_version_text()) 18 19 20def pytest_addoption(parser): 21 parser.addoption("--wycheproof-root", default=None) 22 23 24def pytest_generate_tests(metafunc): 25 if "wycheproof" in metafunc.fixturenames: 26 wycheproof = metafunc.config.getoption("--wycheproof-root") 27 skip_if_wycheproof_none(wycheproof) 28 29 testcases = [] 30 marker = metafunc.definition.get_closest_marker("wycheproof_tests") 31 for path in marker.args: 32 testcases.extend(load_wycheproof_tests(wycheproof, path)) 33 metafunc.parametrize("wycheproof", testcases) 34 35 36@pytest.fixture() 37def backend(request): 38 required_interfaces = [ 39 mark.kwargs["interface"] 40 for mark in request.node.iter_markers("requires_backend_interface") 41 ] 42 if not all( 43 isinstance(openssl_backend, iface) for iface in required_interfaces 44 ): 45 pytest.skip( 46 "OpenSSL doesn't implement required interfaces: {0}".format( 47 required_interfaces 48 ) 49 ) 50 51 check_backend_support(openssl_backend, request) 52 return openssl_backend 53