; config options
server:
	module-config: "validator iterator"
	qname-minimisation: "no"
	minimal-responses: no
	serve-expired: yes
	serve-expired-reply-ttl: 123

stub-zone:
	name: "example.com"
	stub-addr: 1.2.3.4
CONFIG_END

SCENARIO_BEGIN Test 0 TLL with serve-expired
; Scenario overview:
; - query for example.com. IN A
; - check that we get an answer for example.com. IN A with the correct 0 TTL
; - query again; this time the answer has >0 TTL
; - check the answer
; - query one last time after expiration
; - check that the configured reply ttl is used

; ns.example.com.
RANGE_BEGIN 0 100
	ADDRESS 1.2.3.4
	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.com.
		SECTION ADDITIONAL
			ns.example.com. IN A 1.2.3.4
	ENTRY_END
RANGE_END

RANGE_BEGIN 0 10
	ADDRESS 1.2.3.4
	ENTRY_BEGIN
		MATCH opcode qtype qname
		ADJUST copy_id
		REPLY QR NOERROR
		SECTION QUESTION
			example.com. IN A
		SECTION ANSWER
			example.com. 0 IN A 5.6.7.8
		SECTION AUTHORITY
			example.com. 0 IN NS ns.example.com.
		SECTION ADDITIONAL
			ns.example.com. 0 IN A 1.2.3.4
	ENTRY_END
RANGE_END

RANGE_BEGIN 11 100
	ADDRESS 1.2.3.4
	ENTRY_BEGIN
		MATCH opcode qtype qname
		ADJUST copy_id
		REPLY QR NOERROR
		SECTION QUESTION
			example.com. IN A
		SECTION ANSWER
			example.com. 10 IN A 5.6.7.8
		SECTION AUTHORITY
			example.com. 10 IN NS ns.example.com.
		SECTION ADDITIONAL
			ns.example.com. 10 IN A 1.2.3.4
	ENTRY_END
RANGE_END

; Let some time to pass so that timenow > 0
STEP 1 TIME_PASSES ELAPSE 3600

; Query with RD flag
STEP 2 QUERY
ENTRY_BEGIN
	REPLY RD
	SECTION QUESTION
		example.com. IN A
ENTRY_END

; Check that we got the correct answer with 0 TTL
STEP 10 CHECK_ANSWER
ENTRY_BEGIN
	MATCH all ttl
	REPLY QR RD RA NOERROR
	SECTION QUESTION
		example.com. IN A
	SECTION ANSWER
		example.com. 0 IN A 5.6.7.8
	SECTION AUTHORITY
		example.com.  0 IN NS ns.example.com.
	SECTION ADDITIONAL
		ns.example.com. 0 IN A 1.2.3.4
ENTRY_END

; Let some time to pass
STEP 11 TIME_PASSES ELAPSE 1

; Query with RD flag
STEP 20 QUERY
ENTRY_BEGIN
	REPLY RD
	SECTION QUESTION
		example.com. IN A
ENTRY_END

; Check that we got the correct answer
STEP 29 CHECK_ANSWER
ENTRY_BEGIN
	MATCH all ttl
	REPLY QR RD RA NOERROR
	SECTION QUESTION
		example.com. IN A
	SECTION ANSWER
		example.com. 10 IN A 5.6.7.8
	SECTION AUTHORITY
		example.com. 10 IN NS ns.example.com.
	SECTION ADDITIONAL
		ns.example.com. 10 IN A 1.2.3.4
ENTRY_END

; Wait for the TTL to expire
STEP 30 TIME_PASSES ELAPSE 11

; Query with RD flag
STEP 40 QUERY
ENTRY_BEGIN
	REPLY RD
	SECTION QUESTION
		example.com. IN A
ENTRY_END

; Check that we got the correct answer
STEP 49 CHECK_ANSWER
ENTRY_BEGIN
	MATCH all ttl
	REPLY QR RD RA NOERROR
	SECTION QUESTION
		example.com. IN A
	SECTION ANSWER
		example.com. 123 IN A 5.6.7.8
	SECTION AUTHORITY
		example.com. 123 IN NS ns.example.com.
	SECTION ADDITIONAL
		ns.example.com. 123 IN A 1.2.3.4
ENTRY_END

; Give time for the pending query to get answered
STEP 50 TRAFFIC

SCENARIO_END
