2017-11-11 21:29:07 -08:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-11-11 21:29:07 -08:00
|
|
|
|
2022-09-02 15:18:23 -04:00
|
|
|
package integration
|
2017-11-11 21:29:07 -08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"testing"
|
2022-09-02 15:18:23 -04:00
|
|
|
|
2026-04-11 00:49:55 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2026-03-01 07:28:26 +01:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
2022-09-02 15:18:23 -04:00
|
|
|
"code.gitea.io/gitea/tests"
|
2026-03-01 07:28:26 +01:00
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-11-11 21:29:07 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestSignOut(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-11-11 21:29:07 -08:00
|
|
|
|
2026-04-11 00:49:55 +08:00
|
|
|
t.Run("NormalLogout", func(t *testing.T) {
|
|
|
|
|
session := loginUser(t, "user2")
|
2017-11-11 21:29:07 -08:00
|
|
|
|
2026-04-11 00:49:55 +08:00
|
|
|
req := NewRequest(t, "GET", "/user/logout")
|
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusSeeOther)
|
|
|
|
|
assert.Equal(t, "/", resp.Header().Get("Location"))
|
2017-11-11 21:29:07 -08:00
|
|
|
|
2026-04-11 00:49:55 +08:00
|
|
|
// logged out, try to view a private repo, should fail
|
|
|
|
|
req = NewRequest(t, "GET", "/user2/repo2")
|
|
|
|
|
session.MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("ReverseProxyLogoutRedirect", func(t *testing.T) {
|
|
|
|
|
defer test.MockVariableValue(&setting.Service.EnableReverseProxyAuth, true)()
|
|
|
|
|
defer test.MockVariableValue(&setting.ReverseProxyLogoutRedirect, "/my-sso/logout?return_to=/my-sso/home")()
|
|
|
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
|
req := NewRequest(t, "GET", "/user/logout")
|
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusSeeOther)
|
|
|
|
|
assert.Equal(t, "/my-sso/logout?return_to=/my-sso/home", resp.Header().Get("Location"))
|
|
|
|
|
|
|
|
|
|
// logged out, try to view a private repo, should fail
|
|
|
|
|
req = NewRequest(t, "GET", "/user2/repo2")
|
|
|
|
|
session.MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
|
})
|
2017-11-11 21:29:07 -08:00
|
|
|
}
|