Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
varnishtest "Redis VMOD and strings containing NULL chars"
shell {
python - <<EOF
import base64
import redis
b64 = 'X3NmMl9hdHRyaWJ1dGVzfGE6Mjp7czo1OiJsaWtlZCI7YTowOnt9czoxNDoiX3NlY3VyaXR5X21haW4iO3M6OTAzOiJDOjc0OiJTeW1mb255XENvbXBvbmVudFxTZWN1cml0eVxDb3JlXEF1dGhlbnRpY2F0aW9uXFRva2VuXFVzZXJuYW1lUGFzc3dvcmRUb2tlbiI6ODE1OnthOjM6e2k6MDtOO2k6MTtzOjQ6Im1haW4iO2k6MjthOjQ6e2k6MDtPOjQxOiJTeW1mb255XENvbXBvbmVudFxTZWN1cml0eVxDb3JlXFVzZXJcVXNlciI6Nzp7czo1MToiAFN5bWZvbnlcQ29tcG9uZW50XFNlY3VyaXR5XENvcmVcVXNlclxVc2VyAHVzZXJuYW1lIjtzOjU6InRoaWpzIjtzOjUxOiIAU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxVc2VyXFVzZXIAcGFzc3dvcmQiO3M6NjA6IiQyeSQxMiQxaUVVNVJ0REZUQkptMGhocXpZR2NPamdSTFhXUGlPQjYzS2VFVVhNNXA5bFFLejlFeklUQyI7czo1MDoiAFN5bWZvbnlcQ29tcG9uZW50XFNlY3VyaXR5XENvcmVcVXNlclxVc2VyAGVuYWJsZWQiO2I6MTtzOjYwOiIAU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxVc2VyXFVzZXIAYWNjb3VudE5vbkV4cGlyZWQiO2I6MTtzOjY0OiIAU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxVc2VyXFVzZXIAY3JlZGVudGlhbHNOb25FeHBpcmVkIjtiOjE7czo1OToiAFN5bWZvbnlcQ29tcG9uZW50XFNlY3VyaXR5XENvcmVcVXNlclxVc2VyAGFjY291bnROb25Mb2NrZWQiO2I6MTtzOjQ4OiIAU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxVc2VyXFVzZXIAcm9sZXMiO2E6MTp7aTowO3M6MTA6IlJPTEVfQURNSU4iO319aToxO2I6MTtpOjI7YToxOntpOjA7Tzo0MToiU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxSb2xlXFJvbGUiOjE6e3M6NDc6IgBTeW1mb255XENvbXBvbmVudFxTZWN1cml0eVxDb3JlXFJvbGVcUm9sZQByb2xlIjtzOjEwOiJST0xFX0FETUlOIjt9fWk6MzthOjA6e319fX0iO31fc2YyX21ldGF8YTozOntzOjE6InUiO2k6MTU2Mjc1MzI0NDtzOjE6ImMiO2k6MTU2Mjc1MzIzOTtzOjE6ImwiO3M6MToiMCI7fQ=='
r = redis.Redis(host='localhost', port=6379, db=0)
r.set('foo', base64.b64decode(b64))
EOF
}
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl {
import redis;
backend s1 {
.host = "${s1_addr}";
.port = "${s1_port}";
}
sub vcl_init {
new db = redis.db(location="127.0.0.1:6379", type=master);
}
sub vcl_deliver {
db.command("GET");
db.push("foo");
db.execute();
if (db.reply_is_string()) {
set resp.http.Reply-1 = db.get_string_reply();
}
db.command("EVAL");
db.push({"
return string.gsub(redis.call('GET', KEYS[1]),'[%c]','')
"});
db.push("1");
db.push("foo");
db.execute();
if (db.reply_is_string()) {
set resp.http.Reply-2 = db.get_string_reply();
}
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Reply-1 !~ "thijs"
expect resp.http.Reply-2 ~ "thijs"
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.