1 parent
a8a65170d3
commit
581e70b2ca
10 files changed
+624
-46
No files matched your search
@@ -233,12 +233,12 @@ func requestMatchesHTTPSAuthority(r *http.Request, configured string) bool {
|
||||
if r == nil {
|
||||
return false
|
||||
}
|
||||
expectedHost, _, ok := configuredHTTPSAuthority(configured)
|
||||
expectedHost, expectedPort, ok := configuredHTTPSAuthority(configured)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
requestHost, _, ok := normalizeAuthority(r.Host, "443")
|
||||
return ok && requestHost == expectedHost
|
||||
requestHost, requestPort, ok := normalizeAuthority(r.Host, "443")
|
||||
return ok && requestHost == expectedHost && requestPort == expectedPort
|
||||
}
|
||||
|
||||
func configuredHTTPSAuthority(value string) (string, string, bool) {
|
||||
|
||||
@@ -63,6 +63,34 @@ func TestPublicRecoveryPageIsServedOnlyFromMailDomain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicRecoveryPageRequiresConfiguredHTTPSPort(t *testing.T) {
|
||||
configurePublicRecoveryRouteTest(t)
|
||||
config.Instance.HttpsPort = 8443
|
||||
handler, err := newPublicRecoveryHandler()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
allowed := httptest.NewRecorder()
|
||||
handler.ServeHTTP(allowed, publicRecoveryRequest(http.MethodGet, "https://mx.example.com:8443/rest/"))
|
||||
if allowed.Code != http.StatusOK {
|
||||
t.Fatalf("configured HTTPS port returned %d, want %d", allowed.Code, http.StatusOK)
|
||||
}
|
||||
|
||||
for _, target := range []string{
|
||||
"https://mx.example.com/rest/",
|
||||
"https://mx.example.com:9443/rest/",
|
||||
} {
|
||||
t.Run(target, func(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(recorder, publicRecoveryRequest(http.MethodGet, target))
|
||||
if recorder.Code != http.StatusNotFound {
|
||||
t.Fatalf("unexpected recovery page status %d for %q", recorder.Code, target)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicRecoveryLoginEntryRedirectsOnlyFromWebDomain(t *testing.T) {
|
||||
configurePublicRecoveryRouteTest(t)
|
||||
handler, err := newPublicRecoveryHandler()
|
||||
|
||||
Reference in new issue
Block a user