| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# aioimaplib : an IMAPrev4 lib using python asyncio |
| 3 |
# Copyright (C) 2016 Bruno Thomas |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
import os |
| 18 |
|
| 19 |
from OpenSSL import crypto |
| 20 |
from unittest import TestCase |
| 21 |
|
| 22 |
from tests.ssl_cert import create_temp_self_signed_cert |
| 23 |
|
| 24 |
|
| 25 |
class TestSslCert(TestCase): |
| 26 |
def setUp(self): |
| 27 |
self.cert, self.key = create_temp_self_signed_cert() |
| 28 |
|
| 29 |
def tearDown(self): |
| 30 |
os.remove(self.cert) |
| 31 |
os.remove(self.key) |
| 32 |
|
| 33 |
def test_create_temp_self_signed_cert_returns_two_file_names(self): |
| 34 |
assert os.path.isfile(self.cert) |
| 35 |
assert os.path.isfile(self.key) |
| 36 |
|
| 37 |
def test_create_temp_self_signed_cert_returns_cert_as_first_value(self): |
| 38 |
with open(self.cert, 'rb') as f: |
| 39 |
data = f.read() |
| 40 |
|
| 41 |
try: |
| 42 |
crypto.load_certificate(crypto.FILETYPE_PEM, data) |
| 43 |
except crypto.Error: |
| 44 |
self.fail('First file is not a certificate') |
| 45 |
|
| 46 |
def test_create_temp_self_signed_cert_returns_key_as_second_value(self): |
| 47 |
with open(self.key, 'rb') as f: |
| 48 |
data = f.read() |
| 49 |
|
| 50 |
try: |
| 51 |
crypto.load_privatekey(crypto.FILETYPE_PEM, data) |
| 52 |
except crypto.Error: |
| 53 |
self.fail('First file is not a key') |
| 54 |
|
| 55 |
def test_create_temp_self_signed_cert_can_generate_more_than_one_pair_of_keys(self): |
| 56 |
(second_cert, second_key) = create_temp_self_signed_cert() |
| 57 |
assert self.cert != second_cert |
| 58 |
assert os.path.isfile(second_cert) |
| 59 |
assert self.key != second_key |
| 60 |
assert os.path.isfile(second_key) |
| 61 |
os.remove(second_cert) |
| 62 |
os.remove(second_key) |