Debian Codegraph @

dirsrvtests/tests/suites/tls/tls_cert_namespace_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 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 time
10 import subprocess
11 import pytest
12
13 import glob
14 from lib389.utils import *
15 from test389.topologies import topology_st
16 from lib389.paths import Paths
17
18 pytestmark = pytest.mark.tier1
19
20 logging.getLogger(__name__).setLevel(logging.DEBUG)
21 log = logging.getLogger(__name__)
22
23 p = Paths()
24
25
26 @pytest.mark.skipif(p.with_systemd == False, reason='Will not run without systemd')
27 @pytest.mark.skipif(ds_is_older("1.4.3"), reason="Not implemented")
28 def test_pem_cert_in_private_namespace(topology_st):
29 """Test if certificates are present in private /tmp namespace
30
31 :id: 01bc27d0-6368-496a-9724-7fe1e8fb239b
32 :customerscenario: True
33 :setup: Standalone instance
34 :steps:
35 1. Create DS instance
36 2. Enable TLS
37 3. Check if value of PrivateTmp == yes
38 4. Check if pem certificates are present in private /tmp
39 5. Check if pem certificates are not present in /etc/dirsrv/instance
40 :expectedresults:
41 1. Success
42 2. Success
43 3. Success
44 4. Success
45 5. Success
46 """
47
48 PEM_CHECK = ['Self-Signed-CA.pem', 'Server-Cert-Key.pem', 'Server-Cert.pem']
49 PRIVATE_TMP = 'PrivateTmp=yes'
50
51 standalone = topology_st.standalone
52
53 log.info('Enable TLS')
54 standalone.enable_tls()
55
56 log.info('Checking PrivateTmp value')
57 cmdline = ['systemctl', 'show', '-p', 'PrivateTmp', 'dirsrv@{}.service'.format(standalone.serverid)]
58 log.info('Command used : %s' % format_cmd_list(cmdline))
59 result = subprocess.check_output(cmdline)
60 assert PRIVATE_TMP in ensure_str(result)
61
62 log.info('Check files in private /tmp')
63 cert_path = glob.glob('/tmp/systemd-private-*-dirsrv@{}.service-*/tmp/slapd-{}/'.format(standalone.serverid,
64 standalone.serverid))
65 assert os.path.exists(cert_path[0])
66 for item in PEM_CHECK:
67 log.info('Check that {} is present in private /tmp'.format(item))
68 assert os.path.exists(cert_path[0] + item)
69
70 log.info('Check instance cert directory')
71 cert_path = '/etc/dirsrv/slapd-{}/'.format(standalone.serverid)
72 assert os.path.exists(cert_path)
73 for item in PEM_CHECK:
74 log.info('Check that {} is not present in /etc/dirsrv/slapd-{}/ directory'.format(item, standalone.serverid))
75 assert not os.path.exists(cert_path + item)
76
77
78 @pytest.mark.xfail(ds_is_older("1.4.3"), reason="Might fail because of bz1809279")
79 @pytest.mark.skipif(ds_is_older("1.4.0"), reason="Not implemented")
80 def test_cert_category_authority(topology_st):
81 """Test that certificate generated by instance has category: authority
82
83 :id: b7e816e9-2786-4d76-9c5b-bb111b0870f2
84 :setup: Standalone instance
85 :steps:
86 1. Create DS instance
87 2. Enable TLS
88 3. Check if Self-Signed-CA.pem is present
89 4. Trust the certificate
90 5. Search if the certificate has category: authority
91 :expectedresults:
92 1. Success
93 2. Success
94 3. Success
95 4. Success
96 5. Success
97 """
98
99 PEM_FILE = 'Self-Signed-CA.pem'
100
101 standalone = topology_st.standalone
102
103 log.info('Enable TLS')
104 standalone.enable_tls()
105
106 log.info('Get certificate path')
107 if ds_is_older('1.4.3'):
108 cert_path = glob.glob('/etc/dirsrv/slapd-{}/'.format(standalone.serverid))
109 else:
110 cert_path = glob.glob('/tmp/systemd-private-*-dirsrv@{}.service-*/tmp/slapd-{}/'.format(standalone.serverid,
111 standalone.serverid))
112 log.info('Check that {} is present'.format(PEM_FILE))
113 signed_cert = cert_path[0] + PEM_FILE
114 assert os.path.exists(signed_cert)
115
116 log.info('Trust the certificate')
117 subprocess.check_output(['trust', 'anchor', signed_cert])
118
119 log.info('Search if our certificate has category: authority')
120 result = subprocess.check_output(['trust', 'list'])
121 assert re.search(r'^(.*)label: ssca[.]389ds[.]example[.]com\n(.*).*\n.*category: authority$', ensure_str(result),
122 re.MULTILINE)
123
124
125 if __name__ == '__main__':
126 # Run isolated
127 # -s for DEBUG mode
128 CURRENT_FILE = os.path.realpath(__file__)
129 pytest.main("-s %s" % CURRENT_FILE)