Debian Codegraph @

dirsrvtests/tests/suites/tls/ssl_version_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2022 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9 import logging
10 import pytest
11 import os
12 from lib389.config import Encryption
13 from lib389.utils import ds_is_older
14 from test389.topologies import topology_st as topo
15
16 pytestmark = pytest.mark.tier1
17
18 DEBUGGING = os.getenv("DEBUGGING", default=False)
19 if DEBUGGING:
20 logging.getLogger(__name__).setLevel(logging.DEBUG)
21 else:
22 logging.getLogger(__name__).setLevel(logging.INFO)
23 log = logging.getLogger(__name__)
24
25
26 def test_ssl_version_range(topo):
27 """Specify a test case purpose or name here
28
29 :id: bc400f54-3966-49c8-b640-abbf4fb2377e
30 :customerscenario: True
31 1. Get current default range
32 2. Set sslVersionMin and verify it is applied after a restart
33 3. Set sslVersionMax and verify it is applied after a restart
34 4. Sanity test all the min/max versions
35 :expectedresults:
36 1. Success
37 2. Success
38 3. Success
39 4. Success
40 """
41
42 topo.standalone.enable_tls()
43 enc = Encryption(topo.standalone)
44 default_min = enc.get_attr_val_utf8('sslVersionMin')
45 default_max = enc.get_attr_val_utf8('sslVersionMax')
46 log.info(f"default min: {default_min} max: {default_max}")
47 if DEBUGGING:
48 topo.standalone.config.set('nsslapd-auditlog-logging-enabled', 'on')
49
50 # Test that setting the min version is applied after a restart
51 enc.replace('sslVersionMin', default_max)
52 enc.replace('sslVersionMax', default_max)
53 topo.standalone.restart()
54 min = enc.get_attr_val_utf8('sslVersionMin')
55 assert min == default_max
56
57 # Test that setting the max version is applied after a restart
58 enc.replace('sslVersionMin', default_min)
59 enc.replace('sslVersionMax', default_min)
60 topo.standalone.restart()
61 max = enc.get_attr_val_utf8('sslVersionMax')
62 assert max == default_min
63
64 # 389-ds-base-1.4.3 == Fedora 32, 389-ds-base-1.4.4 == Fedora 33
65 # Starting from Fedora 33, cryptographic protocols (TLS 1.0 and TLS 1.1) were moved to LEGACY
66 # So we should not check for the policies with our DEFAULT crypro setup
67 # https://fedoraproject.org/wiki/Changes/StrongCryptoSettings2
68 if ds_is_older('1.4.4'):
69 ssl_versions = [('sslVersionMin', ['TLS1.0', 'TLS1.1', 'TLS1.2', 'TLS1.0']),
70 ('sslVersionMax', ['TLS1.0', 'TLS1.1', 'TLS1.2'])]
71 else:
72 ssl_versions = [('sslVersionMin', ['TLS1.2']),
73 ('sslVersionMax', ['TLS1.2', 'TLS1.3'])]
74
75 # Sanity test all the min/max versions
76 for attr, versions in ssl_versions:
77 for version in versions:
78 # Test that the setting is correctly applied after a restart
79 enc.replace(attr, version)
80 topo.standalone.restart()
81 current_val = enc.get_attr_val_utf8(attr)
82 assert current_val == version
83
84
85 if __name__ == '__main__':
86 # Run isolated
87 # -s for DEBUG mode
88 CURRENT_FILE = os.path.realpath(__file__)
89 pytest.main(["-s", CURRENT_FILE])