Commit 2de6a957 authored by Nils Goroll's avatar Nils Goroll Committed by Lasse Karstensen

varnishtest: fail inequality comparisons if either side is undef'ed

e.g. <undef> >= 0.1 should fail for being an invalid comparison

Conflicts:
	bin/varnishtest/tests/v00013.vtc
parent e73be760
...@@ -37,5 +37,9 @@ client c1 { ...@@ -37,5 +37,9 @@ client c1 {
rxresp rxresp
expect resp.status == 200 expect resp.status == 200
expect resp.http.foo == 2 expect resp.http.foo == 2
expect resp.http.bar >= 0.100
txreq -url /pass
rxresp
expect resp.status == 200
expect resp.http.foo == 0
} -run } -run
...@@ -224,18 +224,16 @@ cmd_var_resolve(struct http *hp, char *spec) ...@@ -224,18 +224,16 @@ cmd_var_resolve(struct http *hp, char *spec)
} else } else
return (spec); return (spec);
hdr = http_find_header(hh, hdr); hdr = http_find_header(hh, hdr);
if (hdr != NULL) return (hdr);
return (hdr);
return ("<undef>");
} }
static void static void
cmd_http_expect(CMD_ARGS) cmd_http_expect(CMD_ARGS)
{ {
struct http *hp; struct http *hp;
const char *lhs; const char *lhs, *clhs;
char *cmp; char *cmp;
const char *rhs; const char *rhs, *crhs;
vre_t *vre; vre_t *vre;
const char *error; const char *error;
int erroroffset; int erroroffset;
...@@ -252,14 +250,27 @@ cmd_http_expect(CMD_ARGS) ...@@ -252,14 +250,27 @@ cmd_http_expect(CMD_ARGS)
AN(av[2]); AN(av[2]);
AZ(av[3]); AZ(av[3]);
lhs = cmd_var_resolve(hp, av[0]); lhs = cmd_var_resolve(hp, av[0]);
if (lhs == NULL)
lhs = "<missing>";
cmp = av[1]; cmp = av[1];
rhs = cmd_var_resolve(hp, av[2]); rhs = cmd_var_resolve(hp, av[2]);
if (rhs == NULL)
rhs = "<missing>"; clhs = lhs ? lhs : "<undef>";
if (!strcmp(cmp, "==")) { crhs = rhs ? rhs : "<undef>";
retval = strcmp(lhs, rhs) == 0;
if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
vre = VRE_compile(crhs, 0, &error, &erroroffset);
if (vre == NULL)
vtc_log(hp->vl, 0, "REGEXP error: %s (@%d) (%s)",
error, erroroffset, crhs);
i = VRE_exec(vre, clhs, strlen(clhs), 0, 0, NULL, 0, 0);
retval = (i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!');
VRE_free(&vre);
} else if (!strcmp(cmp, "==")) {
retval = strcmp(clhs, crhs) == 0;
} else if (!strcmp(cmp, "!=")) {
retval = strcmp(clhs, crhs) != 0;
} else if (lhs == NULL || rhs == NULL) {
// fail inequality comparisons if either side is undef'ed
retval = 0;
} else if (!strcmp(cmp, "<")) { } else if (!strcmp(cmp, "<")) {
retval = strcmp(lhs, rhs) < 0; retval = strcmp(lhs, rhs) < 0;
} else if (!strcmp(cmp, "<=")) { } else if (!strcmp(cmp, "<=")) {
...@@ -268,24 +279,15 @@ cmd_http_expect(CMD_ARGS) ...@@ -268,24 +279,15 @@ cmd_http_expect(CMD_ARGS)
retval = strcmp(lhs, rhs) >= 0; retval = strcmp(lhs, rhs) >= 0;
} else if (!strcmp(cmp, ">")) { } else if (!strcmp(cmp, ">")) {
retval = strcmp(lhs, rhs) > 0; retval = strcmp(lhs, rhs) > 0;
} else if (!strcmp(cmp, "!=")) {
retval = strcmp(lhs, rhs) != 0;
} else if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
vre = VRE_compile(rhs, 0, &error, &erroroffset);
if (vre == NULL)
vtc_log(hp->vl, 0, "REGEXP error: %s (@%d) (%s)",
error, erroroffset, rhs);
i = VRE_exec(vre, lhs, strlen(lhs), 0, 0, NULL, 0, 0);
retval = (i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!');
VRE_free(&vre);
} }
if (retval == -1) if (retval == -1)
vtc_log(hp->vl, 0, vtc_log(hp->vl, 0,
"EXPECT %s (%s) %s %s (%s) test not implemented", "EXPECT %s (%s) %s %s (%s) test not implemented",
av[0], lhs, av[1], av[2], rhs); av[0], clhs, av[1], av[2], crhs);
else else
vtc_log(hp->vl, retval ? 4 : 0, "EXPECT %s (%s) %s \"%s\" %s", vtc_log(hp->vl, retval ? 4 : 0, "EXPECT %s (%s) %s \"%s\" %s",
av[0], lhs, cmp, rhs, retval ? "match" : "failed"); av[0], clhs, cmp, crhs, retval ? "match" : "failed");
} }
/********************************************************************** /**********************************************************************
......
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