From 73d20e92f2971fdbd94b43b2be7cd6b478289671 Mon Sep 17 00:00:00 2001 From: vanhalenar Date: Tue, 23 Jul 2024 14:26:01 +0200 Subject: [PATCH 1/4] Feat full VM name validation --- test/bin/scenario.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/bin/scenario.sh b/test/bin/scenario.sh index 9e2fe9c59a..6b2aa65319 100755 --- a/test/bin/scenario.sh +++ b/test/bin/scenario.sh @@ -38,6 +38,48 @@ full_vm_name() { echo "${SCENARIO//@/-}-${base}" } +# hostname validation +# based on https://github.com/rhinstaller/anaconda/blob/c95142f76735a2e9ae6d845f8569d46632ddd619/pyanaconda/network.py#L96-L120 +validate_full_vm_name() { + local vm_name="$1" + + if [ -z "${vm_name}" ]; then + error "VM hostname cannot be empty string" + record_junit "${vmname}" "vm_name_validation" "FAILED" + exit 1 + fi + + if [ ${#vm_name} -gt 64 ]; then + error "VM hostname is too long" + record_junit "${vmname}" "vm_name_validation" "FAILED" + exit 1 + fi + + if [[ $vm_name =~ ^\. ]]; then + error "VM hostname cannot start with '.'" + record_junit "${vmname}" "vm_name_validation" "FAILED" + exit 1 + fi + + # split by '.' and check every section separately + IFS='.' read -ra ARR <<< "$vm_name" + for i in "${ARR[@]}"; do + if [ ${#i} -gt 63 ]; then + error "VM hostname is invalid" + record_junit "${vmname}" "vm_name_validation" "FAILED" + exit 1 + fi + + if ! echo "$i" | grep -E '^([a-zA-Z0-9]+-*[a-zA-Z0-9]+)+$|^[a-zA-Z0-9]+$' > /dev/null; then + error "VM hostname is invalid" + record_junit "${vmname}" "vm_name_validation" "FAILED" + exit 1 + fi + done + + record_junit "${vmname}" "vm_name_validation" "OK" +} + vm_property_filename() { local -r vmname="$1" local -r property="$2" @@ -227,6 +269,8 @@ prepare_kickstart() { local -r vm_hostname="${full_vmname/./-}" local -r hostname=$(hostname) + validate_full_vm_name $full_vmname + echo "Preparing kickstart file ${template} at ${output_dir}" if [ ! -f "${KICKSTART_TEMPLATE_DIR}/${template}" ]; then error "No ${template} in ${KICKSTART_TEMPLATE_DIR}" From 384cdddb5e62cfce7fc8cc187d36cfc81eefb176 Mon Sep 17 00:00:00 2001 From: vanhalenar Date: Thu, 25 Jul 2024 11:34:07 +0200 Subject: [PATCH 2/4] Modified VM hostname verification --- test/bin/scenario.sh | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/test/bin/scenario.sh b/test/bin/scenario.sh index 6b2aa65319..c78515814e 100755 --- a/test/bin/scenario.sh +++ b/test/bin/scenario.sh @@ -40,44 +40,34 @@ full_vm_name() { # hostname validation # based on https://github.com/rhinstaller/anaconda/blob/c95142f76735a2e9ae6d845f8569d46632ddd619/pyanaconda/network.py#L96-L120 -validate_full_vm_name() { +validate_vm_hostname() { local vm_name="$1" if [ -z "${vm_name}" ]; then error "VM hostname cannot be empty string" - record_junit "${vmname}" "vm_name_validation" "FAILED" + record_junit "${vm_name}" "vm_hostname_validation" "FAILED" exit 1 fi if [ ${#vm_name} -gt 64 ]; then error "VM hostname is too long" - record_junit "${vmname}" "vm_name_validation" "FAILED" + record_junit "${vm_name}" "vm_hostname_validation" "FAILED" exit 1 fi if [[ $vm_name =~ ^\. ]]; then error "VM hostname cannot start with '.'" - record_junit "${vmname}" "vm_name_validation" "FAILED" + record_junit "${vm_name}" "vm_hostname_validation" "FAILED" + exit 1 + fi + + if ! echo "${vm_name}" | grep -E '^([a-zA-Z0-9]+-*[a-zA-Z0-9]+)+$|^[a-zA-Z0-9]+$' > /dev/null; then + error "VM hostname is invalid" + record_junit "${vm_name}" "vm_hostname_validation" "FAILED" exit 1 fi - # split by '.' and check every section separately - IFS='.' read -ra ARR <<< "$vm_name" - for i in "${ARR[@]}"; do - if [ ${#i} -gt 63 ]; then - error "VM hostname is invalid" - record_junit "${vmname}" "vm_name_validation" "FAILED" - exit 1 - fi - - if ! echo "$i" | grep -E '^([a-zA-Z0-9]+-*[a-zA-Z0-9]+)+$|^[a-zA-Z0-9]+$' > /dev/null; then - error "VM hostname is invalid" - record_junit "${vmname}" "vm_name_validation" "FAILED" - exit 1 - fi - done - - record_junit "${vmname}" "vm_name_validation" "OK" + record_junit "${vm_name}" "vm_hostname_validation" "OK" } vm_property_filename() { @@ -269,7 +259,7 @@ prepare_kickstart() { local -r vm_hostname="${full_vmname/./-}" local -r hostname=$(hostname) - validate_full_vm_name $full_vmname + validate_vm_hostname "${vm_hostname}" echo "Preparing kickstart file ${template} at ${output_dir}" if [ ! -f "${KICKSTART_TEMPLATE_DIR}/${template}" ]; then From 18eee872bbeb440b8cf290de3fd0ed23ceb0c0f2 Mon Sep 17 00:00:00 2001 From: vanhalenar Date: Thu, 25 Jul 2024 11:59:21 +0000 Subject: [PATCH 3/4] Minor fix to pass CI verify job --- test/bin/scenario.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bin/scenario.sh b/test/bin/scenario.sh index c78515814e..fd9ddb07cf 100755 --- a/test/bin/scenario.sh +++ b/test/bin/scenario.sh @@ -55,7 +55,7 @@ validate_vm_hostname() { exit 1 fi - if [[ $vm_name =~ ^\. ]]; then + if [[ "${vm_name}" =~ ^\. ]]; then error "VM hostname cannot start with '.'" record_junit "${vm_name}" "vm_hostname_validation" "FAILED" exit 1 From 26248fe9c9c87adab5ba77e9a3c5a90e4165bf3a Mon Sep 17 00:00:00 2001 From: vanhalenar Date: Mon, 29 Jul 2024 11:33:44 +0200 Subject: [PATCH 4/4] Removed an unnecessary check from VM hostname validation --- test/bin/scenario.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/bin/scenario.sh b/test/bin/scenario.sh index fd9ddb07cf..5ccf257296 100755 --- a/test/bin/scenario.sh +++ b/test/bin/scenario.sh @@ -54,12 +54,6 @@ validate_vm_hostname() { record_junit "${vm_name}" "vm_hostname_validation" "FAILED" exit 1 fi - - if [[ "${vm_name}" =~ ^\. ]]; then - error "VM hostname cannot start with '.'" - record_junit "${vm_name}" "vm_hostname_validation" "FAILED" - exit 1 - fi if ! echo "${vm_name}" | grep -E '^([a-zA-Z0-9]+-*[a-zA-Z0-9]+)+$|^[a-zA-Z0-9]+$' > /dev/null; then error "VM hostname is invalid"