; config options
server:
	target-fetch-policy: "0 0 0 0 0"
	; Options for signed zone. The zone is partially copied from val_negcache_nxdomain.rpl
	trust-anchor: "testzone.nlnetlabs.nl.	IN	DS	2926 8 2 6f8512d1e82eecbd684fc4a76f39f8c5b411af385494873bdead663ddb78a88b"
	val-override-date: "20180213111425"
	qname-minimisation: "no"
	trust-anchor-signaling: no
	aggressive-nsec: yes
	zonemd-permissive-mode: yes

auth-zone:
	name: "example.com."
	## zonefile (or none).
	## zonefile: "example.com.zone"
	## master by IP address or hostname
	## can list multiple masters, each on one line.
	## master:
	## url for http fetch
	## url:
	## queries from downstream clients get authoritative answers.
	## for-downstream: yes
	for-downstream: yes
	## queries are used to fetch authoritative answers from this zone,
	## instead of unbound itself sending queries there.
	## for-upstream: yes
	for-upstream: no
	## on failures with for-upstream, fallback to sending queries to
	## the authority servers
	## fallback-enabled: no

	## this line generates zonefile: \n"/tmp/xxx.example.com"\n
	zonefile:
TEMPFILE_NAME example.com
	## this is the inline file /tmp/xxx.example.com
	## the tempfiles are deleted when the testrun is over.
TEMPFILE_CONTENTS example.com
$ORIGIN com.
example	3600	IN	SOA	dns.example.de. hostmaster.dns.example.de. (
		1379078166 28800 7200 604800 7200 )
	3600	IN	NS	ns1.example.com.
	3600	IN	NS	ns2.example.com.
$ORIGIN example.com.
www	3600	IN	A	1.2.3.4
mail	3600	IN	A	1.2.3.5
	3600	IN	AAAA	::5
ns1	3600	IN	A	1.2.3.4
ns2	3600	IN	AAAA	::2
TEMPFILE_END

auth-zone:
	name: "soa.high.com."
	for-downstream: yes
	for-upstream: no
	zonefile:
TEMPFILE_NAME soa.high.com
TEMPFILE_CONTENTS soa.high.com
$ORIGIN high.com.
soa	500	IN	SOA	dns.example.de. hostmaster.dns.example.de. (
		1379078166 28800 7200 604800 200 )
	3600	IN	NS	ns1.example.com.
	3600	IN	NS	ns2.example.com.
TEMPFILE_END

auth-zone:
	name: "soa.low.com."
	for-downstream: yes
	for-upstream: no
	zonefile:
TEMPFILE_NAME soa.low.com
TEMPFILE_CONTENTS soa.low.com
$ORIGIN low.com.
soa	200	IN	SOA	dns.example.de. hostmaster.dns.example.de. (
		1379078166 28800 7200 604800 500 )
	3600	IN	NS	ns1.example.com.
	3600	IN	NS	ns2.example.com.
TEMPFILE_END

auth-zone:
	name: "testzone.nlnetlabs.nl."
	for-downstream: yes
	for-upstream: no
	zonefile:
TEMPFILE_NAME testzone.nlnetlabs.nl
TEMPFILE_CONTENTS testzone.nlnetlabs.nl
$ORIGIN testzone.nlnetlabs.nl.
testzone.nlnetlabs.nl.  3600    IN      NSEC    alligator.testzone.nlnetlabs.nl. NS SOA RRSIG NSEC DNSKEY
testzone.nlnetlabs.nl.  3600    IN      RRSIG   NSEC 8 3 3600 20180313102201 20180213102201 44940 testzone.nlnetlabs.nl. gTKn6U1nal9oA79IRxLa/7zexl6A0yJZzeEGBbZ5rh5feyAr2X4LTR9bPCgcHeMVggf4FP+kD1L/sxzj/YLwB1ZKGKlwnzsHtPFTlmvDClaqQ76DRZq5Vejr2ZfnclBUb2vtxaXywTRW8oueaaq9flcShEQ/cQ+KRU8sc344qd0=
alligator.testzone.nlnetlabs.nl.        3600    IN      NSEC    cheetah.testzone.nlnetlabs.nl. TXT RRSIG NSEC
alligator.testzone.nlnetlabs.nl.        3600    IN      RRSIG   NSEC 8 4 3600 20180313102201 20180213102201 44940 testzone.nlnetlabs.nl. QAgQ0AsMoYG02+VPfoOctSPlTHdQOkQt5fFkSkzIbVhUzNOqa+dB/Qkc81AwFeJosA+PvYjt6utcVkIWmK2Djy9eXC49gILtVF79vUe4G7ZrybO5NXjqNa5ANoUGM+yew4wkjeNOMVAsvs+1kvFY7S8RAa/0AIYlZHQ8vNBPNaI=
testzone.nlnetlabs.nl.  4600    IN      SOA     ns.nlnetlabs.nl. ralph.nlnetlabs.nl. 1 14400 3600 604800 3600
testzone.nlnetlabs.nl.  4600    IN      RRSIG   SOA 8 3 3600 20180313102201 20180213102201 44940 testzone.nlnetlabs.nl. GhmXNFQktZIgaBpGKwj9Q2mfq5+jcbRPK+PPgtRVicUPZga/d/iGEL8PV/8DzGwkaZbM14pamSUMgdJibW4zNhLz/ukjPilbjoj6giH1jtbdZLAQ6iK9pZ/4jKUEq4txviTczZNnDeolgPEEl4xo4NclQmi7zj1XBlQRbjvG0/0=
TEMPFILE_END

