Adding test

/CoreOS/nmap/Regression/bz1192143-nc-1-performs-IPv6-connect-but-doesn-t-try-IPv4
This commit is contained in:
František Hrdina 2023-03-01 11:25:09 +01:00
commit 9cb64d14bc
2 changed files with 121 additions and 0 deletions

View file

@ -0,0 +1,25 @@
summary: Test for BZ#1192143 (nc(1) performs IPv6 connect but doesn't try IPv4)
description: |
Bug summary: nc(1) performs IPv6 connect but doesn't try IPv4 as well
Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=1192143
contact: fhrdina@redhat.com
component:
- nmap
test: ./runtest.sh
framework: beakerlib
recommend:
- nmap
duration: 15m
enabled: true
tag:
- Tier1
tier: '1'
link:
- relates: https://bugzilla.redhat.com/show_bug.cgi?id=1192143
adjust:
- enabled: false
when: distro < rhel-6
continue: false
extra-nitrate: TC#0496593
extra-summary: /CoreOS/nmap/Regression/bz1192143-nc-1-performs-IPv6-connect-but-doesn-t-try-IPv4
extra-task: /CoreOS/nmap/Regression/bz1192143-nc-1-performs-IPv6-connect-but-doesn-t-try-IPv4

View file

@ -0,0 +1,96 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/nmap/Regression/bz1192143-nc-1-performs-IPv6-connect-but-doesn-t-try-IPv4
# Description: Test for BZ#1192143 (nc(1) performs IPv6 connect but doesn't try IPv4)
# Author: Jaroslav Aster <jaster@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2015 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="nmap"
TMP_DIR="$(mktemp -d)"
NCAT_SERVER_OUTPUT="ncat-server-output.txt"
NCAT_CLIENT_OUTPUT="ncat-client-output.txt"
IPv4_LOCALHOST_IP="127.0.0.1"
TEST_PORT="22345"
HOSTS_FILE="/etc/hosts"
IPV6_SAVED_STATE="$(sysctl -n net.ipv6.conf.all.disable_ipv6)"
create_hosts_file()
{
rlFileBackup "$HOSTS_FILE"
cat << EOF > "$HOSTS_FILE"
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
EOF
}
restore_hosts_file()
{
rlFileRestore
}
enable_ipv6()
{
rlRun "sysctl -n net.ipv6.conf.all.disable_ipv6=0" 0 "Enabling ipv6."
}
restore_ipv6()
{
rlRun "sysctl -n net.ipv6.conf.all.disable_ipv6=${IPV6_SAVED_STATE}" 0 "Restoring ipv6."
}
rlJournalStart
rlPhaseStartSetup
rlAssertRpm "$PACKAGE"
rlRun "pushd ${TMP_DIR}" 0 "Entering to tmp dir."
create_hosts_file
enable_ipv6
rlPhaseEnd
rlPhaseStartTest
rlRun "ip -6 a show dev lo | grep '::1/128'"
rlRun "ip -4 a show dev lo | grep '127.0.0.1/8'"
ncat --recv-only -l "$IPv4_LOCALHOST_IP" "$TEST_PORT" &> "$NCAT_SERVER_OUTPUT" &
ncat_pid="$!"
rlRun "echo 'Test Message' | ncat --send-only localhost ${TEST_PORT} &> ${NCAT_CLIENT_OUTPUT}" 0 "Running ncat client, sending 'Test Message'."
kill "$ncat_pid"
rlRun "grep 'Ncat: Connection refused.' ${NCAT_CLIENT_OUTPUT}" 1 "Searching there is no 'Connection refused' message in ncat client output."
rlRun "grep 'Test Message' ${NCAT_SERVER_OUTPUT}" 0 "Searching there is 'Test Message' in ncat server output."
rlRun "cat ${NCAT_CLIENT_OUTPUT}" 0 "Printing ncat client output."
rlRun "cat ${NCAT_SERVER_OUTPUT}" 0 "Printing ncat server output."
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd" 0 "Leaving tmp dir."
rlRun "rm -r ${TMP_DIR}" 0 "Removing tmp files and dirs."
restore_hosts_file
restore_ipv6
rlPhaseEnd
rlJournalPrintText
rlJournalEnd