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 | 133a179 | 2017-06-03 20:38:22 -0400 | [diff] [blame] | 11 | from .utils import check_backend_support |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 12 | |
| 13 | |
Alex Gaynor | b8b1d72 | 2016-03-19 16:47:30 -0400 | [diff] [blame] | 14 | def pytest_report_header(config): |
Alex Gaynor | e85797b | 2016-03-19 16:51:05 -0400 | [diff] [blame] | 15 | return "OpenSSL: {0}".format(openssl_backend.openssl_version_text()) |
Alex Gaynor | b8b1d72 | 2016-03-19 16:47:30 -0400 | [diff] [blame] | 16 | |
Alex Gaynor | 5930305 | 2016-03-19 16:48:18 -0400 | [diff] [blame] | 17 | |
Alex Gaynor | 133a179 | 2017-06-03 20:38:22 -0400 | [diff] [blame] | 18 | @pytest.fixture() |
| 19 | def backend(request): |
| 20 | required_interfaces = [ |
| 21 | mark.kwargs["interface"] |
| 22 | for mark in request.node.get_marker("requires_backend_interface") |
| 23 | ] |
Alex Gaynor | e6055fb | 2017-06-03 22:02:50 -0400 | [diff] [blame] | 24 | if not all( |
Alex Gaynor | 133a179 | 2017-06-03 20:38:22 -0400 | [diff] [blame] | 25 | isinstance(openssl_backend, iface) for iface in required_interfaces |
| 26 | ): |
Alex Gaynor | e6055fb | 2017-06-03 22:02:50 -0400 | [diff] [blame] | 27 | pytest.skip( |
| 28 | "OpenSSL doesn't implement required interfaces: {0}".format( |
| 29 | required_interfaces |
| 30 | ) |
Alex Gaynor | 133a179 | 2017-06-03 20:38:22 -0400 | [diff] [blame] | 31 | ) |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 32 | |
Alex Gaynor | e6055fb | 2017-06-03 22:02:50 -0400 | [diff] [blame] | 33 | check_backend_support(openssl_backend, request) |
| 34 | return openssl_backend |