@@ -205,9 +205,10 @@ func TestParseVariablesLeavesMissingValuesUnset(t *testing.T) {
205205func TestParseVariablesCapturesBodyRegex (t * testing.T ) {
206206 variables := map [string ]string {}
207207 err := parseVariables (
208- []byte (`<a href="/password-reset/abc123">reset</a>` ),
208+ []byte (`<a href="/password-reset/abc123?next= ">reset</a>` ),
209209 []api.HTTPRequestResponseVariable {
210210 {Name : "resetToken" , BodyRegex : `/password-reset/([a-z0-9]+)` },
211+ {Name : "nextPath" , BodyRegex : `next=([^"]*)` },
211212 },
212213 variables ,
213214 )
@@ -217,6 +218,9 @@ func TestParseVariablesCapturesBodyRegex(t *testing.T) {
217218 if variables ["resetToken" ] != "abc123" {
218219 t .Fatalf ("resetToken = %q, want abc123" , variables ["resetToken" ])
219220 }
221+ if nextPath , ok := variables ["nextPath" ]; ! ok || nextPath != "" {
222+ t .Fatalf ("nextPath = %q, %t, want empty string, true" , nextPath , ok )
223+ }
220224}
221225
222226func TestParseVariablesRequiresCaptureSource (t * testing.T ) {
@@ -237,9 +241,13 @@ func TestParseVariablesRequiresCaptureSource(t *testing.T) {
237241func TestParseHeaderVariablesLeavesMissingValuesUnset (t * testing.T ) {
238242 variables := map [string ]string {}
239243 err := parseHeaderVariables (
240- map [string ]string {"Set-Cookie" : "session_id=abc123; Path=/; HttpOnly" },
244+ map [string ]string {
245+ "Set-Cookie" : "session_id=abc123; Path=/; HttpOnly" ,
246+ "Location" : "/login?next=" ,
247+ },
241248 []api.HTTPRequestResponseHeaderVariable {
242249 {Name : "sessionID" , Header : "Set-Cookie" , Regex : "session_id=([^;]+)" },
250+ {Name : "nextPath" , Header : "Location" , Regex : "next=([^&]*)" },
243251 {Name : "missingHeader" , Header : "X-Missing" },
244252 {Name : "missingMatch" , Header : "Set-Cookie" , Regex : "missing=([^;]+)" },
245253 },
@@ -251,6 +259,9 @@ func TestParseHeaderVariablesLeavesMissingValuesUnset(t *testing.T) {
251259 if variables ["sessionID" ] != "abc123" {
252260 t .Fatalf ("sessionID = %q, want abc123" , variables ["sessionID" ])
253261 }
262+ if nextPath , ok := variables ["nextPath" ]; ! ok || nextPath != "" {
263+ t .Fatalf ("nextPath = %q, %t, want empty string, true" , nextPath , ok )
264+ }
254265 if _ , ok := variables ["missingHeader" ]; ok {
255266 t .Fatalf ("expected missing header variable to remain unset" )
256267 }
0 commit comments