1
|
|
|
from . import integ_test_base |
2
|
|
|
import os |
3
|
|
|
|
4
|
|
|
class TestMinimumTLSVersion(integ_test_base.IntegTestBase): |
5
|
|
|
def _get_log_contents(self): |
6
|
|
|
with open(self.log_file_path, 'r') as f: |
7
|
|
|
return f.read() |
8
|
|
|
|
9
|
|
|
def _get_config_file_name(self, tls_version: str) -> str: |
10
|
|
|
config_file = open(os.path.join(self.tmp_dir, "test.conf"), "w+") |
11
|
|
|
config_file.write( |
12
|
|
|
"[TabPy]\n" |
13
|
|
|
"TABPY_PORT = 9005\n" |
14
|
|
|
"TABPY_TRANSFER_PROTOCOL = https\n" |
15
|
|
|
"TABPY_CERTIFICATE_FILE = ./tests/integration/resources/2019_04_24_to_3018_08_25.crt\n" |
16
|
|
|
"TABPY_KEY_FILE = ./tests/integration/resources/2019_04_24_to_3018_08_25.key\n" |
17
|
|
|
) |
18
|
|
|
|
19
|
|
|
if tls_version is not None: |
20
|
|
|
config_file.write(f"TABPY_MINIMUM_TLS_VERSION = {tls_version}") |
21
|
|
|
|
22
|
|
|
pwd_file = self._get_pwd_file() |
23
|
|
|
if pwd_file is not None: |
24
|
|
|
pwd_file = os.path.abspath(pwd_file) |
25
|
|
|
config_file.write(f"TABPY_PWD_FILE = {pwd_file}\n") |
26
|
|
|
|
27
|
|
|
config_file.close() |
28
|
|
|
self.delete_config_file = True |
29
|
|
|
return config_file.name |
30
|
|
|
|
31
|
|
|
class TestMinimumTLSVersionValid(TestMinimumTLSVersion): |
32
|
|
|
def _get_config_file_name(self) -> str: |
33
|
|
|
return super()._get_config_file_name("TLSv1_3") |
34
|
|
|
|
35
|
|
|
def test_minimum_tls_version_valid(self): |
36
|
|
|
log_contents = self._get_log_contents() |
37
|
|
|
self.assertIn("Setting minimum TLS version to TLSv1_3", log_contents) |
38
|
|
|
|
39
|
|
|
class TestMinimumTLSVersionInvalid(TestMinimumTLSVersion): |
40
|
|
|
def _get_config_file_name(self) -> str: |
41
|
|
|
return super()._get_config_file_name("TLSv-1.3") |
42
|
|
|
|
43
|
|
|
def test_minimum_tls_version_invalid(self): |
44
|
|
|
log_contents = self._get_log_contents() |
45
|
|
|
self.assertIn("Unrecognized value for TABPY_MINIMUM_TLS_VERSION", log_contents) |
46
|
|
|
self.assertIn("Setting minimum TLS version to TLSv1_2", log_contents) |
47
|
|
|
|
48
|
|
|
class TestMinimumTLSVersionNotSpecified(TestMinimumTLSVersion): |
49
|
|
|
def _get_config_file_name(self) -> str: |
50
|
|
|
return super()._get_config_file_name(None) |
51
|
|
|
|
52
|
|
|
def test_minimum_tls_version_not_specified(self): |
53
|
|
|
log_contents = self._get_log_contents() |
54
|
|
|
self.assertIn("Setting minimum TLS version to TLSv1_2", log_contents) |
55
|
|
|
|