forked from ooni/probe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(netemx): use QAEnvOptionNetStack for ScenarioRoleDNSOverHTTPS (
ooni#1229) This diff continues the refactoring of netemx to use a single mechanism to create all the possible kind of servers. While there, this diff removes the limitation that we cannot create more than a single server per IP address, which was one of the reasons why we started this refactoring process. While there, make sure we have full coverage of netemx. ## 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
- Loading branch information
1 parent
93c189d
commit 04440e8
Showing
16 changed files
with
142 additions
and
33 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
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
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
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
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
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,64 @@ | ||
package netemx | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
) | ||
|
||
func TestExampleWebPageHandler(t *testing.T) { | ||
t.Run("we're redirected if the host is example.com", func(t *testing.T) { | ||
req := &http.Request{ | ||
URL: &url.URL{Path: "/"}, | ||
Body: http.NoBody, | ||
Close: false, | ||
Host: "example.com", | ||
} | ||
rr := httptest.NewRecorder() | ||
handler := ExampleWebPageHandler() | ||
handler.ServeHTTP(rr, req) | ||
result := rr.Result() | ||
if result.StatusCode != http.StatusPermanentRedirect { | ||
t.Fatal("unexpected status code", result.StatusCode) | ||
} | ||
if loc := result.Header.Get("Location"); loc != "https://www.example.com/" { | ||
t.Fatal("unexpected location", loc) | ||
} | ||
}) | ||
|
||
t.Run("we're redirected if the host is example.org", func(t *testing.T) { | ||
req := &http.Request{ | ||
URL: &url.URL{Path: "/"}, | ||
Body: http.NoBody, | ||
Close: false, | ||
Host: "example.org", | ||
} | ||
rr := httptest.NewRecorder() | ||
handler := ExampleWebPageHandler() | ||
handler.ServeHTTP(rr, req) | ||
result := rr.Result() | ||
if result.StatusCode != http.StatusPermanentRedirect { | ||
t.Fatal("unexpected status code", result.StatusCode) | ||
} | ||
if loc := result.Header.Get("Location"); loc != "https://www.example.org/" { | ||
t.Fatal("unexpected location", loc) | ||
} | ||
}) | ||
|
||
t.Run("we get a 400 for an unknown host", func(t *testing.T) { | ||
req := &http.Request{ | ||
URL: &url.URL{Path: "/"}, | ||
Body: http.NoBody, | ||
Close: false, | ||
Host: "antani.xyz", | ||
} | ||
rr := httptest.NewRecorder() | ||
handler := ExampleWebPageHandler() | ||
handler.ServeHTTP(rr, req) | ||
result := rr.Result() | ||
if result.StatusCode != http.StatusBadRequest { | ||
t.Fatal("unexpected status code", result.StatusCode) | ||
} | ||
}) | ||
} |