Alex Gaynor | bfc06bc | 2013-08-06 19:36:19 -0700 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | # you may not use this file except in compliance with the License. |
| 3 | # You may obtain a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 10 | # implied. |
| 11 | # See the License for the specific language governing permissions and |
| 12 | # limitations under the License. |
| 13 | |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 14 | import pytest |
| 15 | |
Paul Kehrer | 5266752 | 2013-09-10 15:41:37 -0500 | [diff] [blame] | 16 | from cryptography.bindings.openssl.api import api |
Alex Gaynor | c62e91f | 2013-08-06 19:25:52 -0700 | [diff] [blame] | 17 | |
| 18 | |
Hynek Schlawack | 196515a | 2013-08-08 08:40:47 +0200 | [diff] [blame] | 19 | class TestOpenSSL(object): |
| 20 | def test_api_exists(self): |
| 21 | assert api |
Paul Kehrer | 733404a | 2013-09-09 15:26:26 -0500 | [diff] [blame] | 22 | |
| 23 | def test_openssl_version_text(self): |
Paul Kehrer | c1a218d | 2013-09-09 17:45:52 -0500 | [diff] [blame] | 24 | """ |
| 25 | This test checks the value of OPENSSL_VERSION_TEXT. |
Paul Kehrer | eb49db1 | 2013-09-09 17:12:29 -0500 | [diff] [blame] | 26 | |
| 27 | Unfortunately, this define does not appear to have a |
| 28 | formal content definition, so for now we'll test to see |
| 29 | if it starts with OpenSSL as that appears to be true |
| 30 | for every OpenSSL. |
| 31 | """ |
Paul Kehrer | bdafcd3 | 2013-09-09 17:44:11 -0500 | [diff] [blame] | 32 | assert api.openssl_version_text().startswith("OpenSSL") |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 33 | |
| 34 | def test_supports(self): |
| 35 | assert api.supports("not-a-real-cipher") is False |
| 36 | |
| 37 | def test_create_block_cipher_context_with_unsupported_cipher(self): |
| 38 | class FakeCipher(object): |
| 39 | name = "FakeCipher" |
| 40 | key_size = 24 |
| 41 | |
| 42 | class FakeMode(object): |
| 43 | name = "CCC" |
| 44 | |
| 45 | with pytest.raises(AssertionError): |
| 46 | cipher = FakeCipher() |
| 47 | mode = FakeMode() |
| 48 | api.create_block_cipher_context(cipher, mode) |