varnishtest "Test include vs. unsafe_path and include glob-ing"

server s1 {
	rxreq
	txresp
} -start

shell "echo > ${tmpdir}/_.c00053"

varnish v1 -vcl+backend {
	include "${tmpdir}/_.c00053";
}

varnish v1 -cliok "param.set vcc_feature -unsafe_path"

varnish v1 -errvcl {' is unsafe} {
	backend default { .host = "${s1_sock}"; }
	include "${tmpdir}/_.c00053";
}

varnish v1 -cliok "param.set vcl_path ${tmpdir}"

varnish v1 -vcl+backend {
	include "_.c00053";
}

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

# Testing of include +glob

varnish v1 -cliok "param.set vcc_feature +unsafe_path"

varnish v1 -errvcl "glob pattern matched no files." {
	vcl 4.0;

	include +glob "${tmpdir}/Q*.vcl";
}

shell {
	echo 'sub vcl_deliver { set resp.http.foo = "foo"; }' > ${tmpdir}/sub_foo.vcl
	echo 'sub vcl_deliver { set resp.http.bar = "bar"; }' > ${tmpdir}/sub_bar.vcl
	echo 'vcl 4.0; backend default { .host = "0:0"; } include +glob "./sub_*.vcl";' > ${tmpdir}/top.vcl
}

varnish v1 -vcl+backend {
	include +glob "${tmpdir}/sub_*.vcl";
} -start

client c1 {
	txreq
	rxresp
	expect resp.http.foo == foo
	expect resp.http.bar == bar
} -run

varnish v1 -errvcl {needs absolute filename of including file.} {
	include +glob "./sub_*.vcl";
	backend default none;
}

varnish v1 -cliok "vcl.load foo ${tmpdir}/top.vcl"
varnish v1 -cliok "vcl.use foo"

client c1 {
	txreq
	rxresp
	expect resp.http.foo == foo
	expect resp.http.bar == bar
} -run