stub-zone:
	name: "."
	stub-addr: 193.0.14.129 	# K.ROOT-SERVERS.NET.
CONFIG_END

SCENARIO_BEGIN Test authority zone with zonefile for downstream responses

; K.ROOT-SERVERS.NET.
RANGE_BEGIN 0 100
	ADDRESS 193.0.14.129
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
. IN NS
SECTION ANSWER
. IN NS	K.ROOT-SERVERS.NET.
SECTION ADDITIONAL
K.ROOT-SERVERS.NET.	IN	A	193.0.14.129
ENTRY_END

ENTRY_BEGIN
MATCH opcode subdomain
ADJUST copy_id copy_query
REPLY QR NOERROR
SECTION QUESTION
com. IN NS
SECTION AUTHORITY
com.	IN NS	a.gtld-servers.net.
SECTION ADDITIONAL
a.gtld-servers.net.	IN 	A	192.5.6.30
ENTRY_END
RANGE_END

; a.gtld-servers.net.
RANGE_BEGIN 0 100
	ADDRESS 192.5.6.30
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
com. IN NS
SECTION ANSWER
com.	IN NS	a.gtld-servers.net.
SECTION ADDITIONAL
a.gtld-servers.net.	IN 	A	192.5.6.30
ENTRY_END

ENTRY_BEGIN
MATCH opcode subdomain
ADJUST copy_id copy_query
REPLY QR NOERROR
SECTION QUESTION
example.com. IN NS
SECTION AUTHORITY
example.com.	IN NS	ns.example.com.
SECTION ADDITIONAL
ns.example.com. IN A 1.2.3.44
ENTRY_END
RANGE_END

; ns.example.net.
RANGE_BEGIN 0 100
	ADDRESS 1.2.3.44
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
example.net. IN NS
SECTION ANSWER
example.net.	IN NS	ns.example.net.
SECTION ADDITIONAL
ns.example.net.		IN 	A	1.2.3.44
ENTRY_END

ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
ns.example.net. IN A
SECTION ANSWER
ns.example.net. IN A	1.2.3.44
SECTION AUTHORITY
example.net.	IN NS	ns.example.net.
ENTRY_END

ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
ns.example.net. IN AAAA
SECTION AUTHORITY
example.net.	IN NS	ns.example.net.
SECTION ADDITIONAL
www.example.net. IN A	1.2.3.44
ENTRY_END

ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
example.com. IN NS
SECTION ANSWER
example.com.	IN NS	ns.example.net.
ENTRY_END

ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. IN A	10.20.30.40
ENTRY_END
RANGE_END

STEP 1 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
www.example.com. IN A
ENTRY_END

; recursion happens here.
STEP 20 CHECK_ANSWER
ENTRY_BEGIN
MATCH all
REPLY QR RD RA AA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. IN A	1.2.3.4
ENTRY_END

; check SOA TTL to be the minimum of the SOA.minimum and the SOA TTL
STEP 30 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
nonexistent.soa.high.com. IN A
ENTRY_END
STEP 31 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA AA NXDOMAIN
SECTION QUESTION
nonexistent.soa.high.com IN A
SECTION AUTHORITY
soa.high.com. 200 IN SOA dns.example.de. hostmaster.dns.example.de. 1379078166 28800 7200 604800 200
ENTRY_END
; check that the original SOA is also returned
STEP 32 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
soa.high.com. IN SOA
ENTRY_END
STEP 33 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA AA NOERROR
SECTION QUESTION
soa.high.com. IN SOA
SECTION ANSWER
soa.high.com. 500 IN SOA dns.example.de. hostmaster.dns.example.de. 1379078166 28800 7200 604800 200
ENTRY_END

