#!/bin/bash
set -eu

TESTDIR=$(readlink -f $(dirname $0))

case "$APT_TEST_METHOD" in
	http*_proxy*)
		:
		;;
	*)
		echo 'SKIP (makes sense only for HTTP(S) through proxy)' >&2
		exit 0
		;;
esac

. $TESTDIR/framework

setupenvironment

buildpackage 'simple-package'

generaterepository_and_switch_sources "$TMPWORKINGDIRECTORY/usr/src/RPM/RPMS"

# First, check that there is no access without the proxy.

msgmsg 'Unsetting proxy for apt for a while'
readonly APT_TEST_HTTP_PROXY="$http_proxy"
rm -f "$APT_TEST_PROXY_FOR_HTTP_CONF" ||:
unset http{,s}_proxy # if they were exported, now nothing will be set for children

# Skip the denial test in case we need a separate IPv6 address, because we don't.
case "$APT_TEST_METHOD" in
    http*_localhost6*)
	echo 'SKIPPING the direct access denial check on IPv6 (we lack a 2nd address)' >&2
	return # to where we were sourced from
	;;
esac

testfailure aptget update

testpkgnotinstalled 'simple-package'
testfailure aptget install 'simple-package'
testpkgnotinstalled 'simple-package'

# And then, check that access works through proxy (in the script which
# we are sourced from).
