varnishtest "Test address remapping"

feature persistent_storage

feature disable_aslr

# VM-remapping is too random on OSX
feature	!OSX
# Same on some hardened Linux
feature cmd "test ! -c /dev/grsec"

server s1 {
	rxreq
	txresp
} -start

shell "rm -f ${tmpdir}/_.per?"

varnish v1 \
	-arg "-pfeature=+wait_silo" \
	-arg "-sdeprecated_persistent,${tmpdir}/_.per1,5m" \
	-arg "-sdeprecated_persistent,${tmpdir}/_.per2,5m" \
	-syntax 4.0 \
	-vcl+backend {
	sub vcl_backend_response {
		set beresp.storage = storage.s0;
	}
} -start

varnish v1 -stop

varnish v1 -start

client c1 {
	txreq -url "/"
	rxresp
	expect resp.status == 200
	expect resp.http.X-Varnish == "1001"
} -run

varnish v1 -cliok "storage.list"
varnish v1 -cliok "debug.persistent s0 dump"
varnish v1 -cliok "debug.persistent s0 sync"
varnish v1 -stop

server s1 {
	rxreq
	txresp -status 400 -reason "Persistent Object Not Found"
} -start


varnish v2 \
	-arg "-pfeature=+wait_silo" \
	-arg "-sdeprecated_persistent,${tmpdir}/_.per2,5m" \
	-arg "-sdeprecated_persistent,${tmpdir}/_.per1,5m" \
	-vcl+backend { } -start

client c1 -connect ${v2_sock} {
	txreq -url "/"
	rxresp
	expect resp.reason != "Persistent Object Not Found"
	expect resp.status == 200
	expect resp.http.X-Varnish == "1001 1002"
} -run

# shell "rm -f /tmp/__v1/_.per"
