Commit a3ee09b8 authored by Nils Goroll's avatar Nils Goroll

fix the tiny bit necessary for PRIV_* to work with methods and add tests

... demonstrating that the PRIV_* states are per vmod, no matter if accessed
from a function or method

Fixes #1800

part of #2061
parent 811c0c54
......@@ -10,6 +10,10 @@ varnish v1 -vcl+backend {
import std;
import debug;
sub vcl_init {
new obj = debug.obj();
}
sub vcl_recv {
debug.rot52(req);
}
......@@ -20,6 +24,8 @@ varnish v1 -vcl+backend {
set resp.http.who = debug.author(phk);
debug.test_priv_call();
debug.test_priv_vcl();
obj.test_priv_call();
obj.test_priv_vcl();
std.log("VCL" + " initiated " + "log");
std.syslog(8 + 7, "Somebody runs varnishtest");
debug.rot52(resp);
......
......@@ -11,10 +11,15 @@ varnish v1 -vcl+backend {
import debug;
import std;
sub vcl_init {
new obj = debug.obj();
}
sub vcl_init {
debug.test_priv_task("something");
debug.test_priv_task("to remember");
std.log(debug.test_priv_task());
std.log("func " + debug.test_priv_task());
std.log("obj " + obj.test_priv_task());
}
sub vcl_recv {
......@@ -26,9 +31,11 @@ varnish v1 -vcl+backend {
sub vcl_deliver {
set resp.http.x0 = req.http.x0;
set resp.http.x1 = debug.test_priv_task();
set resp.http.o1 = obj.test_priv_task();
}
sub vcl_backend_fetch {
obj.test_priv_task("b");
std.log("foo");
set bereq.http.bx0 = debug.test_priv_task(bereq.url);
std.log("bar");
......@@ -37,23 +44,25 @@ varnish v1 -vcl+backend {
sub vcl_backend_response {
set beresp.http.bx0 = bereq.http.bx0;
set beresp.http.bx1 = debug.test_priv_task("");
set beresp.http.bo1 = obj.test_priv_task("");
}
} -start
logexpect l1 -v v1 -g raw -d 1 {
expect 0 0 CLI {^Rd vcl.load}
expect 0 = VCL_Log {^something to remember}
expect 0 = VCL_Log {^func something to remember}
expect 0 = VCL_Log {^obj something to remember}
expect * 1002 Begin fetch$
expect * = VCL_call ^BACKEND_FETCH
expect 0 = VCL_Log ^foo
expect 0 = BereqHeader {^bx0: /foobar}
expect 0 = BereqHeader {^bx0: b /foobar}
expect 0 = VCL_Log ^bar
expect * 1004 Begin fetch$
expect * = VCL_call ^BACKEND_FETCH
expect 0 = VCL_Log ^foo
expect 0 = BereqHeader {^bx0: /snafu}
expect 0 = BereqHeader {^bx0: b /snafu}
expect 0 = VCL_Log ^bar
} -start
......@@ -62,15 +71,19 @@ client c1 {
rxresp
expect resp.http.x0 == /foobar
expect resp.http.x1 == "/foobar bazz"
expect resp.http.bx0 == /foobar
expect resp.http.bx1 == /foobar
expect resp.http.o1 == "/foobar bazz"
expect resp.http.bx0 == "b /foobar"
expect resp.http.bx1 == "b /foobar"
expect resp.http.bo1 == "b /foobar"
txreq -url /snafu
rxresp
expect resp.http.x0 == /snafu
expect resp.http.x1 == "/snafu bazz"
expect resp.http.bx0 == /snafu
expect resp.http.bx1 == /snafu
expect resp.http.o1 == "/snafu bazz"
expect resp.http.bx0 == "b /snafu"
expect resp.http.bx1 == "b /snafu"
expect resp.http.bo1 == "b /snafu"
} -run
logexpect l1 -wait
......@@ -36,6 +36,10 @@ server s1 {
varnish v1 -vcl+backend {
import debug;
sub vcl_init {
new o = debug.obj();
}
sub vcl_recv {
set req.http.x0 = debug.test_priv_task(req.url + req.esi_level);
}
......@@ -51,6 +55,7 @@ varnish v1 -vcl+backend {
sub vcl_deliver {
set resp.http.x1 = debug.test_priv_task("");
set resp.http.o1 = o.test_priv_task("");
}
} -start
......@@ -59,10 +64,12 @@ client c1 {
txreq -url /a
rxresp
expect resp.http.x1 == "/a0"
expect resp.http.o1 == "/a0"
txreq -url /b
rxresp
expect resp.http.x1 == "/b0"
expect resp.http.o1 == "/b0"
} -run
varnish v1 -expect s_req == 2
......@@ -38,6 +38,10 @@ server s1 {
varnish v1 -cliok "param.set debug +syncvsl" -vcl+backend {
import debug;
sub vcl_init {
new o = debug.obj();
}
sub vcl_recv {
set req.http.x0 = debug.test_priv_top(req.url + req.esi_level);
}
......@@ -53,6 +57,7 @@ varnish v1 -cliok "param.set debug +syncvsl" -vcl+backend {
sub vcl_deliver {
set resp.http.x1 = debug.test_priv_top("");
set resp.http.o1 = o.test_priv_top("");
}
} -start
......@@ -61,10 +66,12 @@ client c1 {
txreq -url /a
rxresp
expect resp.http.x1 == "/a0"
expect resp.http.o1 == "/a0"
txreq -url /b
rxresp
expect resp.http.x1 == "/b0"
expect resp.http.o1 == "/b0"
} -run
varnish v1 -expect s_req == 2
......@@ -333,6 +333,7 @@ vcc_ParseNew(struct vcc *tl)
sy3->eval_priv = p;
sy3->fmt = VCC_Type(p);
sy3->extra = TlDup(tl, buf1);
sy3->vmod = sy2->vmod;
while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
p++;
p += 3;
......
......@@ -97,6 +97,29 @@ $Method TIME .date()
You never know when you need a date.
$Method VOID .test_priv_call(PRIV_CALL)
Test method for call private pointers
Objects share the PRIV_* state with other objects and methods from the
same vmod - IOW the PRIV_* state is per vmod, not per object.
$Method VOID .test_priv_vcl(PRIV_VCL)
Test method for VCL private pointers
Objects share the PRIV_* state with other objects and methods from the
same vmod - IOW the PRIV_* state is per vmod, not per object.
$Method STRING .test_priv_task(PRIV_TASK, STRING s="")
Test method for TASK private pointers
Objects share the PRIV_* state with other objects and methods from the
same vmod - IOW the PRIV_* state is per vmod, not per object.
$Method STRING .test_priv_top(PRIV_TOP, STRING)
$Function VOID rot52(HTTP hdr)
Encrypt the HTTP header with quad-ROT13 encryption,
......
......@@ -120,3 +120,32 @@ vmod_obj_number(VRT_CTX, struct vmod_debug_obj *o)
assert(o->foobar == 42);
return (o->number);
}
VCL_VOID __match_proto__()
vmod_obj_test_priv_call(VRT_CTX,
struct vmod_debug_obj *o, struct vmod_priv *priv)
{
(void) o;
vmod_test_priv_call(ctx, priv);
}
VCL_VOID __match_proto__()
vmod_obj_test_priv_vcl(VRT_CTX,
struct vmod_debug_obj *o, struct vmod_priv *priv)
{
(void) o;
vmod_test_priv_vcl(ctx, priv);
}
VCL_STRING __match_proto__()
vmod_obj_test_priv_task(VRT_CTX,
struct vmod_debug_obj *o, struct vmod_priv *priv, VCL_STRING s)
{
(void) o;
return (vmod_test_priv_task(ctx, priv, s));
}
VCL_STRING __match_proto__()
vmod_obj_test_priv_top(VRT_CTX,
struct vmod_debug_obj *o, struct vmod_priv *priv, VCL_STRING s)
{
(void) o;
return (vmod_test_priv_top(ctx, priv, s));
}
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