Commit 699924dc authored by Geoff Simmons's avatar Geoff Simmons

add a test for match options

parent c8aed294
# looks like -*- vcl -*-
varnishtest "match options"
# tests mostly from pcre2 testinput2
# offset_limit tested in compile_opts.vtc
# XXX
# - match_limit test results differ for jit or non-jit
# - recursion_limit is only relevant without jit
# - dfa matching, jit fast path, partial matching and start_offset not
# implemented yet
# - option to decide whether to save options in PRIV_CALL?
# - no_utf_check tests depend on whether utf is enabled
# - no_jit depends on whether jit is enabled
# len
varnish v1 -vcl {
import pcre2 from "${vmod_topbuild}/src/.libs/libvmod_pcre2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new r = pcre2.regex("abc");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.r1 = r.match("defabc");
set resp.http.r2 = r.match("defabc", len=3);
}
} -start
client c1 -repeat 2 {
txreq
rxresp
expect resp.status == "200"
expect resp.http.r1 == "true"
expect resp.http.r2 == "false"
} -run
# anchored
varnish v1 -vcl {
import pcre2 from "${vmod_topbuild}/src/.libs/libvmod_pcre2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new r1 = pcre2.regex("abc");
new r2 = pcre2.regex("\Biss\B");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.r1-1 = r1.match("defabc");
set resp.http.r1-2 = r1.match("defabc", anchored=true);
set resp.http.r2-1 = r2.match("Mississippi");
set resp.http.r2-2 = r2.match("Mississippi", anchored=true);
}
}
client c1 -repeat 2 {
txreq
rxresp
expect resp.status == "200"
expect resp.http.r1-1 == "true"
expect resp.http.r1-2 == "false"
expect resp.http.r2-1 == "true"
expect resp.http.r2-2 == "false"
} -run
# notbol
varnish v1 -vcl {
import pcre2 from "${vmod_topbuild}/src/.libs/libvmod_pcre2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new r = pcre2.regex("^X");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.r1 = r.match("XABC");
set resp.http.r2 = r.match("XABC", notbol=true);
}
}
client c1 -repeat 2 {
txreq
rxresp
expect resp.status == "200"
expect resp.http.r1 == "true"
expect resp.http.r2 == "false"
} -run
# noteol
varnish v1 -vcl {
import pcre2 from "${vmod_topbuild}/src/.libs/libvmod_pcre2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new r = pcre2.regex("a$");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.r1 = r.match("a");
set resp.http.r2 = r.match({"a
"});
set resp.http.r3 = r.match("a", noteol=true);
set resp.http.r4 = r.match(noteol=true, subject={"a
"});
}
}
client c1 -repeat 2 {
txreq
rxresp
expect resp.status == "200"
expect resp.http.r1 == "true"
expect resp.http.r2 == "true"
expect resp.http.r3 == "false"
expect resp.http.r4 == "false"
} -run
# notempty
varnish v1 -vcl {
import pcre2 from "${vmod_topbuild}/src/.libs/libvmod_pcre2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new r1 = pcre2.regex("a?b?");
new r2 = pcre2.regex("|-");
new r3 = pcre2.regex("(?>(*ACCEPT)b)c");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.r1-1 = r1.match("");
set resp.http.r1-2 = r1.match("", notempty=true);
set resp.http.r2-1 = r2.match("");
set resp.http.r2-2 = r2.match("", notempty=true);
set resp.http.r3-1 = r3.match("");
set resp.http.r3-2 = r3.match("c", notempty=true);
}
}
client c1 -repeat 2 {
txreq
rxresp
expect resp.status == "200"
expect resp.http.r1-1 == "true"
expect resp.http.r1-2 == "false"
expect resp.http.r2-1 == "true"
expect resp.http.r2-2 == "false"
expect resp.http.r3-1 == "true"
expect resp.http.r3-2 == "false"
} -run
# notempty_atstart
varnish v1 -vcl {
import pcre2 from "${vmod_topbuild}/src/.libs/libvmod_pcre2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new r = pcre2.regex("^a?b?");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.r1 = r.match("xyz");
set resp.http.r2 = r.match("xyz", notempty_atstart=true);
set resp.http.r3 = r.match("xyzabc");
set resp.http.r4 = r.match("xyzabc", notempty_atstart=true);
}
}
client c1 -repeat 2 {
txreq
rxresp
expect resp.status == "200"
expect resp.http.r1 == "true"
expect resp.http.r2 == "false"
expect resp.http.r3 == "true"
expect resp.http.r4 == "false"
} -run
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment