#!/bin/sh
#
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.

#
# Common configuration data for system tests, to be sourced into
# other shell scripts.
#

# Find the top of the BIND9 tree.
TOP=@abs_top_builddir@

# Default algorithm for testing
DEFAULT_ALGORITHM=ECDSAP256SHA256
DEFAULT_ALGORITHM_NUMBER=13
DEFAULT_BITS=256

# must be different from DEFAULT_ALGORITHM
ALTERNATIVE_ALGORITHM=RSASHA256
ALTERNATIVE_ALGORITHM_NUMBER=8
ALTERNATIVE_BITS=1280

ARPANAME=$TOP/bin/tools/arpaname
CDS=$TOP/bin/dnssec/dnssec-cds
CHECKCONF=$TOP/bin/check/named-checkconf
CHECKDS=$TOP/bin/python/dnssec-checkds
CHECKZONE=$TOP/bin/check/named-checkzone
COVERAGE=$TOP/bin/python/dnssec-coverage
DDNSCONFGEN=$TOP/bin/confgen/ddns-confgen
DELV=$TOP/bin/delv/delv
DIG=$TOP/bin/dig/dig
DNSTAPREAD=$TOP/bin/tools/dnstap-read
DSFROMKEY=$TOP/bin/dnssec/dnssec-dsfromkey
FEATURETEST=$TOP/bin/tests/system/feature-test
FSTRM_CAPTURE=@FSTRM_CAPTURE@
IMPORTKEY=$TOP/bin/dnssec/dnssec-importkey
JOURNALPRINT=$TOP/bin/tools/named-journalprint
KEYFRLAB=$TOP/bin/dnssec/dnssec-keyfromlabel
KEYGEN=$TOP/bin/dnssec/dnssec-keygen
KEYMGR=$TOP/bin/python/dnssec-keymgr
MDIG=$TOP/bin/tools/mdig
NAMED=$TOP/bin/named/named
NSEC3HASH=$TOP/bin/tools/nsec3hash
NSLOOKUP=$TOP/bin/dig/nslookup
NSUPDATE=$TOP/bin/nsupdate/nsupdate
NZD2NZF=$TOP/bin/tools/named-nzd2nzf
PK11DEL="$TOP/bin/pkcs11/pkcs11-destroy -s ${SLOT:-0} -p ${HSMPIN:-1234} -w 0"
PK11GEN="$TOP/bin/pkcs11/pkcs11-keygen -q -s ${SLOT:-0} -p ${HSMPIN:-1234}"
PK11LIST="$TOP/bin/pkcs11/pkcs11-list -s ${SLOT:-0} -p ${HSMPIN:-1234}"
RESOLVE=$TOP/lib/samples/resolve
REVOKE=$TOP/bin/dnssec/dnssec-revoke
RNDC=$TOP/bin/rndc/rndc
RNDCCONFGEN=$TOP/bin/confgen/rndc-confgen
RRCHECKER=$TOP/bin/tools/named-rrchecker
SETTIME=$TOP/bin/dnssec/dnssec-settime
SIGNER=$TOP/bin/dnssec/dnssec-signzone
TSIGKEYGEN=$TOP/bin/confgen/tsig-keygen
VERIFY=$TOP/bin/dnssec/dnssec-verify
WIRETEST=$TOP/bin/tests/wire_test

BIGKEY=$TOP/bin/tests/system/rsabigexponent/bigkey
GENCHECK=$TOP/bin/tests/system/rndc/gencheck
KEYCREATE=$TOP/bin/tests/system/tkey/keycreate
KEYDELETE=$TOP/bin/tests/system/tkey/keydelete
MAKEJOURNAL=$TOP/bin/tests/makejournal
PIPEQUERIES=$TOP/bin/tests/system/pipelined/pipequeries
SAMPLEUPDATE=$TOP/lib/samples/sample-update

# we don't want a KRB5_CONFIG setting breaking the tests
KRB5_CONFIG=/dev/null

# The "stress" test is not run by default since it creates enough
# load on the machine to make it unusable to other users.
# The "dialup", "delzone", and "dupsigs" tests are also not run by
# default because they take a very long time to complete.
#
# List of tests hard-coded to use ports 5300 and 9953. For this
# reason, these must be run sequentially.
SEQUENTIALDIRS="ecdsa eddsa @PKCS11_TEST@ tkey"

