diff --git a/checks/http.go b/checks/http.go
index 953d0d9..e9a0340 100644
--- a/checks/http.go
+++ b/checks/http.go
@@ -215,7 +215,7 @@ func parseVariables(body []byte, vardefs []api.HTTPRequestResponseVariable, vari
return fmt.Errorf("invalid response body variable configuration")
}
matches := re.FindStringSubmatch(bodyString)
- if len(matches) == 2 && matches[1] != "" {
+ if len(matches) == 2 {
variables[vardef.Name] = matches[1]
}
@@ -254,7 +254,7 @@ func parseHeaderVariables(headers map[string]string, vardefs []api.HTTPRequestRe
}
matches := re.FindStringSubmatch(headerValue)
- if len(matches) != 2 || matches[1] == "" {
+ if len(matches) != 2 {
continue
}
value = matches[1]
diff --git a/checks/http_test.go b/checks/http_test.go
index a7bfd1b..c552faa 100644
--- a/checks/http_test.go
+++ b/checks/http_test.go
@@ -205,9 +205,10 @@ func TestParseVariablesLeavesMissingValuesUnset(t *testing.T) {
func TestParseVariablesCapturesBodyRegex(t *testing.T) {
variables := map[string]string{}
err := parseVariables(
- []byte(`reset`),
+ []byte(`reset`),
[]api.HTTPRequestResponseVariable{
{Name: "resetToken", BodyRegex: `/password-reset/([a-z0-9]+)`},
+ {Name: "nextPath", BodyRegex: `next=([^"]*)`},
},
variables,
)
@@ -217,6 +218,9 @@ func TestParseVariablesCapturesBodyRegex(t *testing.T) {
if variables["resetToken"] != "abc123" {
t.Fatalf("resetToken = %q, want abc123", variables["resetToken"])
}
+ if nextPath, ok := variables["nextPath"]; !ok || nextPath != "" {
+ t.Fatalf("nextPath = %q, %t, want empty string, true", nextPath, ok)
+ }
}
func TestParseVariablesRequiresCaptureSource(t *testing.T) {
@@ -237,9 +241,13 @@ func TestParseVariablesRequiresCaptureSource(t *testing.T) {
func TestParseHeaderVariablesLeavesMissingValuesUnset(t *testing.T) {
variables := map[string]string{}
err := parseHeaderVariables(
- map[string]string{"Set-Cookie": "session_id=abc123; Path=/; HttpOnly"},
+ map[string]string{
+ "Set-Cookie": "session_id=abc123; Path=/; HttpOnly",
+ "Location": "/login?next=",
+ },
[]api.HTTPRequestResponseHeaderVariable{
{Name: "sessionID", Header: "Set-Cookie", Regex: "session_id=([^;]+)"},
+ {Name: "nextPath", Header: "Location", Regex: "next=([^&]*)"},
{Name: "missingHeader", Header: "X-Missing"},
{Name: "missingMatch", Header: "Set-Cookie", Regex: "missing=([^;]+)"},
},
@@ -251,6 +259,9 @@ func TestParseHeaderVariablesLeavesMissingValuesUnset(t *testing.T) {
if variables["sessionID"] != "abc123" {
t.Fatalf("sessionID = %q, want abc123", variables["sessionID"])
}
+ if nextPath, ok := variables["nextPath"]; !ok || nextPath != "" {
+ t.Fatalf("nextPath = %q, %t, want empty string, true", nextPath, ok)
+ }
if _, ok := variables["missingHeader"]; ok {
t.Fatalf("expected missing header variable to remain unset")
}