fix(webconnectivity): ignore any status code <= 0 (#579)
This diff changes the algorithm used by webconnectivity's httpanalysis.go to ignore any status code <= 0 rather than just ignoring the == 0 case. Make sure we add test cases for when the control's status code is negative rather than being zero. While there, simplify code where boolean checks could be more compact according to staticcheck. Closes https://github.com/ooni/probe/issues/1825
This commit is contained in:
parent
5b8f4546f3
commit
3b27780836
3 changed files with 82 additions and 8 deletions
|
|
@ -80,14 +80,14 @@ func HTTPStatusCodeMatch(tk urlgetter.TestKeys, ctrl ControlResponse) (out *bool
|
|||
return // no real status code
|
||||
}
|
||||
measurement := tk.Requests[0].Response.Code
|
||||
if control == 0 {
|
||||
if control <= 0 {
|
||||
return // no real status code
|
||||
}
|
||||
if measurement == 0 {
|
||||
if measurement <= 0 {
|
||||
return // no real status code
|
||||
}
|
||||
value := control == measurement
|
||||
if value == true {
|
||||
if value {
|
||||
// if the status codes are equal, they clearly match
|
||||
out = &value
|
||||
return
|
||||
|
|
@ -110,10 +110,10 @@ func HTTPHeadersMatch(tk urlgetter.TestKeys, ctrl ControlResponse) *bool {
|
|||
if len(tk.Requests) <= 0 {
|
||||
return nil
|
||||
}
|
||||
if tk.Requests[0].Response.Code == 0 {
|
||||
if tk.Requests[0].Response.Code <= 0 {
|
||||
return nil
|
||||
}
|
||||
if ctrl.HTTPRequest.StatusCode == 0 {
|
||||
if ctrl.HTTPRequest.StatusCode <= 0 {
|
||||
return nil
|
||||
}
|
||||
control := ctrl.HTTPRequest.Headers
|
||||
|
|
@ -203,13 +203,13 @@ func HTTPTitleMatch(tk urlgetter.TestKeys, ctrl ControlResponse) (out *bool) {
|
|||
return
|
||||
}
|
||||
response := tk.Requests[0].Response
|
||||
if response.Code == 0 {
|
||||
if response.Code <= 0 {
|
||||
return
|
||||
}
|
||||
if response.BodyIsTruncated {
|
||||
return
|
||||
}
|
||||
if ctrl.HTTPRequest.StatusCode == 0 {
|
||||
if ctrl.HTTPRequest.StatusCode <= 0 {
|
||||
return
|
||||
}
|
||||
control := ctrl.HTTPRequest.Title
|
||||
|
|
|
|||
Loading…
Reference in a new issue