|
|
@@ -812,12 +812,11 @@ func (TestHostNameTransformer) TransformHostName(string) (string, bool) {
|
|
|
|
|
|
func fetchAndVerifyWebsite(t *testing.T, httpProxyPort int) {
|
|
|
|
|
|
- testUrl := "https://raw.githubusercontent.com/Psiphon-Labs/psiphon-tunnel-core/master/LICENSE"
|
|
|
+ testUrl := "https://psiphon.ca"
|
|
|
roundTripTimeout := 30 * time.Second
|
|
|
- expectedResponsePrefix := " GNU GENERAL PUBLIC LICENSE"
|
|
|
- expectedResponseSize := 35148
|
|
|
+ expectedResponseContains := "Psiphon"
|
|
|
checkResponse := func(responseBody string) bool {
|
|
|
- return strings.HasPrefix(responseBody, expectedResponsePrefix) && len(responseBody) == expectedResponseSize
|
|
|
+ return strings.Contains(responseBody, expectedResponseContains)
|
|
|
}
|
|
|
|
|
|
// Test: use HTTP proxy
|
|
|
@@ -827,18 +826,20 @@ func fetchAndVerifyWebsite(t *testing.T, httpProxyPort int) {
|
|
|
t.Fatalf("error initializing proxied HTTP request: %s", err)
|
|
|
}
|
|
|
|
|
|
+ httpTransport := &http.Transport{
|
|
|
+ Proxy: http.ProxyURL(proxyUrl),
|
|
|
+ DisableKeepAlives: true,
|
|
|
+ }
|
|
|
+
|
|
|
httpClient := &http.Client{
|
|
|
- Transport: &http.Transport{
|
|
|
- Proxy: http.ProxyURL(proxyUrl),
|
|
|
- },
|
|
|
- Timeout: roundTripTimeout,
|
|
|
+ Transport: httpTransport,
|
|
|
+ Timeout: roundTripTimeout,
|
|
|
}
|
|
|
|
|
|
request, err := http.NewRequest("GET", testUrl, nil)
|
|
|
if err != nil {
|
|
|
t.Fatalf("error preparing proxied HTTP request: %s", err)
|
|
|
}
|
|
|
- request.Close = true
|
|
|
|
|
|
response, err := httpClient.Do(request)
|
|
|
if err != nil {
|
|
|
@@ -860,8 +861,12 @@ func fetchAndVerifyWebsite(t *testing.T, httpProxyPort int) {
|
|
|
|
|
|
// Test: use direct URL proxy
|
|
|
|
|
|
+ httpTransport = &http.Transport{
|
|
|
+ DisableKeepAlives: true,
|
|
|
+ }
|
|
|
+
|
|
|
httpClient = &http.Client{
|
|
|
- Transport: http.DefaultTransport,
|
|
|
+ Transport: httpTransport,
|
|
|
Timeout: roundTripTimeout,
|
|
|
}
|
|
|
|
|
|
@@ -873,7 +878,6 @@ func fetchAndVerifyWebsite(t *testing.T, httpProxyPort int) {
|
|
|
if err != nil {
|
|
|
t.Fatalf("error preparing direct URL request: %s", err)
|
|
|
}
|
|
|
- request.Close = true
|
|
|
|
|
|
response, err = httpClient.Do(request)
|
|
|
if err != nil {
|
|
|
@@ -890,11 +894,21 @@ func fetchAndVerifyWebsite(t *testing.T, httpProxyPort int) {
|
|
|
t.Fatalf("unexpected direct URL response")
|
|
|
}
|
|
|
|
|
|
+ // Delay before requesting from external service again
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+
|
|
|
// Test: use tunneled URL proxy
|
|
|
|
|
|
- response, err = httpClient.Get(
|
|
|
+ request, err = http.NewRequest(
|
|
|
+ "GET",
|
|
|
fmt.Sprintf("http://127.0.0.1:%d/tunneled/%s",
|
|
|
- httpProxyPort, url.QueryEscape(testUrl)))
|
|
|
+ httpProxyPort, url.QueryEscape(testUrl)),
|
|
|
+ nil)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("error preparing tunneled URL request: %s", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ response, err = httpClient.Do(request)
|
|
|
if err != nil {
|
|
|
t.Fatalf("error sending tunneled URL request: %s", err)
|
|
|
}
|