Skip to content

Commit c6cbe94

Browse files
committed
foremanctl deploy --certificate-cname
1 parent c8beb78 commit c6cbe94

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/foreman/installer/test_install_foremanctl.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,59 @@ def test_foremanctl_deploy_reset_parameters(module_sat_ready_rhel):
165165
parameters_file = module_sat_ready_rhel.load_remote_yaml_file(FOREMANCTL_PARAMETERS_FILE)
166166
assert 'foreman_puma_workers' not in parameters_file
167167
assert 'pulp_worker_count' not in parameters_file
168+
169+
170+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default'], indirect=True)
171+
def test_foremanctl_deploy_certificate_cname(module_sat_ready_rhel):
172+
"""Verify foremanctl deploy --certificate-cname adds CNAME to server certificate SANs
173+
174+
:id: a5390e11-0e48-4a13-951f-749df8716e0c
175+
176+
:steps:
177+
1. Run foremanctl deploy --certificate-cname with an additional DNS name
178+
2. Verify the CNAME is persisted in the foremanctl parameters file
179+
3. Inspect the server certificate for the CNAME in Subject Alternative Names
180+
4. Add a /etc/hosts entry so the CNAME resolves locally
181+
5. Verify HTTPS connectivity using the CNAME with the self-signed CA
182+
183+
:expectedresults:
184+
1. foremanctl deploy completes successfully
185+
2. certificates_cnames contains the CNAME in the parameters file
186+
3. The server certificate SAN includes DNS:<cname>
187+
4. HTTPS request via the CNAME returns HTTP 200 without certificate errors
188+
"""
189+
satellite = module_sat_ready_rhel
190+
cname = f'cname.{satellite.hostname}'
191+
192+
result = satellite.execute(
193+
f'foremanctl deploy --certificate-cname {cname}',
194+
timeout='10m',
195+
)
196+
assert result.status == 0, (
197+
f'foremanctl deploy with --certificate-cname failed:\n{result.stderr}'
198+
)
199+
200+
parameters_file = satellite.load_remote_yaml_file(FOREMANCTL_PARAMETERS_FILE)
201+
assert cname in parameters_file.certificates_cnames
202+
203+
result = satellite.execute(
204+
'openssl x509 -in /root/certificates/certs/$(hostname -f).crt -noout -ext subjectAltName'
205+
)
206+
assert result.status == 0, f'Failed to read server certificate:\n{result.stderr}'
207+
assert f'DNS:{cname}' in result.stdout, (
208+
f'CNAME {cname} not found in server certificate SANs:\n{result.stdout}'
209+
)
210+
211+
satellite.execute(
212+
f'grep -q {cname} /etc/hosts '
213+
f'|| echo "$(hostname -I | awk \'{{print $1}}\') {cname}" >> /etc/hosts'
214+
)
215+
216+
result = satellite.execute(
217+
f'curl -s -o /dev/null -w "%{{http_code}}" '
218+
f'--cacert /root/certificates/certs/ca.crt '
219+
f'https://{cname}/users/login'
220+
)
221+
assert result.stdout.strip() == '200', (
222+
f'HTTPS request to {cname} failed with status {result.stdout.strip()}'
223+
)

0 commit comments

Comments
 (0)