Verify the user-provided hostname in the server installer

The refactor change 9094dfc had a slight error where the
user-input provided value in input wasn't being validated. Only
the command-line or the current FQDN was being verified so
if the FQDN was bad any value input by the user was being skipped.

Fixes: https://pagure.io/freeipa/issue/9111

Signed-off-by: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
This commit is contained in:
Rob Crittenden authored and Florence Blanc-Renaud committed 2022-02-25 11:15:39 +01:00
1 parent ab9e7dac41
commit 7ac8e9696e
2 files changed
+31 -1

No files matched your search

+1 -1
View File
@@ -502,7 +502,7 @@ def install_check(installer):
host_name = host_default
try:
verify_fqdn(host_default, options.no_host_dns)
verify_fqdn(host_name, options.no_host_dns)
except BadHostError as e:
raise ScriptError(e)
@@ -1994,3 +1994,33 @@ class TestInstallwithSHA384withRSA(IntegrationTest):
result = self.master.run_command(cmd_args)
assert_str = 'Signature Algorithm: sha384WithRSAEncryption'
assert assert_str in result.stdout_text
class TestHostnameValidator(IntegrationTest):
"""Test installer options/validation"""
num_replicas = 0
def test_validate_hostname(self):
# https://pagure.io/freeipa/issue/9111
# Validate the user-provided hostname
self.master.run_command(['hostname', 'fedora'])
result = tasks.install_master(
self.master, unattended=False,
stdin_text=self.master.hostname + '\nn\nn\nn\n',
extra_args=('--netbios-name', 'EXAMPLE',),
raiseonerr=False
)
# Scrape the output for the summary which is only displayed
# if the hostname is validated.
hostname = None
for line in result.stdout_text.split('\n'):
print(line)
m = re.match(
r"Hostname:\s+({})".format(self.master.hostname), line
)
if m:
hostname = m.group(1)
break
assert hostname == self.master.hostname