Alex Gaynor | 5951f46 | 2014-11-16 09:08:42 -0800 | [diff] [blame] | 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. |
Alex Gaynor | c37feed | 2014-03-08 08:32:56 -0800 | [diff] [blame] | 4 | |
| 5 | from __future__ import absolute_import, division, print_function |
| 6 | |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 7 | import pytest |
| 8 | |
Alex Gaynor | b8b1d72 | 2016-03-19 16:47:30 -0400 | [diff] [blame] | 9 | from cryptography.hazmat.backends.openssl import backend as openssl_backend |
Alex Gaynor | 7aab8b4 | 2014-10-23 11:01:25 -0700 | [diff] [blame] | 10 | |
Alex Gaynor | 2e85a92 | 2018-07-16 11:18:33 -0400 | [diff] [blame] | 11 | from .utils import ( |
| 12 | check_backend_support, load_wycheproof_tests, skip_if_wycheproof_none |
| 13 | ) |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 14 | |
| 15 | |
Alex Gaynor | b8b1d72 | 2016-03-19 16:47:30 -0400 | [diff] [blame] | 16 | def pytest_report_header(config): |
Alex Gaynor | e85797b | 2016-03-19 16:51:05 -0400 | [diff] [blame] | 17 | return "OpenSSL: {0}".format(openssl_backend.openssl_version_text()) |
Alex Gaynor | b8b1d72 | 2016-03-19 16:47:30 -0400 | [diff] [blame] | 18 | |
Alex Gaynor | 5930305 | 2016-03-19 16:48:18 -0400 | [diff] [blame] | 19 | |
Alex Gaynor | 2e85a92 | 2018-07-16 11:18:33 -0400 | [diff] [blame] | 20 | def pytest_addoption(parser): |
| 21 | parser.addoption("--wycheproof-root", default=None) |
| 22 | |
| 23 | |
| 24 | def 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 Gaynor | 133a179 | 2017-06-03 20:38:22 -0400 | [diff] [blame] | 35 | @pytest.fixture() |
| 36 | def backend(request): |
| 37 | required_interfaces = [ |
| 38 | mark.kwargs["interface"] |
| 39 | for mark in request.node.get_marker("requires_backend_interface") |
| 40 | ] |
Alex Gaynor | e6055fb | 2017-06-03 22:02:50 -0400 | [diff] [blame] | 41 | if not all( |
Alex Gaynor | 133a179 | 2017-06-03 20:38:22 -0400 | [diff] [blame] | 42 | isinstance(openssl_backend, iface) for iface in required_interfaces |
| 43 | ): |
Alex Gaynor | e6055fb | 2017-06-03 22:02:50 -0400 | [diff] [blame] | 44 | pytest.skip( |
| 45 | "OpenSSL doesn't implement required interfaces: {0}".format( |
| 46 | required_interfaces |
| 47 | ) |
Alex Gaynor | 133a179 | 2017-06-03 20:38:22 -0400 | [diff] [blame] | 48 | ) |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 49 | |
Alex Gaynor | e6055fb | 2017-06-03 22:02:50 -0400 | [diff] [blame] | 50 | check_backend_support(openssl_backend, request) |
| 51 | return openssl_backend |