# List of tests that use ports assigned by caller (other than 5300
# and 9953). Because separate blocks of ports can be used for teach
# test, these tests can be run in parallel.
#
# This symbol must be kept in step with the PARALLEL macro in Makefile.in
PARALLELDIRS="acl additional addzone allow-query auth autosign \
	builtin cacheclean case catz cds chain \
	checkconf checknames checkzone \
	@CHECKDS@ @COVERAGE@ @KEYMGR@ \
	cookie database digdelv dlv dlz dlzexternal \
	dns64 dnssec @DNSTAP@ dscp dsdigest dyndb \
	ednscompliance emptyzones \
	fetchlimit filter-aaaa formerr forward \
	geoip glue idna inline integrity ixfr keepalive \
	legacy limits logfileconfig \
	masterfile masterformat metadata mirror mkeys \
	names notify nslookup nsupdate nzd2nzf \
	padding pending pipelined qmin \
	reclimit redirect resolver rndc rootkeysentinel rpz rpzrecurse \
	rrchecker rrl rrsetorder rsabigexponent runtime \
	serve-stale sfcache smartsign sortlist \
	spf staticstub statistics statschannel stub synthfromdnssec \
	tcp tools tsig tsiggss ttl \
	unknown upforwd verify views wildcard \
	xfer xferquota zero zonechecks"

SUBDIRS="$SEQUENTIALDIRS $PARALLELDIRS"


# Things that are different on Windows
KILL=kill
DIFF=diff
DOS2UNIX=true
# There's no trailing period on Windows
TP=.

# Use the CONFIG_SHELL detected by configure for tests
SHELL=@SHELL@

# CURL will be empty if no program was found by configure
CURL=@CURL@

# XMLLINT will be empty if no program was found by configure
XMLLINT=@XMLLINT@

# PERL will be an empty string if no perl interpreter was found.
PERL=@PERL@

# Windows process management leave empty
PSSUSPEND=

PYTHON=@PYTHON@

#
# Determine if we support various optional features.
#
HAVEXMLSTATS=@XMLSTATS@
HAVEJSONSTATS=@JSONSTATS@
ZLIB=@ZLIB@
NZD=@NZD_TOOLS@

# copy_setports - Copy Configuration File and Replace Ports
# Unfortunately it has to be different on Windows.
#
# Convenience function to copy a configuration file, replacing the tokens
# QUERYPORT, CONTROLPORT and EXTRAPORT[1-8] with the values of the equivalent
# environment variables. (These values are set by "run.sh", which calls the
# scripts invoking this function.)
#
# Usage:
#   copy_setports infile outfile

copy_setports() {
    sed -e "s/@PORT@/${PORT}/g" \
        -e "s/@EXTRAPORT1@/${EXTRAPORT1}/g" \
        -e "s/@EXTRAPORT2@/${EXTRAPORT2}/g" \
        -e "s/@EXTRAPORT3@/${EXTRAPORT3}/g" \
        -e "s/@EXTRAPORT4@/${EXTRAPORT4}/g" \
        -e "s/@EXTRAPORT5@/${EXTRAPORT5}/g" \
        -e "s/@EXTRAPORT6@/${EXTRAPORT6}/g" \
        -e "s/@EXTRAPORT7@/${EXTRAPORT7}/g" \
        -e "s/@EXTRAPORT8@/${EXTRAPORT8}/g" \
        -e "s/@CONTROLPORT@/${CONTROLPORT}/g" \
	-e "s/@DEFAULT_ALGORITHM@/${DEFAULT_ALGORITHM}/g" \
	-e "s/@DEFAULT_ALGORITHM_NUMBER@/${DEFAULT_ALGORITHM_NUMBER}/g" \
	-e "s/@DEFAULT_BITS@/${DEFAULT_BITS}/g" \
	-e "s/@ALTERNATIVE_ALGORITHM@/${ALTERNATIVE_ALGORITHM}/g" \
	-e "s/@ALTERNATIVE_ALGORITHM_NUMBER@/${ALTERNATIVE_ALGORITHM_NUMBER}/g" \
	-e "s/@ALTERNATIVE_BITS@/${ALTERNATIVE_BITS}/g" \
	$1 > $2
}

# The rest is shared between Windows and Unices
. $TOP/bin/tests/system/conf.sh.common
