diff --git a/test/unit/fetch_command_output.cfg b/test/unit/fetch_command_output.cfg index 62290a8..c09df6c 100644 --- a/test/unit/fetch_command_output.cfg +++ b/test/unit/fetch_command_output.cfg @@ -46,7 +46,25 @@ COMMANDS+=("show lldp neighbors $LLDPINTERFACE") # ntp commands COMMANDS+=("show sntp status") +# !!! keeep replacement the same lenght OBFUSCATE=() -OBFUSCATE+=("sw-cb-&&&switch-") -OBFUSCATE+=("PSZ21221ECM&&&ABC12234XYZ") +# keys and secrets +OBFUSCATE+=("[a-f0-9]{40}&&&0123456789abcdef0123456789abcdef01234567") +OBFUSCATE+=("[a-zA-Z0-9+/]{30}&&&ABCD1234abcdABCD1234abcdABCD12") +# domains +OBFUSCATE+=("sw-cb-vratnice-&&&switch-no-2548-") +OBFUSCATE+=("sw-cb-&&&switch") +OBFUSCATE+=("cb.madeta.cz&&&examples.com") +OBFUSCATE+=("madeta.cz&&&examp.com") +# names and acronims OBFUSCATE+=("CZ;Ceske Budejovice;Rudolfovska 83;vr&&&Something;Somewhere;Somestreet;others") +OBFUSCATE+=("MDT&&&ABC") +OBFUSCATE+=("Madeta&&&Abcdef") +OBFUSCATE+=("NECOSS&&&Abcdef") +OBFUSCATE+=("Atlantis&&&Abcdefgh") +OBFUSCATE+=("PSZ21221ECM&&&ABC12234XYZ") +# specific repairs for example: +# - versions confused with IPs +OBFUSCATE+=("3.3.3.73&&&2.4.5.71") +OBFUSCATE+=("3.3.7.3&&&2.2.8.4") + diff --git a/test/unit/fetch_command_output.cfg.template b/test/unit/fetch_command_output.cfg.template new file mode 100644 index 0000000..44b04e3 --- /dev/null +++ b/test/unit/fetch_command_output.cfg.template @@ -0,0 +1,68 @@ +# Config file for utility 'fetch_command_output.sh' +# +# This will help you to make bunch of command output files for napalm drivers unit tests +# +# There is not any IP, MAC or names obfuscation or anonymizations! +# Before using outputs as a unit test files it is recommendet to protect +# your privacy information yourself by editing output files. + +# Required variables +# $INTERFACE - for detailed interface information +# $LLDPINTERFACE - for detailed LLDP information + +# Define empty array of commands +COMMANDS=() + +# This is example set of commands for napalm driver 's350' (Cisco SMB) + +# system info +COMMANDS+=("show version") +COMMANDS+=("show system") +COMMANDS+=("show version") +COMMANDS+=("show inventory") + +# config commands +COMMANDS+=("show startup-config") +COMMANDS+=("show running-config") +COMMANDS+=("show running-config detailed") + +# interface commands +COMMANDS+=("show interfaces status") +COMMANDS+=("show interfaces description") +COMMANDS+=("show interface switchport $INTERFACE") +COMMANDS+=("show ports jumbo-frame") + +# ip commands +COMMANDS+=("show hosts") +COMMANDS+=("show ip interface") +COMMANDS+=("show ipv6 interface brief") +COMMANDS+=("show arp") + +# lldp commands +COMMANDS+=("show lldp neighbors") +COMMANDS+=("show lldp local $LLDPINTERFACE") +COMMANDS+=("show lldp neighbors $LLDPINTERFACE") + +# ntp commands +COMMANDS+=("show sntp status") + +# Additional obfuscations +# format is "SOURCE&&&REPLACEMENT" +# !!! keep source and replacement the same lenght +OBFUSCATE=() +# keys and secrets +OBFUSCATE+=("[a-f0-9]{40}&&&0123456789abcdef0123456789abcdef01234567") +OBFUSCATE+=("[a-zA-Z0-9+/]{30}&&&ABCD1234abcdABCD1234abcdABCD12") +# domains +OBFUSCATE+=("somedoma.org&&&examples.com") +OBFUSCATE+=("domai.org&&&examp.com") +# names and acronims +OBFUSCATE+=("SECRET&&&someth") +OBFUSCATE+=("IBM&&&ABC") +OBFUSCATE+=("Microsoft&&&Abcdefgh") +OBFUSCATE+=("PS222221ECM&&&ABC12234XYZ") +# specific repairs for example: +# - versions confused with IPs +OBFUSCATE+=("3.3.3.73&&&2.4.5.71") +OBFUSCATE+=("3.3.7.3&&&2.2.8.4") + diff --git a/test/unit/fetch_command_output.sh b/test/unit/fetch_command_output.sh index 24d5b5e..18dd292 100755 --- a/test/unit/fetch_command_output.sh +++ b/test/unit/fetch_command_output.sh @@ -152,15 +152,13 @@ do echo "## Fetching '$CMD' to '$CMDSTR.txt'" # --debug - set -x - echo -e "$(napalm --debug --user "$DEVUSERNAME" --password "$DEVPASSWORD" --vendor "$VENDOR" "$DEVICE" call --method-kwargs "command='$CMD'" "$METHOD" | sed 's/^"//;s/"$//;s/\\"/"/g')" > "$CMDFILE" - set +x + echo -e "$(napalm --user "$DEVUSERNAME" --password "$DEVPASSWORD" --vendor "$VENDOR" "$DEVICE" call --method-kwargs "command='$CMD'" "$METHOD" | sed 's/^"//;s/"$//;s/\\"/"/g')" > "$CMDFILE" done echo "#### Preparing obfuscate script" echo "## IP addresses" IPs=$(cat "$CODIR/$TYPE/"*.txt \ - | sed -rn 's/.*[^0-9\.](([0-9]{1,3}\.){3}[0-9]{1,3})[^0-9\.].*/\1/gp' \ + | sed -rn 's/.*[^0-9\.](([0-9]{1,3}\.){3}[0-9]{1,3})[^0-9\.]*.*/\1/gp' \ | sort \ | uniq ) @@ -184,7 +182,7 @@ done echo "## MAC addresses" MACs=$(cat "$CODIR/$TYPE/"*.txt \ - | sed -rn -e 's/.*[^0-9\.:a-f-](([[:xdigit:]]{2}[:.-]?){5}[[:xdigit:]]{2})[^0-9\.:a-f-].*/\1/gp' \ + | sed -rn -e 's/.*[^0-9\.:a-f-](([[:xdigit:]]{2}[:.-]?){5}[[:xdigit:]]{2})[^0-9\.:a-f-]*.*/\1/gp' \ | sort \ | uniq ) @@ -215,7 +213,7 @@ echo "## Obfuscate IPs and MACs" echo oIPS=$oIPs echo oMACs=$oMACs set -x -sed -r -iOBF $oMACs $oIPs "$CODIR/$TYPE/"*.txt +sed -r -i $oMACs $oIPs "$CODIR/$TYPE/"*.txt set +x echo "## Obfuscate strings from OBFUSCATE config variable" @@ -228,9 +226,7 @@ do done echo $oSTR -sed -r -iSTR -e "$oSTR" "$CODIR/$TYPE/"*.txt - - +sed -r -i -e "$oSTR" "$CODIR/$TYPE/"*.txt echo "###################################################" echo "## Do not forget obfuscate other output: ##"