; check SOA TTL to be the minimum of the SOA.minimum and the SOA TTL
STEP 40 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
nonexistent.soa.low.com. IN A
ENTRY_END
STEP 41 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA AA NXDOMAIN
SECTION QUESTION
nonexistent.soa.low.com. IN A
SECTION AUTHORITY
soa.low.com. 200 IN SOA dns.example.de. hostmaster.dns.example.de. 1379078166 28800 7200 604800 500
ENTRY_END
; check that the original SOA is also returned
STEP 42 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
soa.low.com. IN SOA
ENTRY_END
STEP 43 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA AA NOERROR
SECTION QUESTION
soa.low.com. IN SOA
SECTION ANSWER
soa.low.com. 200 IN SOA dns.example.de. hostmaster.dns.example.de. 1379078166 28800 7200 604800 500
ENTRY_END

; check SOA TTL to be minimum of the SOA.minimum and the SOA TTL for DNSSEC
STEP 50 QUERY
ENTRY_BEGIN
REPLY RD DO
SECTION QUESTION
ant.testzone.nlnetlabs.nl. IN A
ENTRY_END
STEP 51 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD DO RA AA NXDOMAIN
SECTION QUESTION
ant.testzone.nlnetlabs.nl. IN A
SECTION AUTHORITY
testzone.nlnetlabs.nl.  3600    IN      SOA     ns.nlnetlabs.nl. ralph.nlnetlabs.nl. 1 14400 3600 604800 3600
testzone.nlnetlabs.nl.  3600    IN      RRSIG   SOA 8 3 3600 20180313102201 20180213102201 44940 testzone.nlnetlabs.nl. GhmXNFQktZIgaBpGKwj9Q2mfq5+jcbRPK+PPgtRVicUPZga/d/iGEL8PV/8DzGwkaZbM14pamSUMgdJibW4zNhLz/ukjPilbjoj6giH1jtbdZLAQ6iK9pZ/4jKUEq4txviTczZNnDeolgPEEl4xo4NclQmi7zj1XBlQRbjvG0/0=
alligator.testzone.nlnetlabs.nl.        3600    IN      NSEC    cheetah.testzone.nlnetlabs.nl. TXT RRSIG NSEC
alligator.testzone.nlnetlabs.nl.        3600    IN      RRSIG   NSEC 8 4 3600 20180313102201 20180213102201 44940 testzone.nlnetlabs.nl. QAgQ0AsMoYG02+VPfoOctSPlTHdQOkQt5fFkSkzIbVhUzNOqa+dB/Qkc81AwFeJosA+PvYjt6utcVkIWmK2Djy9eXC49gILtVF79vUe4G7ZrybO5NXjqNa5ANoUGM+yew4wkjeNOMVAsvs+1kvFY7S8RAa/0AIYlZHQ8vNBPNaI=
testzone.nlnetlabs.nl.  3600    IN      NSEC    alligator.testzone.nlnetlabs.nl. NS SOA RRSIG NSEC DNSKEY
testzone.nlnetlabs.nl.  3600    IN      RRSIG   NSEC 8 3 3600 20180313102201 20180213102201 44940 testzone.nlnetlabs.nl. gTKn6U1nal9oA79IRxLa/7zexl6A0yJZzeEGBbZ5rh5feyAr2X4LTR9bPCgcHeMVggf4FP+kD1L/sxzj/YLwB1ZKGKlwnzsHtPFTlmvDClaqQ76DRZq5Vejr2ZfnclBUb2vtxaXywTRW8oueaaq9flcShEQ/cQ+KRU8sc344qd0=
ENTRY_END
; check that the original SOA is also returned
STEP 52 QUERY
ENTRY_BEGIN
REPLY RD DO
SECTION QUESTION
testzone.nlnetlabs.nl. IN SOA
ENTRY_END
STEP 53 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD DO RA AA NOERROR
SECTION QUESTION
testzone.nlnetlabs.nl. IN SOA
SECTION ANSWER
testzone.nlnetlabs.nl.  4600    IN      SOA     ns.nlnetlabs.nl. ralph.nlnetlabs.nl. 1 14400 3600 604800 3600
testzone.nlnetlabs.nl.  4600    IN      RRSIG   SOA 8 3 3600 20180313102201 20180213102201 44940 testzone.nlnetlabs.nl. GhmXNFQktZIgaBpGKwj9Q2mfq5+jcbRPK+PPgtRVicUPZga/d/iGEL8PV/8DzGwkaZbM14pamSUMgdJibW4zNhLz/ukjPilbjoj6giH1jtbdZLAQ6iK9pZ/4jKUEq4txviTczZNnDeolgPEEl4xo4NclQmi7zj1XBlQRbjvG0/0=
ENTRY_END

SCENARIO_END
