-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webconnectivityqa): port jafar's http-diff test cases (#1242)
## Checklist - [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md) - [x] reference issue for this pull request: ooni/probe#1803 - [x] if you changed anything related to how experiments work and you need to reflect these changes in the ooni/spec repository, please link to the related ooni/spec pull request: N/A - [x] if you changed code inside an experiment, make sure you bump its version number: N/A ## Description This diff ports jafar's http-diff test cases to webconnectivityqa.
- Loading branch information
1 parent
db7c7cf
commit e14895a
Showing
7 changed files
with
284 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package webconnectivityqa | ||
|
||
import ( | ||
"github.com/apex/log" | ||
"github.com/ooni/netem" | ||
"github.com/ooni/probe-cli/v3/internal/netemx" | ||
) | ||
|
||
// httpDiffWithConsistentDNS verifies the case where there is an HTTP diff | ||
// but the addresses returned by the DNS resolver are consistent. | ||
func httpDiffWithConsistentDNS() *TestCase { | ||
return &TestCase{ | ||
Name: "httpDiffWithConsistentDNS", | ||
Flags: TestCaseFlagNoLTE, // BUG: LTE does not set whether the headers match | ||
Input: "http://www.example.com/", | ||
Configure: func(env *netemx.QAEnv) { | ||
|
||
// spoof the blockpage | ||
env.DPIEngine().AddRule(&netem.DPISpoofBlockpageForString{ | ||
HTTPResponse: netem.DPIFormatHTTPResponse([]byte(netemx.Blockpage)), | ||
Logger: log.Log, | ||
ServerIPAddress: netemx.AddressWwwExampleCom, | ||
ServerPort: 80, | ||
String: "www.example.com", | ||
}) | ||
|
||
}, | ||
ExpectErr: false, | ||
ExpectTestKeys: &testKeys{ | ||
DNSExperimentFailure: nil, | ||
DNSConsistency: "consistent", | ||
BodyLengthMatch: false, | ||
BodyProportion: 0.12263535551206783, | ||
StatusCodeMatch: true, | ||
HeadersMatch: false, | ||
TitleMatch: false, | ||
HTTPExperimentFailure: nil, | ||
XStatus: 64, // StatusAnomalyHTTPDiff | ||
XDNSFlags: 0, | ||
XBlockingFlags: 16, // analysisFlagHTTPDiff | ||
Accessible: false, | ||
Blocking: "http-diff", | ||
}, | ||
} | ||
} | ||
|
||
// httpDiffWithInconsistentDNS verifies the case where there is an HTTP diff | ||
// but the addresses returned by the DNS resolver are inconsistent. | ||
func httpDiffWithInconsistentDNS() *TestCase { | ||
return &TestCase{ | ||
Name: "httpDiffWithInconsistentDNS", | ||
Flags: TestCaseFlagNoLTE, // BUG: LTE does not detect any HTTP diff here | ||
Input: "http://www.example.com/", | ||
Configure: func(env *netemx.QAEnv) { | ||
|
||
// add DPI rule to force all the cleartext DNS queries to | ||
// point the client to used the ISPProxyAddress | ||
env.DPIEngine().AddRule(&netem.DPISpoofDNSResponse{ | ||
Addresses: []string{netemx.ISPProxyAddress}, | ||
Logger: env.Logger(), | ||
Domain: "www.example.com", | ||
}) | ||
|
||
// spoof the blockpage for the legitimate website address as well | ||
env.DPIEngine().AddRule(&netem.DPISpoofBlockpageForString{ | ||
HTTPResponse: netem.DPIFormatHTTPResponse([]byte(netemx.Blockpage)), | ||
Logger: log.Log, | ||
ServerIPAddress: netemx.AddressWwwExampleCom, | ||
ServerPort: 80, | ||
String: "www.example.com", | ||
}) | ||
|
||
// spoof the blockpage for the address that we assume the client would use | ||
env.DPIEngine().AddRule(&netem.DPISpoofBlockpageForString{ | ||
HTTPResponse: netem.DPIFormatHTTPResponse([]byte(netemx.Blockpage)), | ||
Logger: log.Log, | ||
ServerIPAddress: netemx.ISPProxyAddress, | ||
ServerPort: 80, | ||
String: "www.example.com", | ||
}) | ||
|
||
}, | ||
ExpectErr: false, | ||
ExpectTestKeys: &testKeys{ | ||
DNSExperimentFailure: nil, | ||
DNSConsistency: "inconsistent", | ||
HTTPExperimentFailure: nil, | ||
BodyLengthMatch: false, | ||
BodyProportion: 0.12263535551206783, | ||
StatusCodeMatch: true, | ||
HeadersMatch: false, | ||
TitleMatch: false, | ||
XStatus: 96, // StatusAnomalyHTTPDiff | StatusAnomalyDNS | ||
XDNSFlags: 4, // AnalysisDNSUnexpectedAddrs | ||
XBlockingFlags: 35, // analysisFlagSuccess | analysisFlagDNSBlocking | analysisFlagTCPIPBlocking | ||
Accessible: false, | ||
Blocking: "dns", | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package webconnectivityqa | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/apex/log" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/ooni/probe-cli/v3/internal/netemx" | ||
"github.com/ooni/probe-cli/v3/internal/netxlite" | ||
"github.com/ooni/probe-cli/v3/internal/runtimex" | ||
) | ||
|
||
func TestHTTPDiffWithConsistentDNS(t *testing.T) { | ||
testcases := []*TestCase{ | ||
httpDiffWithConsistentDNS(), | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
env := netemx.MustNewScenario(netemx.InternetScenario) | ||
tc.Configure(env) | ||
|
||
env.Do(func() { | ||
client := netxlite.NewHTTPClientStdlib(log.Log) | ||
req := runtimex.Try1(http.NewRequest("GET", "http://www.example.com/", nil)) | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer resp.Body.Close() | ||
body, err := netxlite.ReadAllContext(req.Context(), resp.Body) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff := cmp.Diff([]byte(netemx.Blockpage), body); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func TestHTTPDiffWithInconsistentDNS(t *testing.T) { | ||
testcases := []*TestCase{ | ||
httpDiffWithInconsistentDNS(), | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
env := netemx.MustNewScenario(netemx.InternetScenario) | ||
tc.Configure(env) | ||
|
||
env.Do(func() { | ||
t.Run("there is blockpage spoofing", func(t *testing.T) { | ||
client := netxlite.NewHTTPClientStdlib(log.Log) | ||
req := runtimex.Try1(http.NewRequest("GET", "http://www.example.com/", nil)) | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer resp.Body.Close() | ||
body, err := netxlite.ReadAllContext(req.Context(), resp.Body) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff := cmp.Diff([]byte(netemx.Blockpage), body); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
}) | ||
|
||
t.Run("there is DNS spoofing", func(t *testing.T) { | ||
expect := []string{netemx.ISPProxyAddress} | ||
|
||
t.Run("with stdlib resolver", func(t *testing.T) { | ||
reso := netxlite.NewStdlibResolver(log.Log) | ||
addrs, err := reso.LookupHost(context.Background(), "www.example.com") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff := cmp.Diff(expect, addrs); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
}) | ||
|
||
t.Run("with UDP resolver", func(t *testing.T) { | ||
d := netxlite.NewDialerWithoutResolver(log.Log) | ||
reso := netxlite.NewParallelUDPResolver(log.Log, d, "8.8.8.8:53") | ||
addrs, err := reso.LookupHost(context.Background(), "www.example.com") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff := cmp.Diff(expect, addrs); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.