#!/bin/sh

set -e

cd "${AUTOPKGTEST_TMP:-$(mktemp -d)}"

# AutoRecon creates its config and plugins directories in the user's home
export HOME="$PWD"
unset XDG_CONFIG_HOME XDG_DATA_HOME

# Scan only tcp/80 and run a single plugin of each type: the 'all-tcp-ports'
# port scan, the 'curl' service scan and the 'markdown' report.
# --disable-keyboard-control: stdin is not a terminal
# --unprivileged: use a TCP connect scan, so nmap doesn't need raw socket
#                 privileges (tests usually run as a normal user)
autorecon -v --disable-keyboard-control \
	-p T:80 --tags all-tcp-ports,curl,markdown \
	--nmap-append=--unprivileged \
	-o results megacorpone.com

out=results/megacorpone.com

# nmap found the web server
grep -E '^80/tcp +open +http ' "$out/scans/_full_tcp_nmap.txt"
# curl fetched the home page
grep -F '<title>MegaCorp One' "$out/scans/tcp80/tcp_80_http_curl.html"
# the results were added to the markdown report
grep -rlF '<title>MegaCorp One' "$out/report/report.md"
