mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-16 22:15:43 +08:00
Merge fa7ee5a9dc into 1f5237e0d7
This commit is contained in:
commit
b982375d32
@ -463,6 +463,11 @@ INTERNAL_TOKEN =
|
|||||||
;; Name of cookie used to store authentication information.
|
;; Name of cookie used to store authentication information.
|
||||||
;COOKIE_REMEMBER_NAME = gitea_incredible
|
;COOKIE_REMEMBER_NAME = gitea_incredible
|
||||||
;;
|
;;
|
||||||
|
;; URL or path that Gitea should redirect users to *after* performing its own logout.
|
||||||
|
;; Use this, if needed, when authentication is handled by a reverse proxy or SSO.
|
||||||
|
;; Mellon example: REVERSE_PROXY_LOGOUT_REDIRECT = /mellon/logout?ReturnTo=/
|
||||||
|
;REVERSE_PROXY_LOGOUT_REDIRECT =
|
||||||
|
;;
|
||||||
;; Reverse proxy authentication header name of user name, email, and full name
|
;; Reverse proxy authentication header name of user name, email, and full name
|
||||||
;REVERSE_PROXY_AUTHENTICATION_USER = X-WEBAUTH-USER
|
;REVERSE_PROXY_AUTHENTICATION_USER = X-WEBAUTH-USER
|
||||||
;REVERSE_PROXY_AUTHENTICATION_EMAIL = X-WEBAUTH-EMAIL
|
;REVERSE_PROXY_AUTHENTICATION_EMAIL = X-WEBAUTH-EMAIL
|
||||||
|
|||||||
@ -25,6 +25,7 @@ var (
|
|||||||
ReverseProxyAuthEmail string
|
ReverseProxyAuthEmail string
|
||||||
ReverseProxyAuthFullName string
|
ReverseProxyAuthFullName string
|
||||||
ReverseProxyLimit int
|
ReverseProxyLimit int
|
||||||
|
ReverseProxyLogoutRedirect string
|
||||||
ReverseProxyTrustedProxies []string
|
ReverseProxyTrustedProxies []string
|
||||||
MinPasswordLength int
|
MinPasswordLength int
|
||||||
ImportLocalPaths bool
|
ImportLocalPaths bool
|
||||||
@ -121,6 +122,7 @@ func loadSecurityFrom(rootCfg ConfigProvider) {
|
|||||||
ReverseProxyAuthFullName = sec.Key("REVERSE_PROXY_AUTHENTICATION_FULL_NAME").MustString("X-WEBAUTH-FULLNAME")
|
ReverseProxyAuthFullName = sec.Key("REVERSE_PROXY_AUTHENTICATION_FULL_NAME").MustString("X-WEBAUTH-FULLNAME")
|
||||||
|
|
||||||
ReverseProxyLimit = sec.Key("REVERSE_PROXY_LIMIT").MustInt(1)
|
ReverseProxyLimit = sec.Key("REVERSE_PROXY_LIMIT").MustInt(1)
|
||||||
|
ReverseProxyLogoutRedirect = sec.Key("REVERSE_PROXY_LOGOUT_REDIRECT").MustString("")
|
||||||
ReverseProxyTrustedProxies = sec.Key("REVERSE_PROXY_TRUSTED_PROXIES").Strings(",")
|
ReverseProxyTrustedProxies = sec.Key("REVERSE_PROXY_TRUSTED_PROXIES").Strings(",")
|
||||||
if len(ReverseProxyTrustedProxies) == 0 {
|
if len(ReverseProxyTrustedProxies) == 0 {
|
||||||
ReverseProxyTrustedProxies = []string{"127.0.0.0/8", "::1/128"}
|
ReverseProxyTrustedProxies = []string{"127.0.0.0/8", "::1/128"}
|
||||||
|
|||||||
@ -416,7 +416,11 @@ func SignOut(ctx *context.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
HandleSignOut(ctx)
|
HandleSignOut(ctx)
|
||||||
ctx.JSONRedirect(setting.AppSubURL + "/")
|
if setting.ReverseProxyLogoutRedirect != "" {
|
||||||
|
ctx.Redirect(setting.ReverseProxyLogoutRedirect)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Redirect(setting.AppSubURL + "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignUp render the register page
|
// SignUp render the register page
|
||||||
|
|||||||
@ -55,7 +55,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<a class="item link-action" href data-url="{{AppSubUrl}}/user/logout">
|
<form id="logout-form" method="post" action="{{AppSubUrl}}/user/logout"></form>
|
||||||
|
<a class="item" onclick="document.getElementById('logout-form').submit();">
|
||||||
{{svg "octicon-sign-out"}}
|
{{svg "octicon-sign-out"}}
|
||||||
{{ctx.Locale.Tr "sign_out"}}
|
{{ctx.Locale.Tr "sign_out"}}
|
||||||
</a>
|
</a>
|
||||||
@ -128,7 +129,8 @@
|
|||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<a class="item link-action" href data-url="{{AppSubUrl}}/user/logout">
|
<form id="logout-form" method="post" action="{{AppSubUrl}}/user/logout"></form>
|
||||||
|
<a class="item" onclick="document.getElementById('logout-form').submit();">
|
||||||
{{svg "octicon-sign-out"}}
|
{{svg "octicon-sign-out"}}
|
||||||
{{ctx.Locale.Tr "sign_out"}}
|
{{ctx.Locale.Tr "sign_out"}}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,7 +18,34 @@ func TestSignOut(t *testing.T) {
|
|||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
|
|
||||||
req := NewRequest(t, "POST", "/user/logout")
|
req := NewRequest(t, "POST", "/user/logout")
|
||||||
session.MakeRequest(t, req, http.StatusOK)
|
resp := session.MakeRequest(t, req, http.StatusSeeOther)
|
||||||
|
|
||||||
|
expected := "/"
|
||||||
|
loc := resp.Header().Get("Location")
|
||||||
|
if loc != expected {
|
||||||
|
t.Fatalf("expected redirect to %q, got %q", expected, loc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to view a private repo, should fail
|
||||||
|
req = NewRequest(t, "GET", "/user2/repo2")
|
||||||
|
session.MakeRequest(t, req, http.StatusNotFound)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSignOut_ReverseProxyLogoutRedirect(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
|
defer test.MockVariableValue(&setting.ReverseProxyLogoutRedirect, "/mellon/logout?ReturnTo=/")()
|
||||||
|
|
||||||
|
session := loginUser(t, "user2")
|
||||||
|
|
||||||
|
req := NewRequest(t, "POST", "/user/logout")
|
||||||
|
resp := session.MakeRequest(t, req, http.StatusSeeOther)
|
||||||
|
|
||||||
|
expected := "/mellon/logout?ReturnTo=/"
|
||||||
|
loc := resp.Header().Get("Location")
|
||||||
|
if loc != expected {
|
||||||
|
t.Fatalf("expected redirect to %q, got %q", expected, loc)
|
||||||
|
}
|
||||||
|
|
||||||
// try to view a private repo, should fail
|
// try to view a private repo, should fail
|
||||||
req = NewRequest(t, "GET", "/user2/repo2")
|
req = NewRequest(t, "GET", "/user2/repo2")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user