Exemple #1
0
def pytest_generate_tests(metafunc):
    names = metafunc.config.getoption("--backend")
    selected_backends = select_backends(names, _available_backends())

    if "backend" in metafunc.fixturenames:
        filtered_backends = []
        required = metafunc.function.requires_backend_interface
        required_interfaces = tuple(mark.kwargs["interface"]
                                    for mark in required)
        for backend in selected_backends:
            if isinstance(backend, required_interfaces):
                filtered_backends.append(backend)

        # If you pass an empty list to parametrize Bad Things(tm) happen
        # as of pytest 2.6.4 when the test also has a parametrize decorator
        skip_if_empty(filtered_backends, required_interfaces)

        metafunc.parametrize("backend", filtered_backends)
Exemple #2
0
def pytest_generate_tests(metafunc):
    names = metafunc.config.getoption("--backend")
    selected_backends = select_backends(names, _available_backends())

    if "backend" in metafunc.fixturenames:
        filtered_backends = []
        required = metafunc.function.requires_backend_interface
        required_interfaces = tuple(
            mark.kwargs["interface"] for mark in required
        )
        for backend in selected_backends:
            if isinstance(backend, required_interfaces):
                filtered_backends.append(backend)

        # If you pass an empty list to parametrize Bad Things(tm) happen
        # as of pytest 2.6.4 when the test also has a parametrize decorator
        skip_if_empty(filtered_backends, required_interfaces)

        metafunc.parametrize("backend", filtered_backends)
Exemple #3
0
def pytest_generate_tests(metafunc):
    names = metafunc.config.getoption("--backend")
    selected_backends = select_backends(names, _available_backends())

    if "backend" in metafunc.fixturenames:
        metafunc.parametrize("backend", selected_backends)
from cryptography.hazmat.primitives.ciphers import Cipher, CipherAlgorithm
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.ciphers.modes import CBC, GCM

from ...utils import raises_unsupported_algorithm


@utils.register_interface(CipherAlgorithm)
class DummyCipher(object):
    name = "dummy-cipher"
    block_size = None
    key_size = None


@pytest.mark.skipif("commoncrypto"
                    not in [i.name for i in _available_backends()],
                    reason="CommonCrypto not available")
class TestCommonCrypto(object):
    def test_supports_cipher(self):
        from cryptography.hazmat.backends.commoncrypto.backend import backend
        assert backend.cipher_supported(None, None) is False

    def test_register_duplicate_cipher_adapter(self):
        from cryptography.hazmat.backends.commoncrypto.backend import backend
        with pytest.raises(ValueError):
            backend._register_cipher_adapter(AES,
                                             backend._lib.kCCAlgorithmAES128,
                                             CBC, backend._lib.kCCModeCBC)

    def test_handle_response(self):
        from cryptography.hazmat.backends.commoncrypto.backend import backend
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.ciphers.base import Cipher
from cryptography.hazmat.primitives.ciphers.modes import CBC, GCM

from ...utils import raises_unsupported_algorithm


@utils.register_interface(interfaces.CipherAlgorithm)
class DummyCipher(object):
    name = "dummy-cipher"
    block_size = None
    key_size = None


@pytest.mark.skipif("commoncrypto" not in
                    [i.name for i in _available_backends()],
                    reason="CommonCrypto not available")
class TestCommonCrypto(object):
    def test_supports_cipher(self):
        from cryptography.hazmat.backends.commoncrypto.backend import backend
        assert backend.cipher_supported(None, None) is False

    def test_register_duplicate_cipher_adapter(self):
        from cryptography.hazmat.backends.commoncrypto.backend import backend
        with pytest.raises(ValueError):
            backend._register_cipher_adapter(
                AES, backend._lib.kCCAlgorithmAES128,
                CBC, backend._lib.kCCModeCBC
            )

    def test_handle_response(self):
def pytest_generate_tests(metafunc):
    names = metafunc.config.getoption("--backend")
    selected_backends = select_backends(names, _available_backends())

    if "backend" in metafunc.fixturenames:
        metafunc.parametrize("backend", selected_backends)
def openssl_backend():
    """Return OpenSSL cryptography backend or fail."""
    for backend in _available_backends():
        if backend.name == 'openssl':
            return backend
    raise Exception('Could not find OpenSSL cryptography backend')
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.

from __future__ import absolute_import, division, print_function

import pytest

from cryptography.hazmat.backends import _available_backends
from cryptography.hazmat.bindings.commoncrypto.binding import Binding


@pytest.mark.skipif("commoncrypto" not in [i.name for i in _available_backends()], reason="CommonCrypto not available")
class TestCommonCrypto(object):
    def test_binding_loads(self):
        binding = Binding()
        assert binding
        assert binding.lib
        assert binding.ffi

    def test_binding_returns_same_lib(self):
        binding = Binding()
        binding2 = Binding()
        assert binding.lib == binding2.lib
        assert binding.ffi == binding2.ffi