-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2942 from getlantern/issue2941
Report and use IP and country from CloudFlare closes #2941
- Loading branch information
Showing
5 changed files
with
110 additions
and
15 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,39 @@ | ||
package enproxy | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestCustomHeaders(t *testing.T) { | ||
|
||
proxy := &Proxy{} | ||
|
||
w := httptest.NewRecorder() | ||
|
||
req, err := http.NewRequest("GET", "http://example.com/foo", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
xff := "7.7.7.7" | ||
req.Header.Set("X-Forwarded-For", xff) | ||
|
||
ipc := "US" | ||
req.Header.Set("Cf-Ipcountry", ipc) | ||
|
||
proxy.ServeHTTP(w, req) | ||
|
||
ip := w.Header().Get("Lantern-IP") | ||
country := w.Header().Get("Lantern-Country") | ||
|
||
log.Debugf("Testing IP: %v", ip) | ||
log.Debugf("Testing country: %v", country) | ||
if ip != xff { | ||
t.Fatalf("Unexpected ip: %v", ip) | ||
} | ||
if country != ipc { | ||
t.Fatalf("Unexpected country: %v", country) | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/github.com/getlantern/flashlight/server/server_test.go
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,40 @@ | ||
package server | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/getlantern/fronted" | ||
) | ||
|
||
func TestBanned(t *testing.T) { | ||
|
||
srv := &Server{ | ||
Addr: "127.0.0.1", | ||
ReadTimeout: 0, // don't timeout | ||
WriteTimeout: 0, | ||
CertContext: &fronted.CertContext{}, | ||
AllowedPorts: []int{80, 443, 8080, 8443, 5222, 5223, 5228}, | ||
|
||
// We've observed high resource consumption from these countries for | ||
// purposes unrelated to Lantern's mission, so we disallow them. | ||
BannedCountries: []string{"PH"}, | ||
} | ||
|
||
req, err := http.NewRequest("GET", "http://test.com/foo", nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
req.Header.Set("Cf-Ipcountry", "PH") | ||
|
||
err = srv.checkForBannedCountry(req) | ||
if err == nil { | ||
t.Fatalf("Should be banned: %v", err) | ||
} | ||
|
||
req.Header.Set("Cf-Ipcountry", "US") | ||
err = srv.checkForBannedCountry(req) | ||
if err != nil { | ||
t.Fatalf("Should not be banned: %v", err) | ||
} | ||
} |
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