You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
939 B
28 lines
939 B
|
2 months ago
|
package handlers
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http/httptest"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestHTTPSGatewayMetadataTrustBoundary(t *testing.T) {
|
||
|
|
for _, tc := range []struct{ peer, ip, protocol, port string }{
|
||
|
|
{"127.0.0.1:10000", "192.0.2.77", "https", "443"},
|
||
|
|
{"[::1]:10000", "192.0.2.77", "https", "443"},
|
||
|
|
{"192.0.2.88:10000", "192.0.2.88", "http", "8083"},
|
||
|
|
} {
|
||
|
|
r := httptest.NewRequest("GET", "http://console:8083/", nil)
|
||
|
|
r.RemoteAddr = tc.peer
|
||
|
|
r.Header.Set("X-Tera-Client-IP", "192.0.2.77")
|
||
|
|
r.Header.Set("X-Tera-Client-Protocol", "https")
|
||
|
|
r.Header.Set("X-Tera-Client-Port", "443")
|
||
|
|
ip, protocol, port := browserClientMetadata(r)
|
||
|
|
if ip != tc.ip || protocol != tc.protocol || port != tc.port {
|
||
|
|
t.Fatalf("peer %s: got %s/%s/%s", tc.peer, ip, protocol, port)
|
||
|
|
}
|
||
|
|
if desktopClientID(r) != tc.ip || secureBrowserRequest(r) != (tc.protocol == "https") {
|
||
|
|
t.Fatal("session identity or secure cookie uses incorrect proxy metadata")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|