blob: 583c4099d9a9fe8f69c598fcc0952812e25769c8 [file] [log] [blame]
Alex Gaynor5951f462014-11-16 09:08:42 -08001# 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.
Alex Gaynorc37feed2014-03-08 08:32:56 -08004
5from __future__ import absolute_import, division, print_function
6
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -06007import pytest
8
Alex Gaynorb8b1d722016-03-19 16:47:30 -04009from cryptography.hazmat.backends.openssl import backend as openssl_backend
Alex Gaynor7aab8b42014-10-23 11:01:25 -070010
Alex Gaynor2e85a922018-07-16 11:18:33 -040011from .utils import (
12 check_backend_support, load_wycheproof_tests, skip_if_wycheproof_none
13)
Paul Kehrer34c075e2014-01-13 21:52:08 -050014
15
Alex Gaynorb8b1d722016-03-19 16:47:30 -040016def pytest_report_header(config):
Alex Gaynore85797b2016-03-19 16:51:05 -040017 return "OpenSSL: {0}".format(openssl_backend.openssl_version_text())
Alex Gaynorb8b1d722016-03-19 16:47:30 -040018
Alex Gaynor59303052016-03-19 16:48:18 -040019
Alex Gaynor2e85a922018-07-16 11:18:33 -040020def 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 for path in metafunc.function.wycheproof_tests.args:
31 testcases.extend(load_wycheproof_tests(wycheproof, path))
32 metafunc.parametrize("wycheproof", testcases)
33
34
Alex Gaynor133a1792017-06-03 20:38:22 -040035@pytest.fixture()
36def backend(request):
37 required_interfaces = [
38 mark.kwargs["interface"]
39 for mark in request.node.get_marker("requires_backend_interface")
40 ]
Alex Gaynore6055fb2017-06-03 22:02:50 -040041 if not all(
Alex Gaynor133a1792017-06-03 20:38:22 -040042 isinstance(openssl_backend, iface) for iface in required_interfaces
43 ):
Alex Gaynore6055fb2017-06-03 22:02:50 -040044 pytest.skip(
45 "OpenSSL doesn't implement required interfaces: {0}".format(
46 required_interfaces
47 )
Alex Gaynor133a1792017-06-03 20:38:22 -040048 )
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060049
Alex Gaynore6055fb2017-06-03 22:02:50 -040050 check_backend_support(openssl_backend, request)
51 return openssl_backend