varnishtest "Test vcl ban()"

# see also v00009.vtc

server s1 {
	rxreq
	txresp -body "foo"

	rxreq
	txresp -body "foo"
} -start

varnish v1 -vcl+backend {
	sub vcl_recv {
		if (req.method == "BAN") {
			ban(req.http.doesntexist);
			ban("");
			ban("req.url");
			ban("req.url //");
			ban("req.url // bar");
			ban("req.url == bar //");
			ban("foo == bar //");
			ban("obj.age == 4");
			ban("obj.age // 4d");
			ban("obj.http.foo > 4d");
			ban("req.url ~ ^/$");
			return (synth(209,"foo"));
		}
	}

} -start

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

logexpect l1 -v v1 -d 1 -g vxid {
	expect * 1004	VCL_Error {ban[(][)]: Null argument}
	expect * 1004	VCL_Error {ban[(][)]: No ban conditions found[.]}
	expect * 1004	VCL_Error {ban[(][)]: Expected comparison operator[.]}
	expect * 1004	VCL_Error {ban[(][)]: Expected second operand[.]}
	expect * 1004	VCL_Error {ban[(][)]: expected conditional [(]==, !=, ~ or !~[)] got "//"}
	expect * 1004	VCL_Error {ban[(][)]: Expected && between conditions, found "//"}
	expect * 1004	VCL_Error {ban[(][)]: Unknown or unsupported field "foo"}
	expect * 1004	VCL_Error {ban[(][)]: expected duration <n.nn>.ms|s|m|h|d|w|y. got "4"}
	expect * 1004	VCL_Error {ban[(][)]: expected conditional [(]==, !=, >, >=, < or <=[)] got "//"}
	expect * 1004	VCL_Error {ban[(][)]: expected conditional [(]==, !=, ~ or !~[)] got ">"}


} -start

client c1 {
	txreq -req "BAN"
	rxresp
	expect resp.http.X-Varnish == "1004"
	expect resp.status == 209
} -run

logexpect l1 -wait

client c1 {
	txreq
	rxresp
	expect resp.http.X-Varnish == "1006"
} -run
